Commit a87bbe20 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Move if_eui64 to system-specific file.

parent 1121ea30
......@@ -58,46 +58,6 @@ kernel_ll_addresses(char *ifname, int ifindex,
return j;
}
/* Determine an interface's hardware address, in modified EUI-64 format */
int
if_eui64(char *ifname, int ifindex, unsigned char *eui)
{
int s, rc;
struct ifreq req;
unsigned char *mac;
s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if(s < 0) return -1;
memset(&req, 0, sizeof(req));
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
rc = ioctl(s, SIOCGIFHWADDR, &req);
if(rc < 0) {
int saved_errno = errno;
close(s);
errno = saved_errno;
return -1;
}
close(s);
mac = (unsigned char *)req.ifr_hwaddr.sa_data;
/* OpenVPN interfaces have a null MAC address. Also check not group
and global */
if(memcmp(mac, zeroes, 6) == 0 || (mac[0] & 1) != 0 || (mac[0] & 2) != 0) {
errno = ENOENT;
return -1;
}
eui[0] = mac[0] ^ 2;
eui[1] = mac[1];
eui[2] = mac[2];
eui[3] = 0xFF;
eui[4] = 0xFE;
eui[5] = mac[3];
eui[6] = mac[4];
eui[7] = mac[5];
return 1;
}
/* Like gettimeofday, but should return monotonic time. If POSIX clocks
are not available, falls back to gettimeofday. */
int
......
......@@ -59,6 +59,46 @@ static int old_rp_filter = -1;
static int dgram_socket = -1;
/* Determine an interface's hardware address, in modified EUI-64 format */
int
if_eui64(char *ifname, int ifindex, unsigned char *eui)
{
int s, rc;
struct ifreq req;
unsigned char *mac;
s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
if(s < 0) return -1;
memset(&req, 0, sizeof(req));
strncpy(req.ifr_name, ifname, sizeof(req.ifr_name));
rc = ioctl(s, SIOCGIFHWADDR, &req);
if(rc < 0) {
int saved_errno = errno;
close(s);
errno = saved_errno;
return -1;
}
close(s);
mac = (unsigned char *)req.ifr_hwaddr.sa_data;
/* OpenVPN interfaces have a null MAC address. Also check not group
and global */
if(memcmp(mac, zeroes, 6) == 0 || (mac[0] & 1) != 0 || (mac[0] & 2) != 0) {
errno = ENOENT;
return -1;
}
eui[0] = mac[0] ^ 2;
eui[1] = mac[1];
eui[2] = mac[2];
eui[3] = 0xFF;
eui[4] = 0xFE;
eui[5] = mac[3];
eui[6] = mac[4];
eui[7] = mac[5];
return 1;
}
static int
read_proc(char *filename)
{
......
......@@ -48,6 +48,14 @@ THE SOFTWARE.
int export_table = -1, import_table = -1;
int
if_eui64(char *ifname, int ifindex, unsigned char *eui)
{
errno = ENOSYS;
return -1;
}
/* KAME said : "Following two macros are highly depending on KAME Release" */
#define IN6_LINKLOCAL_IFINDEX(a) ((a).s6_addr[2] << 8 | (a).s6_addr[3])
#define SET_IN6_LINKLOCAL_IFINDEX(a, i) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment