summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--econserv.c17
-rw-r--r--util.c17
-rw-r--r--util.h2
3 files changed, 22 insertions, 14 deletions
diff --git a/econserv.c b/econserv.c
index a1d5a32..3f7bb83 100644
--- a/econserv.c
+++ b/econserv.c
@@ -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);
}
diff --git a/util.c b/util.c
index dc89a48..8a5813f 100644
--- a/util.c
+++ b/util.c
@@ -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)
{
diff --git a/util.h b/util.h
index 4d0e27d..e033e21 100644
--- a/util.h
+++ b/util.h
@@ -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);