diff options
-rw-r--r-- | econserv.c | 17 | ||||
-rw-r--r-- | util.c | 17 | ||||
-rw-r--r-- | util.h | 2 |
3 files changed, 22 insertions, 14 deletions
@@ -14,12 +14,9 @@ #include <sys/types.h> #include <sys/socket.h> -#include <sys/ioctl.h> #include <sys/select.h> #include <sys/uio.h> #include <unistd.h> -#include <net/if.h> -#include <net/if_arp.h> #include <netinet/in.h> #include "econproto.h" @@ -100,18 +97,10 @@ struct ecs { static void get_hwaddr(struct ecs *ecs) { - struct ifreq ifreq; - char *m = &ifreq.ifr_hwaddr.sa_data[0]; + uint8_t *m; - memset(&ifreq, 0, sizeof ifreq); - - strcpy(ifreq.ifr_name, "tap0"); - ioctl(ecs->fd, SIOCGIFHWADDR, &ifreq); - assert(ifreq.ifr_hwaddr.sa_family == ARPHRD_ETHER); -#if 0 - printf("hwaddr: %02hhx-%02hhx-%02hhx-%02hhx-%02hhx-%02hhx\n", - m[0], m[1], m[2], m[3], m[4], m[5]); -#endif + m = sock_get_hwaddr(ecs->fd); + assert(m != NULL); memcpy(ecs->proj_uniq, m, 6); } @@ -72,6 +72,23 @@ sock_get_netmask(int fd) return ((struct sockaddr_in *) &ifreq->ifr_netmask)->sin_addr.s_addr; } +uint8_t * +sock_get_hwaddr(int fd) +{ + struct ifreq *ifreq; + + ifreq = sock_get_ifreq(fd); + if (ifreq == NULL) + return NULL; + + if (ioctl(fd, SIOCGIFHWADDR, ifreq) < 0) + return NULL; + if (ifreq->ifr_hwaddr.sa_family != ARPHRD_ETHER) + return NULL; + + return (uint8_t *) &ifreq->ifr_hwaddr.sa_data[0]; +} + uint32_t sock_get_peer_ipv4_addr(int fd) { @@ -15,6 +15,8 @@ uint32_t sock_get_peer_ipv4_addr(int fd); uint32_t sock_get_netmask(int fd); +uint8_t * +sock_get_hwaddr(int fd); void set_ip(uint8_t *ipbuf, uint32_t ip); |