summaryrefslogtreecommitdiff
path: root/common/lpf.c
diff options
context:
space:
mode:
authorDavid Hankins <dhankins@isc.org>2007-05-08 23:05:22 +0000
committerDavid Hankins <dhankins@isc.org>2007-05-08 23:05:22 +0000
commit98bd7ca0990e6d88e3345d3bc966ebe8216691a7 (patch)
treec4437ca467e8f733d530170a5c445747b2defd68 /common/lpf.c
parent74dc3e0b2786c46956e7517398ae6f7c6dad52d7 (diff)
downloadisc-dhcp-98bd7ca0990e6d88e3345d3bc966ebe8216691a7.tar.gz
DHCPv6 branch merged to HEAD.
Diffstat (limited to 'common/lpf.c')
-rw-r--r--common/lpf.c55
1 files changed, 53 insertions, 2 deletions
diff --git a/common/lpf.c b/common/lpf.c
index 12c46bc1..255fea8f 100644
--- a/common/lpf.c
+++ b/common/lpf.c
@@ -28,7 +28,7 @@
#ifndef lint
static char copyright[] =
-"$Id: lpf.c,v 1.31 2007/04/27 23:54:05 each Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
+"$Id: lpf.c,v 1.32 2007/05/08 23:05:20 dhankins Exp $ Copyright (c) 2004 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -43,6 +43,7 @@ static char copyright[] =
#include "includes/netinet/ip.h"
#include "includes/netinet/udp.h"
#include "includes/netinet/if_ether.h"
+#include <net/if.h>
/* Reinitializes the specified interface after an address change. This
is not required for packet-filter APIs. */
@@ -406,9 +407,59 @@ void maybe_setup_fallback ()
if_readsocket, 0,
fallback_discard, 0, 0);
if (status != ISC_R_SUCCESS)
- log_fatal ("Can't register I/O handle for %s: %s",
+ log_fatal ("Can't register I/O handle for \"%s\": %s",
fbi -> name, isc_result_totext (status));
interface_dereference (&fbi, MDL);
}
}
+
+void
+get_hw_addr(const char *name, struct hardware *hw) {
+ int sock;
+ struct ifreq tmp;
+ struct sockaddr *sa;
+
+ if (strlen(name) >= sizeof(tmp.ifr_name)) {
+ log_fatal("Device name too long: \"%s\"", name);
+ }
+
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ log_fatal("Can't create socket for \"%s\": %m", name);
+ }
+
+ memset(&tmp, 0, sizeof(tmp));
+ strcpy(tmp.ifr_name, name);
+ if (ioctl(sock, SIOCGIFHWADDR, &tmp) < 0) {
+ log_fatal("Error getting hardware address for \"%s\": %m",
+ name);
+ }
+
+ sa = &tmp.ifr_hwaddr;
+ switch (sa->sa_family) {
+ case ARPHRD_ETHER:
+ hw->hlen = 7;
+ hw->hbuf[0] = HTYPE_ETHER;
+ memcpy(&hw->hbuf[1], sa->sa_data, 6);
+ break;
+ case ARPHRD_IEEE802:
+#ifdef ARPHDR_IEEE802_TR
+ case ARPHRD_IEEE802_TR:
+#endif /* ARPHDR_IEEE802_TR */
+ hw->hlen = 7;
+ hw->hbuf[0] = HTYPE_IEEE802;
+ memcpy(&hw->hbuf[1], sa->sa_data, 6);
+ break;
+ case ARPHRD_FDDI:
+ hw->hlen = 17;
+ hw->hbuf[0] = HTYPE_FDDI;
+ memcpy(&hw->hbuf[1], sa->sa_data, 16);
+ break;
+ default:
+ log_fatal("Unsupported device type %ld for \"%s\"",
+ sa->sa_family, name);
+ }
+
+ close(sock);
+}
#endif