Code

--help output cleanup (plus removal of spaces on blank lines)
[nagiosplug.git] / plugins-root / check_dhcp.c
1 /*****************************************************************************
2
3 * Nagios check_dhcp plugin
4
5 * License: GPL
6 * Copyright (c) 2001-2004 Ethan Galstad (nagios@nagios.org)
7 * Copyright (c) 2001-2007 Nagios Plugin Development Team
8
9 * Last Modified: $Date$
10
11 * Description:
12
13 * This file contains the check_dhcp plugin
14
15 * This plugin tests the availability of DHCP servers on a network.
16
17 * Unicast mode was originally implemented by Heiti of Boras Kommun with
18 * general improvements as well as usability fixes and "forward"-porting by
19 * Andreas Ericsson of OP5 AB.
20
21
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
26
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 * GNU General Public License for more details.
31
32 * You should have received a copy of the GNU General Public License
33 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
34
35 * $Id$
36
37 *****************************************************************************/
39 const char *progname = "check_dhcp";
40 const char *revision = "$Revision$";
41 const char *copyright = "2001-2007";
42 const char *email = "nagiosplug-devel@lists.sourceforge.net";
44 #include "common.h"
45 #include "netutils.h"
46 #include "utils.h"
48 #include <ctype.h>
49 #include <stdio.h>
50 #include <stdlib.h>
51 #include <string.h>
52 #include <errno.h>
53 #include <unistd.h>
54 #include <sys/time.h>
55 #include <sys/ioctl.h>
56 #include <fcntl.h>
57 #include <getopt.h>
58 #include <sys/socket.h>
59 #include <sys/types.h>
60 #include <netdb.h>
61 #include <netinet/in.h>
62 #include <net/if.h>
63 #include <arpa/inet.h>
64 #if HAVE_SYS_SOCKIO_H
65 #include <sys/sockio.h>
66 #endif
68 #if defined( __linux__ )
70 #include <linux/if_ether.h>
71 #include <features.h>
73 #elif defined (__bsd__)
75 #include <netinet/if_ether.h>
76 #include <sys/param.h>
77 #include <sys/sysctl.h>
78 #include <net/if_dl.h>
80 #elif defined(__sun__) || defined(__solaris__) || defined(__hpux__)
82 #define INSAP 22 
83 #define OUTSAP 24 
85 #include <signal.h>
86 #include <ctype.h>
87 #include <sys/stropts.h>
88 #include <sys/poll.h>
89 #include <sys/dlpi.h>
91 #define bcopy(source, destination, length) memcpy(destination, source, length)
93 #define AREA_SZ 5000            /* buffer length in bytes */ 
94 static u_long ctl_area[AREA_SZ];
95 static u_long dat_area[AREA_SZ];
96 static struct strbuf ctl = {AREA_SZ, 0, (char *)ctl_area};
97 static struct strbuf dat = {AREA_SZ, 0, (char *)dat_area};
99 #define GOT_CTRL 1 
100 #define GOT_DATA 2 
101 #define GOT_BOTH 3 
102 #define GOT_INTR 4 
103 #define GOT_ERR 128 
105 #define u_int8_t         uint8_t
106 #define u_int16_t       uint16_t
107 #define u_int32_t       uint32_t
109 static int get_msg(int);
110 static int check_ctrl(int);
111 static int put_ctrl(int, int, int);
112 static int put_both(int, int, int, int);
113 static int dl_open(const char *, int, int *);
114 static int dl_bind(int, int, u_char *);
115 long mac_addr_dlpi( const char *, int, u_char *);
117 #endif
121 /**** Common definitions ****/
123 #define OK                0
124 #define ERROR             -1
126 #define FALSE             0
127 #define TRUE              1
130 /**** DHCP definitions ****/
132 #define MAX_DHCP_CHADDR_LENGTH           16
133 #define MAX_DHCP_SNAME_LENGTH            64
134 #define MAX_DHCP_FILE_LENGTH             128
135 #define MAX_DHCP_OPTIONS_LENGTH          312
138 typedef struct dhcp_packet_struct{
139         u_int8_t  op;                   /* packet type */
140         u_int8_t  htype;                /* type of hardware address for this machine (Ethernet, etc) */
141         u_int8_t  hlen;                 /* length of hardware address (of this machine) */
142         u_int8_t  hops;                 /* hops */
143         u_int32_t xid;                  /* random transaction id number - chosen by this machine */
144         u_int16_t secs;                 /* seconds used in timing */
145         u_int16_t flags;                /* flags */
146         struct in_addr ciaddr;          /* IP address of this machine (if we already have one) */
147         struct in_addr yiaddr;          /* IP address of this machine (offered by the DHCP server) */
148         struct in_addr siaddr;          /* IP address of DHCP server */
149         struct in_addr giaddr;          /* IP address of DHCP relay */
150         unsigned char chaddr [MAX_DHCP_CHADDR_LENGTH];      /* hardware address of this machine */
151         char sname [MAX_DHCP_SNAME_LENGTH];    /* name of DHCP server */
152         char file [MAX_DHCP_FILE_LENGTH];      /* boot file name (used for diskless booting?) */
153         char options[MAX_DHCP_OPTIONS_LENGTH];  /* options */
154         }dhcp_packet;
157 typedef struct dhcp_offer_struct{
158         struct in_addr server_address;   /* address of DHCP server that sent this offer */
159         struct in_addr offered_address;  /* the IP address that was offered to us */
160         u_int32_t lease_time;            /* lease time in seconds */
161         u_int32_t renewal_time;          /* renewal time in seconds */
162         u_int32_t rebinding_time;        /* rebinding time in seconds */
163         struct dhcp_offer_struct *next;
164         }dhcp_offer;
167 typedef struct requested_server_struct{
168         struct in_addr server_address;
169         int answered;
170         struct requested_server_struct *next;
171         }requested_server;
174 #define BOOTREQUEST     1
175 #define BOOTREPLY       2
177 #define DHCPDISCOVER    1
178 #define DHCPOFFER       2
179 #define DHCPREQUEST     3
180 #define DHCPDECLINE     4
181 #define DHCPACK         5
182 #define DHCPNACK        6
183 #define DHCPRELEASE     7
185 #define DHCP_OPTION_MESSAGE_TYPE        53
186 #define DHCP_OPTION_HOST_NAME           12
187 #define DHCP_OPTION_BROADCAST_ADDRESS   28
188 #define DHCP_OPTION_REQUESTED_ADDRESS   50
189 #define DHCP_OPTION_LEASE_TIME          51
190 #define DHCP_OPTION_SERVER_IDENTIFIER   54
191 #define DHCP_OPTION_RENEWAL_TIME        58
192 #define DHCP_OPTION_REBINDING_TIME      59
193 #define DHCP_OPTION_END                 255
195 #define DHCP_INFINITE_TIME              0xFFFFFFFF
197 #define DHCP_BROADCAST_FLAG 32768
198 #define DHCP_UNICAST_FLAG   0
200 #define DHCP_SERVER_PORT   67
201 #define DHCP_CLIENT_PORT   68
203 #define ETHERNET_HARDWARE_ADDRESS            1     /* used in htype field of dhcp packet */
204 #define ETHERNET_HARDWARE_ADDRESS_LENGTH     6     /* length of Ethernet hardware addresses */
206 u_int8_t unicast = 0;        /* unicast mode: mimic a DHCP relay */
207 struct in_addr my_ip;        /* our address (required for relay) */
208 struct in_addr dhcp_ip;      /* server to query (if in unicast mode) */
209 unsigned char client_hardware_address[MAX_DHCP_CHADDR_LENGTH]="";
210 unsigned char *user_specified_mac=NULL;
212 char network_interface_name[IFNAMSIZ]="eth0";
214 u_int32_t packet_xid=0;
216 u_int32_t dhcp_lease_time=0;
217 u_int32_t dhcp_renewal_time=0;
218 u_int32_t dhcp_rebinding_time=0;
220 int dhcpoffer_timeout=2;
222 dhcp_offer *dhcp_offer_list=NULL;
223 requested_server *requested_server_list=NULL;
225 int valid_responses=0;     /* number of valid DHCPOFFERs we received */
226 int requested_servers=0;   
227 int requested_responses=0;
229 int request_specific_address=FALSE;
230 int received_requested_address=FALSE;
231 int verbose=0;
232 struct in_addr requested_address;
235 int process_arguments(int, char **);
236 int call_getopt(int, char **);
237 int validate_arguments(void);
238 void print_usage(void);
239 void print_help(void);
241 void resolve_host(const char *in,struct in_addr *out);
242 unsigned char *mac_aton(const char *);
243 void print_hardware_address(const unsigned char *);
244 int get_hardware_address(int,char *);
245 int get_ip_address(int,char *);
247 int send_dhcp_discover(int);
248 int get_dhcp_offer(int);
250 int get_results(void);
252 int add_dhcp_offer(struct in_addr,dhcp_packet *);
253 int free_dhcp_offer_list(void);
254 int free_requested_server_list(void);
256 int create_dhcp_socket(void);
257 int close_dhcp_socket(int);
258 int send_dhcp_packet(void *,int,int,struct sockaddr_in *);
259 int receive_dhcp_packet(void *,int,int,int,struct sockaddr_in *);
263 int main(int argc, char **argv){
264         int dhcp_socket;
265         int result = STATE_UNKNOWN;
267         setlocale (LC_ALL, "");
268         bindtextdomain (PACKAGE, LOCALEDIR);
269         textdomain (PACKAGE);
271         if(process_arguments(argc,argv)!=OK){
272                 usage4 (_("Could not parse arguments"));
273                 }
275         /* this plugin almost certainly needs root permissions. */
276         np_warn_if_not_root();
278         /* create socket for DHCP communications */
279         dhcp_socket=create_dhcp_socket();
281         /* get hardware address of client machine */
282         if(user_specified_mac!=NULL)
283                 memcpy(client_hardware_address,user_specified_mac,6);
284         else
285                 get_hardware_address(dhcp_socket,network_interface_name);
287         if(unicast) /* get IP address of client machine */
288                 get_ip_address(dhcp_socket,network_interface_name);
290         /* send DHCPDISCOVER packet */
291         send_dhcp_discover(dhcp_socket);
293         /* wait for a DHCPOFFER packet */
294         get_dhcp_offer(dhcp_socket);
296         /* close socket we created */
297         close_dhcp_socket(dhcp_socket);
299         /* determine state/plugin output to return */
300         result=get_results();
302         /* free allocated memory */
303         free_dhcp_offer_list();
304         free_requested_server_list();
306         return result;
307         }
311 /* determines hardware address on client machine */
312 int get_hardware_address(int sock,char *interface_name){
314 #if defined(__linux__)
315         struct ifreq ifr;
317         strncpy((char *)&ifr.ifr_name,interface_name,sizeof(ifr.ifr_name)-1);
318         ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0';
320         /* try and grab hardware address of requested interface */
321         if(ioctl(sock,SIOCGIFHWADDR,&ifr)<0){
322                 printf(_("Error: Could not get hardware address of interface '%s'\n"),interface_name);
323                 exit(STATE_UNKNOWN);
324                 }
326         memcpy(&client_hardware_address[0],&ifr.ifr_hwaddr.sa_data,6);
328 #elif defined(__bsd__)
329                                                 /* King 2004    see ACKNOWLEDGEMENTS */
331         int                     mib[6], len;
332         char                    *buf;
333         unsigned char           *ptr;
334         struct if_msghdr        *ifm;
335         struct sockaddr_dl      *sdl;
337         mib[0] = CTL_NET;
338         mib[1] = AF_ROUTE;
339         mib[2] = 0;
340         mib[3] = AF_LINK;
341         mib[4] = NET_RT_IFLIST;
343         if((mib[5] = if_nametoindex(interface_name)) == 0){
344                 printf(_("Error: if_nametoindex error - %s.\n"), strerror(errno));
345                 exit(STATE_UNKNOWN);
346                 }
348         if(sysctl(mib, 6, NULL, &len, NULL, 0) < 0){
349                 printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno));
350                 exit(STATE_UNKNOWN);
351                 }
353         if((buf = malloc(len)) == NULL){
354                 printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno));
355                 exit(4);
356                 }
358         if(sysctl(mib, 6, buf, &len, NULL, 0) < 0){
359                 printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno));
360                 exit(STATE_UNKNOWN);
361                 }
363         ifm = (struct if_msghdr *)buf;
364         sdl = (struct sockaddr_dl *)(ifm + 1);
365         ptr = (unsigned char *)LLADDR(sdl);
366         memcpy(&client_hardware_address[0], ptr, 6) ;
367                                                 /* King 2004 */
369 #elif defined(__sun__) || defined(__solaris__)
371                                                 /* Kompf 2000-2003      see ACKNOWLEDGEMENTS */
372         long stat;
373         char dev[20] = "/dev/";
374         char *p;
375         int unit;
377         for(p = interface_name; *p && isalpha(*p); p++)
378                 /* no-op */ ;
379         if( p != '\0' ){
380                 unit = atoi(p) ;
381                 *p = '\0' ;
382                 strncat(dev, interface_name, 6) ;
383                 } 
384         else{
385                 printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name);
386                 exit(STATE_UNKNOWN);
387                 }
388         stat = mac_addr_dlpi(dev, unit, client_hardware_address);
389         if(stat != 0){
390                 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
391                 exit(STATE_UNKNOWN);
392                 }
394 #elif defined(__hpux__)
396         long stat;
397         char dev[20] = "/dev/dlpi" ;
398         int unit = 0;
400         stat = mac_addr_dlpi(dev, unit, client_hardware_address);
401         if(stat != 0){
402                 printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit);
403                 exit(STATE_UNKNOWN);
404                 }
405                                                 /* Kompf 2000-2003 */
407 #else
408         printf(_("Error: can't get MAC address for this architecture.  Use the --mac option.\n"));
409         exit(STATE_UNKNOWN);
410 #endif
412         if(verbose)
413                 print_hardware_address(client_hardware_address);
415         return OK;
416         }
418 /* determines IP address of the client interface */
419 int get_ip_address(int sock,char *interface_name){
420 #if defined(SIOCGIFADDR)
421         struct ifreq ifr;
423         strncpy((char *)&ifr.ifr_name,interface_name,sizeof(ifr.ifr_name)-1);
424         ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0';
426         if(ioctl(sock,SIOCGIFADDR,&ifr)<0){
427                 printf(_("Error: Cannot determine IP address of interface %s\n"),
428                         interface_name);
429                 exit(STATE_UNKNOWN);
430                 }
432         my_ip=((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
434 #else
435         printf(_("Error: Cannot get interface IP address on this platform.\n"));
436         exit(STATE_UNKNOWN);
437 #endif
439         if(verbose)
440                 printf(_("Pretending to be relay client %s\n"),inet_ntoa(my_ip));
442         return OK;
443         }
445 /* sends a DHCPDISCOVER broadcast message in an attempt to find DHCP servers */
446 int send_dhcp_discover(int sock){
447         dhcp_packet discover_packet;
448         struct sockaddr_in sockaddr_broadcast;
449     unsigned short opts;
452         /* clear the packet data structure */
453         bzero(&discover_packet,sizeof(discover_packet));
456         /* boot request flag (backward compatible with BOOTP servers) */
457         discover_packet.op=BOOTREQUEST;
459         /* hardware address type */
460         discover_packet.htype=ETHERNET_HARDWARE_ADDRESS;
462         /* length of our hardware address */
463         discover_packet.hlen=ETHERNET_HARDWARE_ADDRESS_LENGTH;
465         /*
466          * transaction ID is supposed to be random.  We won't use the address so
467          * we don't care about high entropy here.  time(2) is good enough.
468          */
469         srand(time(NULL));
470         packet_xid=random();
471         discover_packet.xid=htonl(packet_xid);
473         /**** WHAT THE HECK IS UP WITH THIS?!?  IF I DON'T MAKE THIS CALL, ONLY ONE SERVER RESPONSE IS PROCESSED!!!! ****/
474         /* downright bizzarre... */
475         ntohl(discover_packet.xid);
477         /*discover_packet.secs=htons(65535);*/
478         discover_packet.secs=0xFF;
480         /*
481          * server needs to know if it should broadcast or unicast its response:
482          * 0x8000L == 32768 == 1 << 15 == broadcast, 0 == unicast
483          */
484         discover_packet.flags = unicast ? 0 : htons(DHCP_BROADCAST_FLAG);
486         /* our hardware address */
487         memcpy(discover_packet.chaddr,client_hardware_address,ETHERNET_HARDWARE_ADDRESS_LENGTH);
489         /* first four bytes of options field is magic cookie (as per RFC 2132) */
490         discover_packet.options[0]='\x63';
491         discover_packet.options[1]='\x82';
492         discover_packet.options[2]='\x53';
493         discover_packet.options[3]='\x63';
495     opts = 4;
496         /* DHCP message type is embedded in options field */
497         discover_packet.options[opts++]=DHCP_OPTION_MESSAGE_TYPE;    /* DHCP message type option identifier */
498         discover_packet.options[opts++]='\x01';               /* DHCP message option length in bytes */
499         discover_packet.options[opts++]=DHCPDISCOVER;
501         /* the IP address we're requesting */
502         if(request_specific_address==TRUE){
503                 discover_packet.options[opts++]=DHCP_OPTION_REQUESTED_ADDRESS;
504                 discover_packet.options[opts++]='\x04';
505                 memcpy(&discover_packet.options[opts],&requested_address,sizeof(requested_address));
506                 opts += sizeof(requested_address);
507                 }
508         discover_packet.options[opts++]=DHCP_OPTION_END;
510         /* unicast fields */
511         if(unicast)
512                 discover_packet.giaddr.s_addr = my_ip.s_addr;
514         /* see RFC 1542, 4.1.1 */
515         discover_packet.hops = unicast ? 1 : 0;
517         /* send the DHCPDISCOVER packet to broadcast address */
518         sockaddr_broadcast.sin_family=AF_INET;
519         sockaddr_broadcast.sin_port=htons(DHCP_SERVER_PORT);
520         sockaddr_broadcast.sin_addr.s_addr = unicast ? dhcp_ip.s_addr : INADDR_BROADCAST;
521         bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero));
524         if(verbose){
525                 printf(_("DHCPDISCOVER to %s port %d\n"),inet_ntoa(sockaddr_broadcast.sin_addr),ntohs(sockaddr_broadcast.sin_port));
526                 printf("DHCPDISCOVER XID: %u (0x%X)\n",ntohl(discover_packet.xid),ntohl(discover_packet.xid));
527                 printf("DHCDISCOVER ciaddr:  %s\n",inet_ntoa(discover_packet.ciaddr));
528                 printf("DHCDISCOVER yiaddr:  %s\n",inet_ntoa(discover_packet.yiaddr));
529                 printf("DHCDISCOVER siaddr:  %s\n",inet_ntoa(discover_packet.siaddr));
530                 printf("DHCDISCOVER giaddr:  %s\n",inet_ntoa(discover_packet.giaddr));
531                 }
533         /* send the DHCPDISCOVER packet out */
534         send_dhcp_packet(&discover_packet,sizeof(discover_packet),sock,&sockaddr_broadcast);
536         if(verbose) 
537                 printf("\n\n");
539         return OK;
540         }
545 /* waits for a DHCPOFFER message from one or more DHCP servers */
546 int get_dhcp_offer(int sock){
547         dhcp_packet offer_packet;
548         struct sockaddr_in source;
549         struct sockaddr_in via;
550         int result=OK;
551         int responses=0;
552         int x;
553         time_t start_time;
554         time_t current_time;
556         time(&start_time);
558         /* receive as many responses as we can */
559         for(responses=0,valid_responses=0;;){
561                 time(&current_time);
562                 if((current_time-start_time)>=dhcpoffer_timeout)
563                         break;
565                 if(verbose) 
566                         printf("\n\n");
568                 bzero(&source,sizeof(source));
569                 bzero(&via,sizeof(via));
570                 bzero(&offer_packet,sizeof(offer_packet));
572                 result=OK;
573                 result=receive_dhcp_packet(&offer_packet,sizeof(offer_packet),sock,dhcpoffer_timeout,&source);
575                 if(result!=OK){
576                         if(verbose)
577                                 printf(_("Result=ERROR\n"));
579                         continue;
580                         }
581                 else{
582                         if(verbose) 
583                                 printf(_("Result=OK\n"));
585                         responses++;
586                         }
588                 /* The "source" is either a server or a relay. */
589                 /* Save a copy of "source" into "via" even if it's via itself */
590                 memcpy(&via,&source,sizeof(source)) ;
592                 /* If siaddr is non-zero, set "source" to siaddr */
593                 if(offer_packet.siaddr.s_addr != 0L){
594                         source.sin_addr.s_addr = offer_packet.siaddr.s_addr ;
595                         }
597                 if(verbose){
598                         printf(_("DHCPOFFER from IP address %s"),inet_ntoa(source.sin_addr));
599                         printf(_(" via %s\n"),inet_ntoa(via.sin_addr));
600                         printf("DHCPOFFER XID: %u (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid));
601                         }
603                 /* check packet xid to see if its the same as the one we used in the discover packet */
604                 if(ntohl(offer_packet.xid)!=packet_xid){
605                         if(verbose)
606                                 printf(_("DHCPOFFER XID (%u) did not match DHCPDISCOVER XID (%u) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid);
608                         continue;
609                         }
611                 /* check hardware address */
612                 result=OK;
613                 if(verbose)
614                         printf("DHCPOFFER chaddr: ");
616                 for(x=0;x<ETHERNET_HARDWARE_ADDRESS_LENGTH;x++){
617                         if(verbose)
618                                 printf("%02X",(unsigned char)offer_packet.chaddr[x]);
620                         if(offer_packet.chaddr[x]!=client_hardware_address[x])
621                                 result=ERROR;
622                         }
623                 if(verbose)
624                         printf("\n");
626                 if(result==ERROR){
627                         if(verbose) 
628                                 printf(_("DHCPOFFER hardware address did not match our own - ignoring packet\n"));
630                         continue;
631                         }
633                 if(verbose){
634                         printf("DHCPOFFER ciaddr: %s\n",inet_ntoa(offer_packet.ciaddr));
635                         printf("DHCPOFFER yiaddr: %s\n",inet_ntoa(offer_packet.yiaddr));
636                         printf("DHCPOFFER siaddr: %s\n",inet_ntoa(offer_packet.siaddr));
637                         printf("DHCPOFFER giaddr: %s\n",inet_ntoa(offer_packet.giaddr));
638                         }
640                 add_dhcp_offer(source.sin_addr,&offer_packet);
642                 valid_responses++;
643                 }
645         if(verbose){
646                 printf(_("Total responses seen on the wire: %d\n"),responses);
647                 printf(_("Valid responses for this machine: %d\n"),valid_responses);
648                 }
650         return OK;
651         }
655 /* sends a DHCP packet */
656 int send_dhcp_packet(void *buffer, int buffer_size, int sock, struct sockaddr_in *dest){
657         int result;
659         result=sendto(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)dest,sizeof(*dest));
661         if(verbose) 
662                 printf(_("send_dhcp_packet result: %d\n"),result);
664         if(result<0)
665                 return ERROR;
667         return OK;
668         }
672 /* receives a DHCP packet */
673 int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, struct sockaddr_in *address){
674         struct timeval tv;
675         fd_set readfds;
676         fd_set oobfds;
677         int recv_result;
678         socklen_t address_size;
679         struct sockaddr_in source_address;
680         int nfound;
683         /* wait for data to arrive (up time timeout) */
684         tv.tv_sec=timeout;
685         tv.tv_usec=0;
686         FD_ZERO(&readfds);
687         FD_ZERO(&oobfds);
688         FD_SET(sock,&readfds);
689         FD_SET(sock,&oobfds);
690         nfound = select(sock+1,&readfds,NULL,&oobfds,&tv);
692         /* make sure some data has arrived */
693         if(!FD_ISSET(sock,&readfds)){
694                 if(verbose)
695                         printf(_("No (more) data received (nfound: %d)\n"), nfound);
696                 return ERROR;
697                 }
699         else{
701                 /* why do we need to peek first?  i don't know, its a hack.  without it, the source address of the first packet received was
702                    not being interpreted correctly.  sigh... */
703                 bzero(&source_address,sizeof(source_address));
704                 address_size=sizeof(source_address);
705                 recv_result=recvfrom(sock,(char *)buffer,buffer_size,MSG_PEEK,(struct sockaddr *)&source_address,&address_size);
706                 if(verbose)
707                         printf("recv_result_1: %d\n",recv_result);
708                 recv_result=recvfrom(sock,(char *)buffer,buffer_size,0,(struct sockaddr *)&source_address,&address_size);
709                 if(verbose)
710                         printf("recv_result_2: %d\n",recv_result);
712                 if(recv_result==-1){
713                         if(verbose){
714                                 printf(_("recvfrom() failed, "));
715                                 printf("errno: (%d) -> %s\n",errno,strerror(errno));
716                                 }
717                         return ERROR;
718                         }
719                 else{
720                         if(verbose){
721                                 printf(_("receive_dhcp_packet() result: %d\n"),recv_result);
722                                 printf(_("receive_dhcp_packet() source: %s\n"),inet_ntoa(source_address.sin_addr));
723                                 }
725                         memcpy(address,&source_address,sizeof(source_address));
726                         return OK;
727                         }
728                 }
730         return OK;
731         }
734 /* creates a socket for DHCP communication */
735 int create_dhcp_socket(void){
736         struct sockaddr_in myname;
737         struct ifreq interface;
738         int sock;
739         int flag=1;
741         /* Set up the address we're going to bind to. */
742         bzero(&myname,sizeof(myname));
743         myname.sin_family=AF_INET;
744         /* listen to DHCP server port if we're in unicast mode */
745         myname.sin_port = htons(unicast ? DHCP_SERVER_PORT : DHCP_CLIENT_PORT);
746         myname.sin_addr.s_addr = unicast ? my_ip.s_addr : INADDR_ANY;
747         bzero(&myname.sin_zero,sizeof(myname.sin_zero));
749         /* create a socket for DHCP communications */
750         sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
751         if(sock<0){
752                 printf(_("Error: Could not create socket!\n"));
753                 exit(STATE_UNKNOWN);
754                 }
756         if(verbose)
757                 printf("DHCP socket: %d\n",sock);
759         /* set the reuse address flag so we don't get errors when restarting */
760         flag=1;
761         if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&flag,sizeof(flag))<0){
762                 printf(_("Error: Could not set reuse address option on DHCP socket!\n"));
763                 exit(STATE_UNKNOWN);
764                 }
766         /* set the broadcast option - we need this to listen to DHCP broadcast messages */
767         if(setsockopt(sock,SOL_SOCKET,SO_BROADCAST,(char *)&flag,sizeof flag)<0){
768                 printf(_("Error: Could not set broadcast option on DHCP socket!\n"));
769                 exit(STATE_UNKNOWN);
770                 }
772         /* bind socket to interface */
773 #if defined(__linux__)
774         strncpy(interface.ifr_ifrn.ifrn_name,network_interface_name,IFNAMSIZ-1);
775         interface.ifr_ifrn.ifrn_name[IFNAMSIZ-1]='\0';
776         if(setsockopt(sock,SOL_SOCKET,SO_BINDTODEVICE,(char *)&interface,sizeof(interface))<0){
777                 printf(_("Error: Could not bind socket to interface %s.  Check your privileges...\n"),network_interface_name);
778                 exit(STATE_UNKNOWN);
779                 }
781 #else
782         strncpy(interface.ifr_name,network_interface_name,IFNAMSIZ-1);
783         interface.ifr_name[IFNAMSIZ-1]='\0';
784 #endif
786         /* bind the socket */
787         if(bind(sock,(struct sockaddr *)&myname,sizeof(myname))<0){
788                 printf(_("Error: Could not bind to DHCP socket (port %d)!  Check your privileges...\n"),DHCP_CLIENT_PORT);
789                 exit(STATE_UNKNOWN);
790                 }
792         return sock;
793         }
796 /* closes DHCP socket */
797 int close_dhcp_socket(int sock){
799         close(sock);
801         return OK;
802         }
805 /* adds a requested server address to list in memory */
806 int add_requested_server(struct in_addr server_address){
807         requested_server *new_server;
809         new_server=(requested_server *)malloc(sizeof(requested_server));
810         if(new_server==NULL)
811                 return ERROR;
813         new_server->server_address=server_address;
814         new_server->answered=FALSE;
816         new_server->next=requested_server_list;
817         requested_server_list=new_server;
819         requested_servers++;
821         if(verbose)
822                 printf(_("Requested server address: %s\n"),inet_ntoa(new_server->server_address));
824         return OK;
825         }
830 /* adds a DHCP OFFER to list in memory */
831 int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){
832         dhcp_offer *new_offer;
833         int x;
834         unsigned option_type;
835         unsigned option_length;
836         struct in_addr serv_ident = {0};
838         if(offer_packet==NULL)
839                 return ERROR;
841         /* process all DHCP options present in the packet */
842         for(x=4;x<MAX_DHCP_OPTIONS_LENGTH;){
844                 /* end of options (0 is really just a pad, but bail out anyway) */
845                 if((int)offer_packet->options[x]==-1 || (int)offer_packet->options[x]==0)
846                         break;
848                 /* get option type */
849                 option_type=offer_packet->options[x++];
851                 /* get option length */
852                 option_length=offer_packet->options[x++];
854                 if(verbose) 
855                         printf("Option: %d (0x%02X)\n",option_type,option_length);
857                 /* get option data */
858                 switch(option_type){
859                 case DHCP_OPTION_LEASE_TIME:
860                         memcpy(&dhcp_lease_time, &offer_packet->options[x],sizeof(dhcp_lease_time));
861                         dhcp_lease_time = ntohl(dhcp_lease_time);
862                         break;
863                 case DHCP_OPTION_RENEWAL_TIME:
864                         memcpy(&dhcp_renewal_time, &offer_packet->options[x],sizeof(dhcp_renewal_time));
865                         dhcp_renewal_time = ntohl(dhcp_renewal_time);
866                         break;
867                 case DHCP_OPTION_REBINDING_TIME:
868                         memcpy(&dhcp_rebinding_time, &offer_packet->options[x],sizeof(dhcp_rebinding_time));
869                         dhcp_rebinding_time = ntohl(dhcp_rebinding_time);
870                         break;
871                 case DHCP_OPTION_SERVER_IDENTIFIER:
872                         memcpy(&serv_ident.s_addr, &offer_packet->options[x],sizeof(serv_ident.s_addr));
873                         break;
874                         }
876                 /* skip option data we're ignoring */
877                 if(option_type!=DHCP_OPTION_REBINDING_TIME)
878                         x+=option_length;
879                 }
881         if(verbose){
882                 if(dhcp_lease_time==DHCP_INFINITE_TIME)
883                         printf(_("Lease Time: Infinite\n"));
884                 else
885                         printf(_("Lease Time: %lu seconds\n"),(unsigned long)dhcp_lease_time);
886                 if(dhcp_renewal_time==DHCP_INFINITE_TIME)
887                         printf(_("Renewal Time: Infinite\n"));
888                 else
889                         printf(_("Renewal Time: %lu seconds\n"),(unsigned long)dhcp_renewal_time);
890                 if(dhcp_rebinding_time==DHCP_INFINITE_TIME)
891                         printf(_("Rebinding Time: Infinite\n"));
892                 printf(_("Rebinding Time: %lu seconds\n"),(unsigned long)dhcp_rebinding_time);
893                 }
895         new_offer=(dhcp_offer *)malloc(sizeof(dhcp_offer));
897         if(new_offer==NULL)
898                 return ERROR;
900         /*
901          * RFC 2131 (2.) says: "DHCP clarifies the interpretation of the
902          * 'siaddr' field as the address of the server to use in the next step
903          * of the client's bootstrap process.  A DHCP server may return its own
904          * address in the 'siaddr' field, if the server is prepared to supply
905          * the next bootstrap service (e.g., delivery of an operating system
906          * executable image).  A DHCP server always returns its own address in
907          * the 'server identifier' option."  'serv_ident' is the 'server
908          * identifier' option, 'source' is the 'siaddr' field or (if 'siaddr'
909          * wasn't available) the IP address we received the DHCPOFFER from.  If
910          * 'serv_ident' isn't available for some reason, we use 'source'.
911          */
912         new_offer->server_address=serv_ident.s_addr?serv_ident:source;
913         new_offer->offered_address=offer_packet->yiaddr;
914         new_offer->lease_time=dhcp_lease_time;
915         new_offer->renewal_time=dhcp_renewal_time;
916         new_offer->rebinding_time=dhcp_rebinding_time;
919         if(verbose){
920                 printf(_("Added offer from server @ %s"),inet_ntoa(new_offer->server_address));
921                 printf(_(" of IP address %s\n"),inet_ntoa(new_offer->offered_address));
922                 }
924         /* add new offer to head of list */
925         new_offer->next=dhcp_offer_list;
926         dhcp_offer_list=new_offer;
928         return OK;
929         }
932 /* frees memory allocated to DHCP OFFER list */
933 int free_dhcp_offer_list(void){
934         dhcp_offer *this_offer;
935         dhcp_offer *next_offer;
937         for(this_offer=dhcp_offer_list;this_offer!=NULL;this_offer=next_offer){
938                 next_offer=this_offer->next;
939                 free(this_offer);
940                 }
942         return OK;
943         }
946 /* frees memory allocated to requested server list */
947 int free_requested_server_list(void){
948         requested_server *this_server;
949         requested_server *next_server;
951         for(this_server=requested_server_list;this_server!=NULL;this_server=next_server){
952                 next_server=this_server->next;
953                 free(this_server);
954                 }
956         return OK;
957         }
960 /* gets state and plugin output to return */
961 int get_results(void){
962         dhcp_offer *temp_offer;
963         requested_server *temp_server;
964         int result;
965         u_int32_t max_lease_time=0;
967         received_requested_address=FALSE;
969         /* checks responses from requested servers */
970         requested_responses=0;
971         if(requested_servers>0){
973                 for(temp_server=requested_server_list;temp_server!=NULL;temp_server=temp_server->next){
975                         for(temp_offer=dhcp_offer_list;temp_offer!=NULL;temp_offer=temp_offer->next){
977                                 /* get max lease time we were offered */
978                                 if(temp_offer->lease_time>max_lease_time || temp_offer->lease_time==DHCP_INFINITE_TIME)
979                                         max_lease_time=temp_offer->lease_time;
981                                 /* see if we got the address we requested */
982                                 if(!memcmp(&requested_address,&temp_offer->offered_address,sizeof(requested_address)))
983                                         received_requested_address=TRUE;
985                                 /* see if the servers we wanted a response from talked to us or not */
986                                 if(!memcmp(&temp_offer->server_address,&temp_server->server_address,sizeof(temp_server->server_address))){
987                                         if(verbose){
988                                                 printf(_("DHCP Server Match: Offerer=%s"),inet_ntoa(temp_offer->server_address));
989                                                 printf(_(" Requested=%s"),inet_ntoa(temp_server->server_address));
990                                                 if(temp_server->answered) 
991                                                         printf(_(" (duplicate)"));
992                                                 printf(_("\n"));
993                                                 }
994                                         if(temp_server->answered == FALSE){
995                                                 requested_responses++;
996                                                 temp_server->answered=TRUE;
997                                                 }
998                                         }
999                                 }
1000                         }
1002                 }
1004         /* else check and see if we got our requested address from any server */
1005         else{
1007                 for(temp_offer=dhcp_offer_list;temp_offer!=NULL;temp_offer=temp_offer->next){
1009                         /* get max lease time we were offered */
1010                         if(temp_offer->lease_time>max_lease_time || temp_offer->lease_time==DHCP_INFINITE_TIME)
1011                                 max_lease_time=temp_offer->lease_time;
1013                         /* see if we got the address we requested */
1014                         if(!memcmp(&requested_address,&temp_offer->offered_address,sizeof(requested_address)))
1015                                 received_requested_address=TRUE;
1016                         }
1017                 }
1019         result=STATE_OK;
1020         if(valid_responses==0)
1021                 result=STATE_CRITICAL;
1022         else if(requested_servers>0 && requested_responses==0)
1023                 result=STATE_CRITICAL;
1024         else if(requested_responses<requested_servers)
1025                 result=STATE_WARNING;
1026         else if(request_specific_address==TRUE && received_requested_address==FALSE)
1027                 result=STATE_WARNING;
1029         if(result==0)               /* garrett honeycutt 2005 */
1030                 printf("OK: ");
1031         else if(result==1)
1032                 printf("WARNING: ");
1033         else if(result==2)
1034                 printf("CRITICAL: ");
1035         else if(result==3)
1036                 printf("UNKNOWN: ");
1038         /* we didn't receive any DHCPOFFERs */
1039         if(dhcp_offer_list==NULL){
1040                 printf(_("No DHCPOFFERs were received.\n"));
1041                 return result;
1042                 }
1044         printf(_("Received %d DHCPOFFER(s)"),valid_responses);
1046         if(requested_servers>0)
1047                 printf(_(", %s%d of %d requested servers responded"),((requested_responses<requested_servers) && requested_responses>0)?"only ":"",requested_responses,requested_servers);
1049         if(request_specific_address==TRUE)
1050                 printf(_(", requested address (%s) was %soffered"),inet_ntoa(requested_address),(received_requested_address==TRUE)?"":_("not "));
1052         printf(_(", max lease time = "));
1053         if(max_lease_time==DHCP_INFINITE_TIME)
1054                 printf(_("Infinity"));
1055         else
1056                 printf("%lu sec",(unsigned long)max_lease_time);
1058         printf(".\n");
1060         return result;
1061         }
1064 /* process command-line arguments */
1065 int process_arguments(int argc, char **argv){
1066         int c;
1068         if(argc<1)
1069                 return ERROR;
1071         c=0;
1072         while((c+=(call_getopt(argc-c,&argv[c])))<argc){
1074                 /*
1075                 if(is_option(argv[c]))
1076                         continue;
1077                 */
1078                 }
1080         return validate_arguments();
1081         }
1085 int call_getopt(int argc, char **argv){
1086         int c=0;
1087         int i=0;
1089         int option_index = 0;
1090         static struct option long_options[] =
1091         { 
1092                 {"serverip",       required_argument,0,'s'},
1093                 {"requestedip",    required_argument,0,'r'},
1094                 {"timeout",        required_argument,0,'t'},
1095                 {"interface",      required_argument,0,'i'},
1096                 {"mac",            required_argument,0,'m'},
1097                 {"unicast",        no_argument,      0,'u'},
1098                 {"verbose",        no_argument,      0,'v'},
1099                 {"version",        no_argument,      0,'V'},
1100                 {"help",           no_argument,      0,'h'},
1101                 {0,0,0,0}
1102         };
1104         while(1){
1105                 c=getopt_long(argc,argv,"+hVvt:s:r:t:i:m:u",long_options,&option_index);
1107                 i++;
1109                 if(c==-1||c==EOF||c==1)
1110                         break;
1112                 switch(c){
1113                 case 'w':
1114                 case 'r':
1115                 case 't':
1116                 case 'i':
1117                         i++;
1118                         break;
1119                 default:
1120                         break;
1121                         }
1123                 switch(c){
1125                 case 's': /* DHCP server address */
1126                         resolve_host(optarg,&dhcp_ip);
1127                         add_requested_server(dhcp_ip);
1128                         break;
1130                 case 'r': /* address we are requested from DHCP servers */
1131                         resolve_host(optarg,&requested_address);
1132                         request_specific_address=TRUE;
1133                         break;
1135                 case 't': /* timeout */
1137                         /*
1138                         if(is_intnonneg(optarg))
1139                         */
1140                         if(atoi(optarg)>0)
1141                                 dhcpoffer_timeout=atoi(optarg);
1142                         /*
1143                         else
1144                                 usage("Time interval must be a nonnegative integer\n");
1145                         */
1146                         break;
1148                 case 'm': /* MAC address */
1150                         if((user_specified_mac=mac_aton(optarg)) == NULL)
1151                                 usage("Cannot parse MAC address.\n");
1152                         if(verbose)
1153                                 print_hardware_address(user_specified_mac);
1155                         break;
1157                 case 'i': /* interface name */
1159                         strncpy(network_interface_name,optarg,sizeof(network_interface_name)-1);
1160                         network_interface_name[sizeof(network_interface_name)-1]='\x0';
1162                         break;
1164                 case 'u': /* unicast testing */
1165                         unicast=1;
1166                         break;
1168                 case 'V': /* version */
1169                         print_revision(progname,revision);
1170                         exit(STATE_OK);
1172                 case 'h': /* help */
1173                         print_help();
1174                         exit(STATE_OK);
1176                 case 'v': /* verbose */
1177                         verbose=1;
1178                         break;
1180                 case '?': /* help */
1181                         usage5 ();
1182                         break;
1184                 default:
1185                         break;
1186                         }
1187                 }
1189         return i;
1190         }
1193 int validate_arguments(void){
1195         return OK;
1196         }
1199 #if defined(__sun__) || defined(__solaris__) || defined(__hpux__)
1200 /* Kompf 2000-2003      see ACKNOWLEDGEMENTS */
1202 /* get a message from a stream; return type of message */
1203 static int get_msg(int fd){
1204         int flags = 0;
1205         int res, ret;
1206         ctl_area[0] = 0;
1207         dat_area[0] = 0;
1208         ret = 0;
1209         res = getmsg(fd, &ctl, &dat, &flags);
1211         if(res < 0){
1212                 if(errno == EINTR){
1213                         return(GOT_INTR);
1214                         }
1215                 else{
1216                         printf("%s\n", "get_msg FAILED.");
1217                         return(GOT_ERR);
1218                         }
1219                 }
1220         if(ctl.len > 0){
1221                 ret |= GOT_CTRL;
1222                 }
1223         if(dat.len > 0){
1224                 ret |= GOT_DATA;
1225                 }
1227         return(ret);
1228         }
1230 /* verify that dl_primitive in ctl_area = prim */
1231 static int check_ctrl(int prim){
1232         dl_error_ack_t *err_ack = (dl_error_ack_t *)ctl_area;
1234         if(err_ack->dl_primitive != prim){
1235                 printf(_("Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n"), strerror(errno));
1236                 exit(STATE_UNKNOWN);
1237                 }
1239         return 0;
1240         }
1242 /* put a control message on a stream */
1243 static int put_ctrl(int fd, int len, int pri){
1245         ctl.len = len;
1246         if(putmsg(fd, &ctl, 0, pri) < 0){
1247                 printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno));
1248                 exit(STATE_UNKNOWN);
1249                 }
1251         return  0;
1252         }
1254 /* put a control + data message on a stream */
1255 static int put_both(int fd, int clen, int dlen, int pri){
1257         ctl.len = clen;
1258         dat.len = dlen;
1259         if(putmsg(fd, &ctl, &dat, pri) < 0){
1260                 printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno));
1261                 exit(STATE_UNKNOWN);
1262                 }
1264         return  0;
1265         }
1267 /* open file descriptor and attach */
1268 static int dl_open(const char *dev, int unit, int *fd){
1269         dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area;
1271         if((*fd = open(dev, O_RDWR)) == -1){
1272                 printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno));
1273                 exit(STATE_UNKNOWN);
1274                 }
1275         attach_req->dl_primitive = DL_ATTACH_REQ;
1276         attach_req->dl_ppa = unit;
1277         put_ctrl(*fd, sizeof(dl_attach_req_t), 0);
1278         get_msg(*fd);
1279         return check_ctrl(DL_OK_ACK);
1280         }
1282 /* send DL_BIND_REQ */
1283 static int dl_bind(int fd, int sap, u_char *addr){
1284         dl_bind_req_t *bind_req = (dl_bind_req_t *)ctl_area;
1285         dl_bind_ack_t *bind_ack = (dl_bind_ack_t *)ctl_area;
1287         bind_req->dl_primitive = DL_BIND_REQ;
1288         bind_req->dl_sap = sap;
1289         bind_req->dl_max_conind = 1;
1290         bind_req->dl_service_mode = DL_CLDLS;
1291         bind_req->dl_conn_mgmt = 0;
1292         bind_req->dl_xidtest_flg = 0;
1293         put_ctrl(fd, sizeof(dl_bind_req_t), 0);
1294         get_msg(fd);
1295         if (GOT_ERR == check_ctrl(DL_BIND_ACK)){
1296                 printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno));
1297                 exit(STATE_UNKNOWN);
1298                 }
1299         bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr,
1300               bind_ack->dl_addr_length);
1302         return 0;
1303         }
1305 /***********************************************************************
1306  * interface:
1307  * function mac_addr_dlpi - get the mac address of the interface with 
1308  *                          type dev (eg lnc, hme) and unit (0, 1 ..)
1309  *
1310  * parameter: addr: an array of six bytes, has to be allocated by the caller
1311  *
1312  * return: 0 if OK, -1 if the address could not be determined
1313  *
1314  *
1315  ***********************************************************************/
1317 long mac_addr_dlpi( const char *dev, int unit, u_char  *addr){
1318         int fd;
1319         u_char mac_addr[25];
1321         if(GOT_ERR != dl_open(dev, unit, &fd)){
1322                 if(GOT_ERR != dl_bind(fd, INSAP, mac_addr)){
1323                         bcopy( mac_addr, addr, 6);
1324                         return 0;
1325                         }
1326                 }
1327         close(fd);
1329         return -1;
1330         }
1332 /* Kompf 2000-2003 */
1333 #endif
1336 /* resolve host name or die (TODO: move this to netutils.c!) */
1337 void resolve_host(const char *in,struct in_addr *out){
1338         struct addrinfo hints, *ai;
1340         memset(&hints,0,sizeof(hints));
1341         hints.ai_family=PF_INET;
1342         if (getaddrinfo(in,NULL,&hints,&ai) != 0)
1343                 usage_va(_("Invalid hostname/address - %s"),optarg);
1345         memcpy(out,&((struct sockaddr_in *)ai->ai_addr)->sin_addr,sizeof(*out));
1346         freeaddrinfo(ai);
1347         }
1350 /* parse MAC address string, return 6 bytes (unterminated) or NULL */
1351 unsigned char *mac_aton(const char *string){
1352         static unsigned char result[6];
1353         char tmp[3];
1354         unsigned i, j;
1356         for(i=0, j=0; string[i] != '\0' && j < sizeof(result); i++){
1357                 /* ignore ':' and any other non-hex character */
1358                 if(!isxdigit(string[i]) || !isxdigit(string[i+1]))
1359                         continue;
1360                 tmp[0]=string[i];
1361                 tmp[1]=string[i+1];
1362                 tmp[2]='\0';
1363                 result[j]=strtol(tmp,(char **)NULL,16);
1364                 i++;
1365                 j++;
1366                 }
1368         return (j==6) ? result : NULL;
1369         }
1372 void print_hardware_address(const unsigned char *address){
1373         int i;
1375         printf(_("Hardware address: "));
1376         for (i=0; i<5; i++)
1377                 printf("%2.2x:", address[i]);
1378         printf("%2.2x", address[i]);
1379         putchar('\n');
1380         }
1383 /* print usage help */
1384 void print_help(void){
1386         print_revision(progname,revision);
1388         printf("Copyright (c) 2001-2004 Ethan Galstad (nagios@nagios.org)\n");
1389         printf (COPYRIGHT, copyright, email);
1391         printf("%s\n", _("This plugin tests the availability of DHCP servers on a network."));
1393   printf ("\n\n");
1395         print_usage();
1397         printf (_(UT_HELP_VRSN));
1399         printf (_(UT_VERBOSE));
1401         printf (" %s\n", "-s, --serverip=IPADDRESS");
1402   printf ("    %s\n", _("IP address of DHCP server that we must hear from"));
1403   printf (" %s\n", "-r, --requestedip=IPADDRESS");
1404   printf ("    %s\n", _("IP address that should be offered by at least one DHCP server"));
1405   printf (" %s\n", "-t, --timeout=INTEGER");
1406   printf ("    %s\n", _("Seconds to wait for DHCPOFFER before timeout occurs"));
1407   printf (" %s\n", "-i, --interface=STRING");
1408   printf ("    %s\n", _("Interface to to use for listening (i.e. eth0)"));
1409   printf (" %s\n", "-m, --mac=STRING");
1410   printf ("    %s\n", _("MAC address to use in the DHCP request"));
1411   printf (" %s\n", "-u, --unicast");
1412   printf ("    %s\n", _("Unicast testing: mimic a DHCP relay, requires -s"));
1414   printf (_(UT_SUPPORT));
1415         return;
1416         }
1419 void
1420 print_usage(void){
1422   printf (_("Usage:"));
1423   printf (" %s [-v] [-u] [-s serverip] [-r requestedip] [-t timeout]\n",progname);
1424   printf ("                  [-i interface] [-m mac]\n");
1426         return;
1427         }