summaryrefslogtreecommitdiffstats
path: root/plugins-root/check_dhcp.c
diff options
context:
space:
mode:
authorEthan Galstad <egalstad@users.sourceforge.net>2006-05-25 17:40:19 +0000
committerEthan Galstad <egalstad@users.sourceforge.net>2006-05-25 17:40:19 +0000
commitac0e03df0d64a3d1f6cba3f34305f24f7d8db302 (patch)
treeab7cb355523a0d6af4aa4a80b8ac1cee70943ff0 /plugins-root/check_dhcp.c
parenta6f17d22d2f1ae3faf9499d940e9e8659240cc2e (diff)
downloadmonitoring-plugins-ac0e03df0d64a3d1f6cba3f34305f24f7d8db302.tar.gz
Applied patch for responses from helpers/relays, cleaned up different coding styles for consistency
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1408 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r--plugins-root/check_dhcp.c387
1 files changed, 206 insertions, 181 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index cec44b57..528298e5 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -152,6 +152,7 @@ typedef struct dhcp_offer_struct{
152 152
153typedef struct requested_server_struct{ 153typedef struct requested_server_struct{
154 struct in_addr server_address; 154 struct in_addr server_address;
155 int answered;
155 struct requested_server_struct *next; 156 struct requested_server_struct *next;
156 }requested_server; 157 }requested_server;
157 158
@@ -306,25 +307,25 @@ int get_hardware_address(int sock,char *interface_name){
306 mib[3] = AF_LINK; 307 mib[3] = AF_LINK;
307 mib[4] = NET_RT_IFLIST; 308 mib[4] = NET_RT_IFLIST;
308 309
309 if ((mib[5] = if_nametoindex(interface_name)) == 0) { 310 if((mib[5] = if_nametoindex(interface_name)) == 0){
310 printf(_("Error: if_nametoindex error - %s.\n"), strerror(errno)); 311 printf(_("Error: if_nametoindex error - %s.\n"), strerror(errno));
311 exit(STATE_UNKNOWN); 312 exit(STATE_UNKNOWN);
312 } 313 }
313 314
314 if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { 315 if(sysctl(mib, 6, NULL, &len, NULL, 0) < 0){
315 printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno)); 316 printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno));
316 exit(STATE_UNKNOWN); 317 exit(STATE_UNKNOWN);
317 } 318 }
318 319
319 if ((buf = malloc(len)) == NULL) { 320 if((buf = malloc(len)) == NULL){
320 printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno)); 321 printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno));
321 exit(4); 322 exit(4);
322 } 323 }
323 324
324 if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { 325 if(sysctl(mib, 6, buf, &len, NULL, 0) < 0){
325 printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno)); 326 printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno));
326 exit(STATE_UNKNOWN); 327 exit(STATE_UNKNOWN);
327 } 328 }
328 329
329 ifm = (struct if_msghdr *)buf; 330 ifm = (struct if_msghdr *)buf;
330 sdl = (struct sockaddr_dl *)(ifm + 1); 331 sdl = (struct sockaddr_dl *)(ifm + 1);
@@ -340,21 +341,22 @@ int get_hardware_address(int sock,char *interface_name){
340 char *p; 341 char *p;
341 int unit; 342 int unit;
342 343
343 for (p = interface_name; *p && isalpha(*p); p++) 344 for(p = interface_name; *p && isalpha(*p); p++)
344 /* no-op */ ; 345 /* no-op */ ;
345 if ( p != '\0' ) { 346 if( p != '\0' ){
346 unit = atoi(p) ; 347 unit = atoi(p) ;
347 *p = '\0' ; 348 *p = '\0' ;
348 strncat(dev, interface_name, 6) ; 349 strncat(dev, interface_name, 6) ;
349 } else { 350 }
351 else{
350 printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name); 352 printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name);
351 exit(STATE_UNKNOWN); 353 exit(STATE_UNKNOWN);
352 } 354 }
353 stat = mac_addr_dlpi(dev, unit, client_hardware_address); 355 stat = mac_addr_dlpi(dev, unit, client_hardware_address);
354 if (stat != 0) { 356 if(stat != 0){
355 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit); 357 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
356 exit(STATE_UNKNOWN); 358 exit(STATE_UNKNOWN);
357 } 359 }
358 360
359#elif defined(__hpux__) 361#elif defined(__hpux__)
360 362
@@ -363,10 +365,10 @@ int get_hardware_address(int sock,char *interface_name){
363 int unit = 0; 365 int unit = 0;
364 366
365 stat = mac_addr_dlpi(dev, unit, client_hardware_address); 367 stat = mac_addr_dlpi(dev, unit, client_hardware_address);
366 if (stat != 0) { 368 if(stat != 0){
367 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit); 369 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
368 exit(STATE_UNKNOWN); 370 exit(STATE_UNKNOWN);
369 } 371 }
370 /* Kompf 2000-2003 */ 372 /* Kompf 2000-2003 */
371 373
372#else 374#else
@@ -374,12 +376,12 @@ int get_hardware_address(int sock,char *interface_name){
374 exit(STATE_UNKNOWN); 376 exit(STATE_UNKNOWN);
375#endif 377#endif
376 378
377 if (verbose) { 379 if(verbose){
378 printf(_("Hardware address: ")); 380 printf(_("Hardware address: "));
379 for (i=0; i<6; ++i) 381 for (i=0; i<6; ++i)
380 printf("%2.2x", client_hardware_address[i]); 382 printf("%2.2x", client_hardware_address[i]);
381 printf( "\n"); 383 printf( "\n");
382 } 384 }
383 385
384 return OK; 386 return OK;
385 } 387 }
@@ -449,19 +451,19 @@ int send_dhcp_discover(int sock){
449 bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero)); 451 bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero));
450 452
451 453
452 if (verbose) { 454 if(verbose){
453 printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port)); 455 printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port));
454 printf("DHCPDISCOVER XID: %lu (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid)); 456 printf("DHCPDISCOVER XID: %lu (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid));
455 printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr)); 457 printf("DHCDISCOVER ciaddr: %s\n",inet_ntoa(discover_packet.ciaddr));
456 printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr)); 458 printf("DHCDISCOVER yiaddr: %s\n",inet_ntoa(discover_packet.yiaddr));
457 printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr)); 459 printf("DHCDISCOVER siaddr: %s\n",inet_ntoa(discover_packet.siaddr));
458 printf("DHCDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); 460 printf("DHCDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr));
459 } 461 }
460 462
461 /* send the DHCPDISCOVER packet out */ 463 /* send the DHCPDISCOVER packet out */
462 send_dhcp_packet(&discover_packet,sizeof(discover_packet),sock,&sockaddr_broadcast); 464 send_dhcp_packet(&discover_packet,sizeof(discover_packet),sock,&sockaddr_broadcast);
463 465
464 if (verbose) 466 if(verbose)
465 printf("\n\n"); 467 printf("\n\n");
466 468
467 return OK; 469 return OK;
@@ -474,6 +476,7 @@ int send_dhcp_discover(int sock){
474int get_dhcp_offer(int sock){ 476int get_dhcp_offer(int sock){
475 dhcp_packet offer_packet; 477 dhcp_packet offer_packet;
476 struct sockaddr_in source; 478 struct sockaddr_in source;
479 struct sockaddr_in via;
477 int result=OK; 480 int result=OK;
478 int timeout=1; 481 int timeout=1;
479 int responses=0; 482 int responses=0;
@@ -490,36 +493,47 @@ int get_dhcp_offer(int sock){
490 if((current_time-start_time)>=dhcpoffer_timeout) 493 if((current_time-start_time)>=dhcpoffer_timeout)
491 break; 494 break;
492 495
493 if (verbose) 496 if(verbose)
494 printf("\n\n"); 497 printf("\n\n");
495 498
496 bzero(&source,sizeof(source)); 499 bzero(&source,sizeof(source));
500 bzero(&via,sizeof(via));
497 bzero(&offer_packet,sizeof(offer_packet)); 501 bzero(&offer_packet,sizeof(offer_packet));
498 502
499 result=OK; 503 result=OK;
500 result=receive_dhcp_packet(&offer_packet,sizeof(offer_packet),sock,dhcpoffer_timeout,&source); 504 result=receive_dhcp_packet(&offer_packet,sizeof(offer_packet),sock,dhcpoffer_timeout,&source);
501 505
502 if(result!=OK){ 506 if(result!=OK){
503 if (verbose) 507 if(verbose)
504 printf(_("Result=ERROR\n")); 508 printf(_("Result=ERROR\n"));
505 509
506 continue; 510 continue;
507 } 511 }
508 else{ 512 else{
509 if (verbose) 513 if(verbose)
510 printf(_("Result=OK\n")); 514 printf(_("Result=OK\n"));
511 515
512 responses++; 516 responses++;
513 } 517 }
514 518
515 if (verbose) { 519 /* The "source" is either a server or a relay. */
516 printf(_("DHCPOFFER from IP address %s\n"),inet_ntoa(source.sin_addr)); 520 /* Save a copy of "source" into "via" even if it's via itself */
521 memcpy(&via,&source,sizeof(source)) ;
522
523 /* If siaddr is non-zero, set "source" to siaddr */
524 if(offer_packet.siaddr.s_addr != 0L){
525 source.sin_addr.s_addr = offer_packet.siaddr.s_addr ;
526 }
527
528 if(verbose){
529 printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr));
530 printf(_(" via %s\n"),inet_ntoa(via.sin_addr));
517 printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid)); 531 printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid));
518 } 532 }
519 533
520 /* check packet xid to see if its the same as the one we used in the discover packet */ 534 /* check packet xid to see if its the same as the one we used in the discover packet */
521 if(ntohl(offer_packet.xid)!=packet_xid){ 535 if(ntohl(offer_packet.xid)!=packet_xid){
522 if (verbose) 536 if(verbose)
523 printf(_("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); 537 printf(_("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid);
524 538
525 continue; 539 continue;
@@ -527,42 +541,42 @@ int get_dhcp_offer(int sock){
527 541
528 /* check hardware address */ 542 /* check hardware address */
529 result=OK; 543 result=OK;
530 if (verbose) 544 if(verbose)
531 printf("DHCPOFFER chaddr: "); 545 printf("DHCPOFFER chaddr: ");
532 546
533 for(x=0;x<ETHERNET_HARDWARE_ADDRESS_LENGTH;x++){ 547 for(x=0;x<ETHERNET_HARDWARE_ADDRESS_LENGTH;x++){
534 if (verbose) 548 if(verbose)
535 printf("%02X",(unsigned char)offer_packet.chaddr[x]); 549 printf("%02X",(unsigned char)offer_packet.chaddr[x]);
536 550
537 if(offer_packet.chaddr[x]!=client_hardware_address[x]) 551 if(offer_packet.chaddr[x]!=client_hardware_address[x])
538 result=ERROR; 552 result=ERROR;
539 } 553 }
540 if (verbose) 554 if(verbose)
541 printf("\n"); 555 printf("\n");
542 556
543 if(result==ERROR){ 557 if(result==ERROR){
544 if (verbose) 558 if(verbose)
545 printf(_("DHCPOFFER hardware address did not match our own - ignoring packet\n")); 559 printf(_("DHCPOFFER hardware address did not match our own - ignoring packet\n"));
546 560
547 continue; 561 continue;
548 } 562 }
549 563
550 if (verbose) { 564 if(verbose){
551 printf("DHCPOFFER ciaddr: %s\n",inet_ntoa(offer_packet.ciaddr)); 565 printf("DHCPOFFER ciaddr: %s\n",inet_ntoa(offer_packet.ciaddr));
552 printf("DHCPOFFER yiaddr: %s\n",inet_ntoa(offer_packet.yiaddr)); 566 printf("DHCPOFFER yiaddr: %s\n",inet_ntoa(offer_packet.yiaddr));
553 printf("DHCPOFFER siaddr: %s\n",inet_ntoa(offer_packet.siaddr)); 567 printf("DHCPOFFER siaddr: %s\n",inet_ntoa(offer_packet.siaddr));
554 printf("DHCPOFFER giaddr: %s\n",inet_ntoa(offer_packet.giaddr)); 568 printf("DHCPOFFER giaddr: %s\n",inet_ntoa(offer_packet.giaddr));
555 } 569 }
556 570
557 add_dhcp_offer(source.sin_addr,&offer_packet); 571 add_dhcp_offer(source.sin_addr,&offer_packet);
558 572
559 valid_responses++; 573 valid_responses++;
560 } 574 }
561 575
562 if (verbose) { 576 if(verbose){
563 printf(_("Total responses seen on the wire: %d\n"),responses); 577 printf(_("Total responses seen on the wire: %d\n"),responses);
564 printf(_("Valid responses for this machine: %d\n"),valid_responses); 578 printf(_("Valid responses for this machine: %d\n"),valid_responses);
565 } 579 }
566 580
567 return OK; 581 return OK;
568 } 582 }
@@ -576,7 +590,7 @@ int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in
576 590
577 result=sendto(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)dest,sizeof(*dest)); 591 result=sendto(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)dest,sizeof(*dest));
578 592
579 if (verbose) 593 if(verbose)
580 printf(_("send_dhcp_packet result: %d\n"),result); 594 printf(_("send_dhcp_packet result: %d\n"),result);
581 595
582 if(result<0) 596 if(result<0)
@@ -605,7 +619,7 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st
605 619
606 /* make sure some data has arrived */ 620 /* make sure some data has arrived */
607 if(!FD_ISSET(sock,&readfds)){ 621 if(!FD_ISSET(sock,&readfds)){
608 if (verbose) 622 if(verbose)
609 printf(_("No (more) data received\n")); 623 printf(_("No (more) data received\n"));
610 return ERROR; 624 return ERROR;
611 } 625 }
@@ -617,24 +631,24 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st
617 bzero(&source_address,sizeof(source_address)); 631 bzero(&source_address,sizeof(source_address));
618 address_size=sizeof(source_address); 632 address_size=sizeof(source_address);
619 recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size); 633 recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size);
620 if (verbose) 634 if(verbose)
621 printf("recv_result_1: %d\n",recv_result); 635 printf("recv_result_1: %d\n",recv_result);
622 recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size); 636 recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size);
623 if (verbose) 637 if(verbose)
624 printf("recv_result_2: %d\n",recv_result); 638 printf("recv_result_2: %d\n",recv_result);
625 639
626 if(recv_result==-1){ 640 if(recv_result==-1){
627 if (verbose) { 641 if(verbose){
628 printf(_("recvfrom() failed, ")); 642 printf(_("recvfrom() failed, "));
629 printf("errno: (%d) -> %s\n",errno,strerror(errno)); 643 printf("errno: (%d) -> %s\n",errno,strerror(errno));
630 } 644 }
631 return ERROR; 645 return ERROR;
632 } 646 }
633 else{ 647 else{
634 if (verbose) { 648 if(verbose){
635 printf(_("receive_dhcp_packet() result: %d\n"),recv_result); 649 printf(_("receive_dhcp_packet() result: %d\n"),recv_result);
636 printf(_("receive_dhcp_packet() source: %s\n"),inet_ntoa(source_address.sin_addr)); 650 printf(_("receive_dhcp_packet() source: %s\n"),inet_ntoa(source_address.sin_addr));
637 } 651 }
638 652
639 memcpy(address,&source_address,sizeof(source_address)); 653 memcpy(address,&source_address,sizeof(source_address));
640 return OK; 654 return OK;
@@ -666,7 +680,7 @@ int create_dhcp_socket(void){
666 exit(STATE_UNKNOWN); 680 exit(STATE_UNKNOWN);
667 } 681 }
668 682
669 if (verbose) 683 if(verbose)
670 printf("DHCP socket: %d\n",sock); 684 printf("DHCP socket: %d\n",sock);
671 685
672 /* set the reuse address flag so we don't get errors when restarting */ 686 /* set the reuse address flag so we don't get errors when restarting */
@@ -722,13 +736,14 @@ int add_requested_server(struct in_addr server_address){
722 return ERROR; 736 return ERROR;
723 737
724 new_server->server_address=server_address; 738 new_server->server_address=server_address;
739 new_server->answered=FALSE;
725 740
726 new_server->next=requested_server_list; 741 new_server->next=requested_server_list;
727 requested_server_list=new_server; 742 requested_server_list=new_server;
728 743
729 requested_servers++; 744 requested_servers++;
730 745
731 if (verbose) 746 if(verbose)
732 printf(_("Requested server address: %s\n"),inet_ntoa(new_server->server_address)); 747 printf(_("Requested server address: %s\n"),inet_ntoa(new_server->server_address));
733 748
734 return OK; 749 return OK;
@@ -761,32 +776,29 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
761 /* get option length */ 776 /* get option length */
762 option_length=offer_packet->options[x++]; 777 option_length=offer_packet->options[x++];
763 778
764 if (verbose) 779 if(verbose)
765 printf("Option: %d (0x%02X)\n",option_type,option_length); 780 printf("Option: %d (0x%02X)\n",option_type,option_length);
766 781
767 /* get option data */ 782 /* get option data */
768 if(option_type==DHCP_OPTION_LEASE_TIME) { 783 if(option_type==DHCP_OPTION_LEASE_TIME){
769 memcpy(&dhcp_lease_time, &offer_packet->options[x], 784 memcpy(&dhcp_lease_time, &offer_packet->options[x],sizeof(dhcp_lease_time));
770 sizeof(dhcp_lease_time)); 785 dhcp_lease_time = ntohl(dhcp_lease_time);
771 dhcp_lease_time = ntohl(dhcp_lease_time); 786 }
772 } 787 if(option_type==DHCP_OPTION_RENEWAL_TIME){
773 if(option_type==DHCP_OPTION_RENEWAL_TIME) { 788 memcpy(&dhcp_renewal_time, &offer_packet->options[x],sizeof(dhcp_renewal_time));
774 memcpy(&dhcp_renewal_time, &offer_packet->options[x], 789 dhcp_renewal_time = ntohl(dhcp_renewal_time);
775 sizeof(dhcp_renewal_time)); 790 }
776 dhcp_renewal_time = ntohl(dhcp_renewal_time); 791 if(option_type==DHCP_OPTION_REBINDING_TIME){
777 } 792 memcpy(&dhcp_rebinding_time, &offer_packet->options[x],sizeof(dhcp_rebinding_time));
778 if(option_type==DHCP_OPTION_REBINDING_TIME) { 793 dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
779 memcpy(&dhcp_rebinding_time, &offer_packet->options[x], 794 }
780 sizeof(dhcp_rebinding_time));
781 dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
782 }
783 795
784 /* skip option data we're ignoring */ 796 /* skip option data we're ignoring */
785 else 797 else
786 for(y=0;y<option_length;y++,x++); 798 for(y=0;y<option_length;y++,x++);
787 } 799 }
788 800
789 if (verbose) { 801 if(verbose){
790 if(dhcp_lease_time==DHCP_INFINITE_TIME) 802 if(dhcp_lease_time==DHCP_INFINITE_TIME)
791 printf(_("Lease Time: Infinite\n")); 803 printf(_("Lease Time: Infinite\n"));
792 else 804 else
@@ -798,7 +810,7 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
798 if(dhcp_rebinding_time==DHCP_INFINITE_TIME) 810 if(dhcp_rebinding_time==DHCP_INFINITE_TIME)
799 printf(_("Rebinding Time: Infinite\n")); 811 printf(_("Rebinding Time: Infinite\n"));
800 printf(_("Rebinding Time: %lu seconds\n"),(unsigned long)dhcp_rebinding_time); 812 printf(_("Rebinding Time: %lu seconds\n"),(unsigned long)dhcp_rebinding_time);
801 } 813 }
802 814
803 new_offer=(dhcp_offer *)malloc(sizeof(dhcp_offer)); 815 new_offer=(dhcp_offer *)malloc(sizeof(dhcp_offer));
804 816
@@ -812,10 +824,10 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
812 new_offer->rebinding_time=dhcp_rebinding_time; 824 new_offer->rebinding_time=dhcp_rebinding_time;
813 825
814 826
815 if (verbose) { 827 if(verbose){
816 printf(_("Added offer from server @ %s"),inet_ntoa(new_offer->server_address)); 828 printf(_("Added offer from server @ %s"),inet_ntoa(new_offer->server_address));
817 printf(_(" of IP address %s\n"),inet_ntoa(new_offer->offered_address)); 829 printf(_(" of IP address %s\n"),inet_ntoa(new_offer->offered_address));
818 } 830 }
819 831
820 /* add new offer to head of list */ 832 /* add new offer to head of list */
821 new_offer->next=dhcp_offer_list; 833 new_offer->next=dhcp_offer_list;
@@ -880,11 +892,17 @@ int get_results(void){
880 892
881 /* see if the servers we wanted a response from talked to us or not */ 893 /* see if the servers we wanted a response from talked to us or not */
882 if(!memcmp(&temp_offer->server_address,&temp_server->server_address,sizeof(temp_server->server_address))){ 894 if(!memcmp(&temp_offer->server_address,&temp_server->server_address,sizeof(temp_server->server_address))){
883 if (verbose) { 895 if(verbose){
884 printf(_("DHCP Server Match: Offerer=%s"),inet_ntoa(temp_offer->server_address)); 896 printf(_("DHCP Server Match: Offerer=%s"),inet_ntoa(temp_offer->server_address));
885 printf(_(" Requested=%s\n"),inet_ntoa(temp_server->server_address)); 897 printf(_(" Requested=%s"),inet_ntoa(temp_server->server_address));
886 } 898 if(temp_server->answered)
887 requested_responses++; 899 printf(_(" (duplicate)"));
900 printf(_("\n"));
901 }
902 if(temp_server->answered == FALSE){
903 requested_responses++;
904 temp_server->answered=TRUE;
905 }
888 } 906 }
889 } 907 }
890 } 908 }
@@ -916,14 +934,14 @@ int get_results(void){
916 else if(request_specific_address==TRUE && received_requested_address==FALSE) 934 else if(request_specific_address==TRUE && received_requested_address==FALSE)
917 result=STATE_WARNING; 935 result=STATE_WARNING;
918 936
919 if(result==0) /* garrett honeycutt 2005 */ 937 if(result==0) /* garrett honeycutt 2005 */
920 printf("OK: "); 938 printf("OK: ");
921 else if(result==1) 939 else if(result==1)
922 printf("WARNING: "); 940 printf("WARNING: ");
923 else if(result==2) 941 else if(result==2)
924 printf("CRITICAL: "); 942 printf("CRITICAL: ");
925 else if(result==3) 943 else if(result==3)
926 printf("UNKNOWN: "); 944 printf("UNKNOWN: ");
927 945
928 /* we didn't receive any DHCPOFFERs */ 946 /* we didn't receive any DHCPOFFERs */
929 if(dhcp_offer_list==NULL){ 947 if(dhcp_offer_list==NULL){
@@ -1081,107 +1099,112 @@ int validate_arguments(void){
1081 return OK; 1099 return OK;
1082 } 1100 }
1083 1101
1084#if defined(__sun__) || defined(__solaris__) || defined(__hpux__)
1085 1102
1086 /* Kompf 2000-2003 see ACKNOWLEDGEMENTS */ 1103#if defined(__sun__) || defined(__solaris__) || defined(__hpux__)
1104/* Kompf 2000-2003 see ACKNOWLEDGEMENTS */
1087 1105
1088/* get a message from a stream; return type of message */ 1106/* get a message from a stream; return type of message */
1089static int get_msg(int fd) 1107static int get_msg(int fd){
1090{ 1108 int flags = 0;
1091 int flags = 0; 1109 int res, ret;
1092 int res, ret; 1110 ctl_area[0] = 0;
1093 ctl_area[0] = 0; 1111 dat_area[0] = 0;
1094 dat_area[0] = 0; 1112 ret = 0;
1095 ret = 0; 1113 res = getmsg(fd, &ctl, &dat, &flags);
1096 res = getmsg(fd, &ctl, &dat, &flags); 1114
1097 1115 if(res < 0){
1098 if(res < 0) { 1116 if(errno == EINTR){
1099 if(errno == EINTR) { 1117 return(GOT_INTR);
1100 return(GOT_INTR); 1118 }
1101 } else { 1119 else{
1102 printf("%s\n", "get_msg FAILED."); 1120 printf("%s\n", "get_msg FAILED.");
1103 return(GOT_ERR); 1121 return(GOT_ERR);
1104 } 1122 }
1105 } 1123 }
1106 if(ctl.len > 0) { 1124 if(ctl.len > 0){
1107 ret |= GOT_CTRL; 1125 ret |= GOT_CTRL;
1108 } 1126 }
1109 if(dat.len > 0) { 1127 if(dat.len > 0){
1110 ret |= GOT_DATA; 1128 ret |= GOT_DATA;
1111 } 1129 }
1112 return(ret); 1130
1113} 1131 return(ret);
1132 }
1114 1133
1115/* verify that dl_primitive in ctl_area = prim */ 1134/* verify that dl_primitive in ctl_area = prim */
1116static int check_ctrl(int prim) 1135static int check_ctrl(int prim){
1117{ 1136 dl_error_ack_t *err_ack = (dl_error_ack_t *)ctl_area;
1118 dl_error_ack_t *err_ack = (dl_error_ack_t *)ctl_area; 1137
1119 if(err_ack->dl_primitive != prim) { 1138 if(err_ack->dl_primitive != prim){
1120 printf(_("Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n"), strerror(errno)); 1139 printf(_("Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n"), strerror(errno));
1121 exit(STATE_UNKNOWN); 1140 exit(STATE_UNKNOWN);
1122 } 1141 }
1123 return 0; 1142
1124} 1143 return 0;
1144 }
1125 1145
1126/* put a control message on a stream */ 1146/* put a control message on a stream */
1127static int put_ctrl(int fd, int len, int pri) 1147static int put_ctrl(int fd, int len, int pri){
1128{ 1148
1129 ctl.len = len; 1149 ctl.len = len;
1130 if(putmsg(fd, &ctl, 0, pri) < 0) { 1150 if(putmsg(fd, &ctl, 0, pri) < 0){
1131 printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno)); 1151 printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno));
1132 exit(STATE_UNKNOWN); 1152 exit(STATE_UNKNOWN);
1133 } 1153 }
1134 return 0; 1154
1135} 1155 return 0;
1156 }
1136 1157
1137/* put a control + data message on a stream */ 1158/* put a control + data message on a stream */
1138static int put_both(int fd, int clen, int dlen, int pri) 1159static int put_both(int fd, int clen, int dlen, int pri){
1139{ 1160
1140 ctl.len = clen; 1161 ctl.len = clen;
1141 dat.len = dlen; 1162 dat.len = dlen;
1142 if(putmsg(fd, &ctl, &dat, pri) < 0) { 1163 if(putmsg(fd, &ctl, &dat, pri) < 0){
1143 printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno)); 1164 printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno));
1144 exit(STATE_UNKNOWN); 1165 exit(STATE_UNKNOWN);
1145 } 1166 }
1146 return 0; 1167
1147} 1168 return 0;
1169 }
1148 1170
1149/* open file descriptor and attach */ 1171/* open file descriptor and attach */
1150static int dl_open(const char *dev, int unit, int *fd) 1172static int dl_open(const char *dev, int unit, int *fd){
1151{ 1173 dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area;
1152 dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area; 1174
1153 if((*fd = open(dev, O_RDWR)) == -1) { 1175 if((*fd = open(dev, O_RDWR)) == -1){
1154 printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno)); 1176 printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno));
1155 exit(STATE_UNKNOWN); 1177 exit(STATE_UNKNOWN);
1156 } 1178 }
1157 attach_req->dl_primitive = DL_ATTACH_REQ; 1179 attach_req->dl_primitive = DL_ATTACH_REQ;
1158 attach_req->dl_ppa = unit; 1180 attach_req->dl_ppa = unit;
1159 put_ctrl(*fd, sizeof(dl_attach_req_t), 0); 1181 put_ctrl(*fd, sizeof(dl_attach_req_t), 0);
1160 get_msg(*fd); 1182 get_msg(*fd);
1161 return check_ctrl(DL_OK_ACK); 1183 return check_ctrl(DL_OK_ACK);
1162} 1184 }
1163 1185
1164/* send DL_BIND_REQ */ 1186/* send DL_BIND_REQ */
1165static int dl_bind(int fd, int sap, u_char *addr) 1187static int dl_bind(int fd, int sap, u_char *addr){
1166{ 1188 dl_bind_req_t *bind_req = (dl_bind_req_t *)ctl_area;
1167 dl_bind_req_t *bind_req = (dl_bind_req_t *)ctl_area; 1189 dl_bind_ack_t *bind_ack = (dl_bind_ack_t *)ctl_area;
1168 dl_bind_ack_t *bind_ack = (dl_bind_ack_t *)ctl_area; 1190
1169 bind_req->dl_primitive = DL_BIND_REQ; 1191 bind_req->dl_primitive = DL_BIND_REQ;
1170 bind_req->dl_sap = sap; 1192 bind_req->dl_sap = sap;
1171 bind_req->dl_max_conind = 1; 1193 bind_req->dl_max_conind = 1;
1172 bind_req->dl_service_mode = DL_CLDLS; 1194 bind_req->dl_service_mode = DL_CLDLS;
1173 bind_req->dl_conn_mgmt = 0; 1195 bind_req->dl_conn_mgmt = 0;
1174 bind_req->dl_xidtest_flg = 0; 1196 bind_req->dl_xidtest_flg = 0;
1175 put_ctrl(fd, sizeof(dl_bind_req_t), 0); 1197 put_ctrl(fd, sizeof(dl_bind_req_t), 0);
1176 get_msg(fd); 1198 get_msg(fd);
1177 if (GOT_ERR == check_ctrl(DL_BIND_ACK)) { 1199 if GOT_ERR == check_ctrl(DL_BIND_ACK)){
1178 printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno)); 1200 printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno));
1179 exit(STATE_UNKNOWN); 1201 exit(STATE_UNKNOWN);
1180 } 1202 }
1181 bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr, 1203 bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr,
1182 bind_ack->dl_addr_length); 1204 bind_ack->dl_addr_length);
1183 return 0; 1205
1184} 1206 return 0;
1207 }
1185 1208
1186/*********************************************************************** 1209/***********************************************************************
1187 * interface: 1210 * interface:
@@ -1195,23 +1218,22 @@ static int dl_bind(int fd, int sap, u_char *addr)
1195 * 1218 *
1196 ***********************************************************************/ 1219 ***********************************************************************/
1197 1220
1198long mac_addr_dlpi( const char *dev, int unit, u_char *addr) { 1221long mac_addr_dlpi( const char *dev, int unit, u_char *addr){
1199
1200 int fd; 1222 int fd;
1201 u_char mac_addr[25]; 1223 u_char mac_addr[25];
1202 1224
1203 if (GOT_ERR != dl_open(dev, unit, &fd)) { 1225 if(GOT_ERR != dl_open(dev, unit, &fd)){
1204 if (GOT_ERR != dl_bind(fd, INSAP, mac_addr)) { 1226 if(GOT_ERR != dl_bind(fd, INSAP, mac_addr)){
1205 bcopy( mac_addr, addr, 6); 1227 bcopy( mac_addr, addr, 6);
1206 return 0; 1228 return 0;
1207 } 1229 }
1208 } 1230 }
1209 close(fd); 1231 close(fd);
1210 return -1;
1211}
1212 1232
1213 /* Kompf 2000-2003 */ 1233 return -1;
1234 }
1214 1235
1236/* Kompf 2000-2003 */
1215#endif 1237#endif
1216 1238
1217 1239
@@ -1240,14 +1262,17 @@ void print_help(void){
1240 Seconds to wait for DHCPOFFER before timeout occurs\n\ 1262 Seconds to wait for DHCPOFFER before timeout occurs\n\
1241 -i, --interface=STRING\n\ 1263 -i, --interface=STRING\n\
1242 Interface to to use for listening (i.e. eth0)\n")); 1264 Interface to to use for listening (i.e. eth0)\n"));
1243} 1265
1266 return;
1267 }
1244 1268
1245 1269
1246void print_usage(void) 1270void print_usage(void){
1247{
1248 printf("\ 1271 printf("\
1249Usage: %s [-s serverip] [-r requestedip] [-t timeout] [-i interface] [-v]\n",progname); 1272Usage: %s [-s serverip] [-r requestedip] [-t timeout] [-i interface] [-v]\n",progname);
1250} 1273
1274 return;
1275 }
1251 1276
1252 1277
1253 1278