diff options
author | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2006-04-13 21:09:04 +0000 |
---|---|---|
committer | james <james@e7ae566f-a301-0410-adde-c780ea21d3b5> | 2006-04-13 21:09:04 +0000 |
commit | e12fe2864a30f4e5b6c77fcf6128be7a6266d73e (patch) | |
tree | 2b2e445fb562542bd9c3c0e0e8eabb05e4145539 /lladdr.c | |
parent | Added --route-metric option to set a default route metric (diff) | |
download | openvpn-e12fe2864a30f4e5b6c77fcf6128be7a6266d73e.tar.xz |
Added --lladdr option to specify the link layer (MAC) address
for the tap interface on non-Windows platforms (Roy Marples).
git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@1012 e7ae566f-a301-0410-adde-c780ea21d3b5
Diffstat (limited to 'lladdr.c')
-rw-r--r-- | lladdr.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lladdr.c b/lladdr.c new file mode 100644 index 0000000..d6fb0a6 --- /dev/null +++ b/lladdr.c @@ -0,0 +1,58 @@ +/* + * Support routine for configuring link layer address + */ + +#ifdef WIN32 +#include "config-win32.h" +#else +#include "config.h" +#endif + +#include "syshead.h" +#include "error.h" +#include "misc.h" + +int set_lladdr(const char *ifname, const char *lladdr, + const struct env_set *es) +{ + char cmd[256]; + + if (!ifname || !lladdr) + return -1; + +#if defined(TARGET_LINUX) +#ifdef CONFIG_FEATURE_IPROUTE + openvpn_snprintf (cmd, sizeof (cmd), + IPROUTE_PATH " link set addr %s dev %s", + lladdr, ifname); +#else + openvpn_snprintf (cmd, sizeof (cmd), + IFCONFIG_PATH " %s hw ether %s", + ifname, lladdr); +#endif +#elif defined(TARGET_SOLARIS) + openvpn_snprintf (cmd, sizeof (cmd), + IFCONFIG_PATH " %s ether %s", + ifname, lladdr); +#elif defined(TARGET_OPENBSD) + openvpn_snprintf (cmd, sizeof (cmd), + IFCONFIG_PATH " %s lladdr %s", + ifname, lladdr); +#elif defined(TARGET_DARWIN) + openvpn_snprintf (cmd, sizeof (cmd), + IFCONFIG_PATH " %s lladdr %s", + ifname, lladdr); +#elif defined(TARGET_FREEBSD) + openvpn_snprintf (cmd, sizeof (cmd), + IFCONFIG_PATH " %s ether %s", + ifname, lladdr); +#else + msg (M_WARN, "Sorry, but I don't know how to configure link layer addresses on this operating system."); + return -1; +#endif + + int r = system_check (cmd, es, M_WARN, "ERROR: Unable to set link layer address."); + if (r) + msg (M_INFO, "TUN/TAP link layer address set to %s", lladdr); + return r; +} |