diff -ruN dhcp_probe-1.2.1/src/Makefile.in dhcp_probe-1.2.1.new/src/Makefile.in --- dhcp_probe-1.2.1/src/Makefile.in 2008-02-29 00:28:31.000000000 +0100 +++ dhcp_probe-1.2.1.new/src/Makefile.in 2008-03-26 15:55:54.000000000 +0100 @@ -51,7 +51,7 @@ sbinPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(sbin_PROGRAMS) am_dhcp_probe_OBJECTS = bootp.$(OBJEXT) configfile.$(OBJEXT) \ - dhcp_probe.$(OBJEXT) get_myeaddr.$(OBJEXT) \ + dhcp_probe.$(OBJEXT) get_myeaddr.$(OBJEXT) arp.$(OBJEXT) \ get_myipaddr.$(OBJEXT) daemonize.$(OBJEXT) report.$(OBJEXT) \ utils.$(OBJEXT) dhcp_probe_OBJECTS = $(am_dhcp_probe_OBJECTS) @@ -163,7 +163,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ dhcp_probe_SOURCES = bootp.c configfile.c dhcp_probe.c \ - get_myeaddr.c get_myipaddr.c \ + get_myeaddr.c get_myipaddr.c arp.c \ daemonize.c report.c utils.c \ bootp.h configfile.h dhcp_probe.h \ defaults.h defs.h \ diff -ruN dhcp_probe-1.2.1/src/arp.c dhcp_probe-1.2.1.new/src/arp.c --- dhcp_probe-1.2.1/src/arp.c 1970-01-01 01:00:00.000000000 +0100 +++ dhcp_probe-1.2.1.new/src/arp.c 2008-03-26 15:55:54.000000000 +0100 @@ -0,0 +1,24 @@ +/* From the Linux net-tools package */ + +#ifdef linux + +#include "arp.h" + +/* Get the hardware address to a specified interface name */ +int arp_getdevhw(char *ifname, struct ether_addr *ea, int sockfd) +{ + struct ifreq ifr; + struct hwtype *xhw; + + strcpy(ifr.ifr_name, ifname); + if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { + fprintf(stderr, "arp: cant get HW-Address for `%s': %s.\n", ifname, strerror(errno)); + return (-1); + } + memcpy((char*)ea, ifr.ifr_hwaddr.sa_data, 6); + //memcpy((char *) sa, (char *) &(ifr.ifr_hwaddr), sizeof(struct sockaddr)); + + return (0); +} + +#endif /* linux */ diff -ruN dhcp_probe-1.2.1/src/arp.h dhcp_probe-1.2.1.new/src/arp.h --- dhcp_probe-1.2.1/src/arp.h 1970-01-01 01:00:00.000000000 +0100 +++ dhcp_probe-1.2.1.new/src/arp.h 2008-03-26 15:55:54.000000000 +0100 @@ -0,0 +1,30 @@ +/* From the Linux net-tools package */ + +#ifndef ARP_H +#define ARP_H + +#ifdef linux + +#include +#include +#include +#include +/* #include */ +/* #include */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Get the hardware address to a specified interface name */ +int arp_getdevhw(char *ifname, struct ether_addr *ea, int sockfd); + +#endif /* linux */ + +#endif /* ARP_H */ diff -ruN dhcp_probe-1.2.1/src/daemonize.c dhcp_probe-1.2.1.new/src/daemonize.c --- dhcp_probe-1.2.1/src/daemonize.c 2001-01-27 23:25:08.000000000 +0100 +++ dhcp_probe-1.2.1.new/src/daemonize.c 2008-03-26 15:55:54.000000000 +0100 @@ -16,6 +16,11 @@ #include "daemonize.h" #include "report.h" +#ifdef linux +#include +#include +#include +#endif /* linux */ void daemonize(void) @@ -23,6 +28,9 @@ int i; pid_t pid; struct sigaction sa; +#ifdef linux + struct rlimit rlim; +#endif /* linux */ if ((pid = fork()) < 0) { report(LOG_ERR, "fork: %s", get_errmsg()); @@ -63,8 +71,18 @@ There is also no portable way to determine the maximum number of file descriptors; presently we'll rely on the non-portable OPEN_MAX constant. */ - for (i = 0; i < OPEN_MAX; i++) +#ifdef linux + if(getrlimit(RLIMIT_NOFILE, &rlim) != 0) { + perror("getrlimit"); + exit(1); + } + for (i = 0; i < rlim.rlim_cur; i++) close(i); +#else /* linux */ + for (i = 0; i < RLIMIT_NOFILE; i++) + close(i); +#endif /* linux */ + return; } diff -ruN dhcp_probe-1.2.1/src/dhcp_probe.c dhcp_probe-1.2.1.new/src/dhcp_probe.c --- dhcp_probe-1.2.1/src/dhcp_probe.c 2006-11-07 16:44:41.000000000 +0100 +++ dhcp_probe-1.2.1.new/src/dhcp_probe.c 2008-03-26 15:55:54.000000000 +0100 @@ -20,6 +20,7 @@ #include "dhcp_probe.h" #include "bootp.h" #include "daemonize.h" +#include "arp.h" #include "get_myeaddr.h" #include "get_myipaddr.h" #include "configfile.h" @@ -292,6 +293,13 @@ exit(1); } +#ifdef linux + if(arp_getdevhw(ifname, &my_eaddr, sockfd) < 0) { + report(LOG_ERR, "couldn't determine my ethernet addr for my IP address %s", inet_ntoa(my_ipaddr)); + cleanup(); + exit(1); + } +#else /* linux */ /* lookup ethernet address for specified IP address */ /* note that my_eaddr must be init'd before calling GetChaddr() */ if (get_myeaddr(sockfd, &my_ipaddr, &my_eaddr, ifname) < 0) { @@ -299,6 +307,7 @@ cleanup(); exit(1); } +#endif /* linux */ if (debug > 0) { if (use_8021q) { @@ -413,6 +422,9 @@ cleanup(); exit(1); } +#ifdef linux + set_timeout(pd_template); +#endif /* linux */ if (pcap_errbuf[0] != '\0') /* even on success, a warning may be produced */ report(LOG_WARNING, "pcap_open_live %s: %s", ifname, pcap_errbuf); @@ -513,6 +525,9 @@ while (pcap_open_retries--) { pcap_errbuf[0] = '\0'; /* so we can tell if a warning was produced on success */ if ((pd = pcap_open_live(ifname, snaplen, promiscuous, GetResponse_wait_time(), pcap_errbuf)) != NULL) { +#ifdef linux + set_timeout(pd); +#endif /* linux */ break; /* success */ } else { /* failure */ if (pcap_open_retries == 0) { @@ -795,7 +810,11 @@ return; } +#ifdef linux + udp_len = udp_header->len; +#else /* linux */ udp_len = udp_header->uh_ulen; +#endif /* linux */ if (udp_len < sizeof(struct udphdr)) { report(LOG_WARNING, "interface %s, ether src %s: invalid UDP packet (UDP length %d, smaller than minimum value %d)", ifname, ether_shost_str, udp_len, sizeof(struct udphdr)); return; @@ -1045,3 +1064,22 @@ return; } +void +set_timeout(pcap_t *pc) +{ + struct timeval timeout; + int time_wait; + + time_wait = GetResponse_wait_time(); + timeout.tv_sec = time_wait / 1000; + timeout.tv_usec = (time_wait % 1000) * 1000; + if(setsockopt(pcap_fileno(pc), SOL_SOCKET, SO_RCVTIMEO, + &timeout, sizeof(timeout)) < 0) { + report(LOG_ERR, + "set_timeout: Unable to set receive timeout: %s", + strerror(errno)); + cleanup(); + exit(1); + } + +} diff -ruN dhcp_probe-1.2.1/src/dhcp_probe.h dhcp_probe-1.2.1.new/src/dhcp_probe.h --- dhcp_probe-1.2.1/src/dhcp_probe.h 2005-09-21 23:57:36.000000000 +0200 +++ dhcp_probe-1.2.1.new/src/dhcp_probe.h 2008-03-26 15:55:54.000000000 +0100 @@ -46,6 +46,7 @@ void cleanup(void); void usage(void); void close_and_reopen_capture_file(void); +void set_timeout(pcap_t *pc);