summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins-root/check_dhcp.c19
1 files changed, 13 insertions, 6 deletions
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){
464 /* length of our hardware address */ 464 /* length of our hardware address */
465 discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH; 465 discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH;
466 466
467 /* transaction id is supposed to be random */ 467 /*
468 * transaction ID is supposed to be random. We won't use the address so
469 * we don't care about high entropy here. time(2) is good enough.
470 */
468 srand(time(NULL)); 471 srand(time(NULL));
469 packet_xid=random(); 472 packet_xid=random();
470 discover_packet.xid=htonl(packet_xid); 473 discover_packet.xid=htonl(packet_xid);
@@ -522,7 +525,7 @@ int send_dhcp_discover(int sock){
522 525
523 if(verbose){ 526 if(verbose){
524 printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port)); 527 printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port));
525 printf("DHCPDISCOVER XID: %lu (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); 528 printf("DHCPDISCOVER XID: %u (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid));
526 printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); 529 printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr));
527 printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); 530 printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr));
528 printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); 531 printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr));
@@ -596,13 +599,13 @@ int get_dhcp_offer(int sock){
596 if(verbose){ 599 if(verbose){
597 printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr)); 600 printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr));
598 printf(_(" via %s\n"),inet_ntoa(via.sin_addr)); 601 printf(_(" via %s\n"),inet_ntoa(via.sin_addr));
599 printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid)); 602 printf("DHCPOFFER XID: %u (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid));
600 } 603 }
601 604
602 /* check packet xid to see if its the same as the one we used in the discover packet */ 605 /* check packet xid to see if its the same as the one we used in the discover packet */
603 if(ntohl(offer_packet.xid)!=packet_xid){ 606 if(ntohl(offer_packet.xid)!=packet_xid){
604 if(verbose) 607 if(verbose)
605 printf(_("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); 608 printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid);
606 609
607 continue; 610 continue;
608 } 611 }
@@ -672,22 +675,26 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in
672int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address){ 675int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address){
673 struct timeval tv; 676 struct timeval tv;
674 fd_set readfds; 677 fd_set readfds;
678 fd_set oobfds;
675 int recv_result; 679 int recv_result;
676 socklen_t address_size; 680 socklen_t address_size;
677 struct sockaddr_in source_address; 681 struct sockaddr_in source_address;
682 int nfound;
678 683
679 684
680 /* wait for data to arrive (up time timeout) */ 685 /* wait for data to arrive (up time timeout) */
681 tv.tv_sec=timeout; 686 tv.tv_sec=timeout;
682 tv.tv_usec=0; 687 tv.tv_usec=0;
683 FD_ZERO(&readfds); 688 FD_ZERO(&readfds);
689 FD_ZERO(&oobfds);
684 FD_SET(sock,&readfds); 690 FD_SET(sock,&readfds);
685 select(sock+1,&readfds,NULL,NULL,&tv); 691 FD_SET(sock,&oobfds);
692 nfound = select(sock+1,&readfds,NULL,&oobfds,&tv);
686 693
687 /* make sure some data has arrived */ 694 /* make sure some data has arrived */
688 if(!FD_ISSET(sock,&readfds)){ 695 if(!FD_ISSET(sock,&readfds)){
689 if(verbose) 696 if(verbose)
690 printf(_("No (more) data received\n")); 697 printf(_("No (more) data received (nfound: %d)\n"), nfound);
691 return ERROR; 698 return ERROR;
692 } 699 }
693 700