From: Holger Weiss Date: Thu, 26 Jul 2007 00:07:19 +0000 (+0000) Subject: A few minor fixes/improvements which were included with (but unrelated X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bd8427362889c23ac963f8e032ee7a6d877b8969;p=nagiosplug.git A few minor fixes/improvements which were included with (but unrelated to) the "--unicast" patch (Andreas Ericsson and Heiti Ernits - 1218235) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1763 f882894a-f735-0410-b71e-b25c423dba1c --- diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c index a1d04c1..904d43e 100644 --- a/plugins-root/check_dhcp.c +++ b/plugins-root/check_dhcp.c @@ -464,7 +464,10 @@ int send_dhcp_discover(int sock){ /* length of our hardware address */ discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; - /* transaction id is supposed to be random */ + /* + * transaction ID is supposed to be random. We won't use the address so + * we don't care about high entropy here. time(2) is good enough. + */ srand(time(NULL)); packet_xid=random(); discover_packet.xid=htonl(packet_xid); @@ -522,7 +525,7 @@ int send_dhcp_discover(int sock){ if(verbose){ printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port)); - printf("DHCPDISCOVER XID: %lu (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); + printf("DHCPDISCOVER XID: %u (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); @@ -596,13 +599,13 @@ int get_dhcp_offer(int sock){ if(verbose){ printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr)); printf(_(" via %s\n"),inet_ntoa(via.sin_addr)); - printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid)); + printf("DHCPOFFER XID: %u (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid)); } /* check packet xid to see if its the same as the one we used in the discover packet */ if(ntohl(offer_packet.xid)!=packet_xid){ if(verbose) - printf(_("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); + printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); continue; } @@ -672,22 +675,26 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address){ struct timeval tv; fd_set readfds; + fd_set oobfds; int recv_result; socklen_t address_size; struct sockaddr_in source_address; + int nfound; /* wait for data to arrive (up time timeout) */ tv.tv_sec=timeout; tv.tv_usec=0; FD_ZERO(&readfds); + FD_ZERO(&oobfds); FD_SET(sock,&readfds); - select(sock+1,&readfds,NULL,NULL,&tv); + FD_SET(sock,&oobfds); + nfound = select(sock+1,&readfds,NULL,&oobfds,&tv); /* make sure some data has arrived */ if(!FD_ISSET(sock,&readfds)){ if(verbose) - printf(_("No (more) data received\n")); + printf(_("No (more) data received (nfound: %d)\n"), nfound); return ERROR; }