X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fcheck_dhcp.c;h=a3e0c53c58198aa60d19a628d7b5d63e9c5adcf8;hb=d4c0948266f261525e12c58d58e0fc68987a9818;hp=ee893cd24965d8b355ae503f860b8d6c690f4e45;hpb=d50a9917ef38c44ac2067dba508cf2e690ff1412;p=nagiosplug.git diff --git a/plugins/check_dhcp.c b/plugins/check_dhcp.c index ee893cd..a3e0c53 100644 --- a/plugins/check_dhcp.c +++ b/plugins/check_dhcp.c @@ -22,8 +22,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * +* $Id$ +* *****************************************************************************/ +const char *progname = "check_dhcp"; +const char *revision = "$Revision$"; +const char *copyright = "2001-2004"; +const char *email = "nagiosplug-devel@lists.sourceforge.net"; + #include "common.h" #include "netutils.h" #include "utils.h" @@ -45,17 +52,55 @@ #include #if defined( __linux__ ) + #include #include -#else + +#elif defined (__bsd__) + #include #include #include -#endif -const char *progname = "check_dhcp"; +#elif defined(__sun__) || defined(__solaris__) || defined(__hpux__) + +#define INSAP 22 +#define OUTSAP 24 + +#include +#include +#include +#include +#include + +#define bcopy(source, destination, length) memcpy(destination, source, length) + +#define AREA_SZ 5000 /* buffer length in bytes */ +static u_long ctl_area[AREA_SZ]; +static u_long dat_area[AREA_SZ]; +static struct strbuf ctl = {AREA_SZ, 0, (char *)ctl_area}; +static struct strbuf dat = {AREA_SZ, 0, (char *)dat_area}; + +#define GOT_CTRL 1 +#define GOT_DATA 2 +#define GOT_BOTH 3 +#define GOT_INTR 4 +#define GOT_ERR 128 + +#define u_int8_t uint8_t +#define u_int16_t uint16_t +#define u_int32_t uint32_t + +static int get_msg(int); +static int check_ctrl(int); +static int put_ctrl(int, int, int); +static int put_both(int, int, int, int); +static int dl_open(const char *, int, int *); +static int dl_bind(int, int, u_char *); +long mac_addr_dlpi( const char *, int, u_char *); + +#endif -/*#define DEBUG*/ #define HAVE_GETOPT_H @@ -166,6 +211,7 @@ int requested_responses=0; int request_specific_address=FALSE; int received_requested_address=FALSE; +int verbose=0; struct in_addr requested_address; @@ -197,12 +243,13 @@ int main(int argc, char **argv){ int dhcp_socket; int result; + setlocale (LC_ALL, ""); + bindtextdomain (PACKAGE, LOCALEDIR); + textdomain (PACKAGE); + if(process_arguments(argc,argv)!=OK){ - /*usage("Invalid command arguments supplied\n");*/ - printf("Invalid command arguments supplied\n"); - exit(STATE_UNKNOWN); - } - + usage4 (_("Could not parse arguments")); + } /* create socket for DHCP communications */ dhcp_socket=create_dhcp_socket(); @@ -233,6 +280,9 @@ int main(int argc, char **argv){ /* determines hardware address on client machine */ int get_hardware_address(int sock,char *interface_name){ + + int i; + #if defined(__linux__) struct ifreq ifr; @@ -240,15 +290,14 @@ int get_hardware_address(int sock,char *interface_name){ /* try and grab hardware address of requested interface */ if(ioctl(sock,SIOCGIFHWADDR,&ifr)<0){ - printf("Error: Could not get hardware address of interface '%s'\n",interface_name); + printf(_("Error: Could not get hardware address of interface '%s'\n"),interface_name); exit(STATE_UNKNOWN); } memcpy(&client_hardware_address[0],&ifr.ifr_hwaddr.sa_data,6); -#else - /* Code from getmac.c posted at http://lists.freebsd.org/pipermail/freebsd-hackers/2004-June/007415.html - * by Alecs King based on Unix Network programming Ch 17 - */ + +#elif defined(__bsd__) + /* King 2004 see ACKNOWLEDGEMENTS */ int mib[6], len; char *buf; @@ -263,39 +312,80 @@ int get_hardware_address(int sock,char *interface_name){ mib[4] = NET_RT_IFLIST; if ((mib[5] = if_nametoindex(interface_name)) == 0) { - perror("if_nametoindex error"); - exit(2); + printf(_("Error: if_nametoindex error - %s.\n"), strerror(errno)); + exit(STATE_UNKNOWN); } if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) { - perror("sysctl 1 error"); - exit(3); + printf(_("Error: Couldn't get hardware address from %s. sysctl 1 error - %s.\n"), interface_name, strerror(errno)); + exit(STATE_UNKNOWN); } if ((buf = malloc(len)) == NULL) { - perror("malloc error"); + printf(_("Error: Couldn't get hardware address from interface %s. malloc error - %s.\n"), interface_name, strerror(errno)); exit(4); } if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) { - perror("sysctl 2 error"); - exit(5); + printf(_("Error: Couldn't get hardware address from %s. sysctl 2 error - %s.\n"), interface_name, strerror(errno)); + exit(STATE_UNKNOWN); } ifm = (struct if_msghdr *)buf; sdl = (struct sockaddr_dl *)(ifm + 1); ptr = (unsigned char *)LLADDR(sdl); memcpy(&client_hardware_address[0], ptr, 6) ; -#endif + /* King 2004 */ + +#elif defined(__sun__) || defined(__solaris__) + + /* Kompf 2000-2003 see ACKNOWLEDGEMENTS */ + long stat; + char dev[20] = "/dev/"; + char *p; + int unit; + + for (p = interface_name; *p && isalpha(*p); p++) + /* no-op */ ; + if ( p != '\0' ) { + unit = atoi(p) ; + *p = '\0' ; + strncat(dev, interface_name, 6) ; + } else { + printf(_("Error: can't find unit number in interface_name (%s) - expecting TypeNumber eg lnc0.\n"), interface_name); + exit(STATE_UNKNOWN); + } + stat = mac_addr_dlpi(dev, unit, client_hardware_address); + if (stat != 0) { + printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit); + exit(STATE_UNKNOWN); + } + +#elif defined(__hpux__) + long stat; + char dev[20] = "/dev/dlpi" ; + int unit = 0; -#ifdef DEBUG - printf("Hardware address: %02x:%02x:%02x:",client_hardware_address[0],client_hardware_address[1],client_hardware_address[2]); - printf("%02x:",client_hardware_address[3]); - printf("%02x:%02x\n",client_hardware_address[4],client_hardware_address[5]); - printf("\n"); + stat = mac_addr_dlpi(dev, unit, client_hardware_address); + if (stat != 0) { + printf(_("Error: can't read MAC address from DLPI streams interface for device %s unit %d.\n"), dev, unit); + exit(STATE_UNKNOWN); + } + /* Kompf 2000-2003 */ + +#else + printf(_("Error: can't get MAC address for this architecture.\n")); + exit(STATE_UNKNOWN); #endif + if (verbose) { + printf(_("Hardware address: ")); + for (i=0; i<6; ++i) + printf("%2.2x", client_hardware_address[i]); + printf( "\n"); + } + return OK; } @@ -364,21 +454,20 @@ int send_dhcp_discover(int sock){ bzero(&sockaddr_broadcast.sin_zero,sizeof(sockaddr_broadcast.sin_zero)); -#ifdef DEBUG - 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("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)); - printf("DHCDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); -#endif + 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("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)); + printf("DHCDISCOVER giaddr: %s\n",inet_ntoa(discover_packet.giaddr)); + } /* send the DHCPDISCOVER packet out */ send_dhcp_packet(&discover_packet,sizeof(discover_packet),sock,&sockaddr_broadcast); -#ifdef DEBUG - printf("\n\n"); -#endif + if (verbose) + printf("\n\n"); return OK; } @@ -406,9 +495,8 @@ int get_dhcp_offer(int sock){ if((current_time-start_time)>=dhcpoffer_timeout) break; -#ifdef DEBUG - printf("\n\n"); -#endif + if (verbose) + printf("\n\n"); bzero(&source,sizeof(source)); bzero(&offer_packet,sizeof(offer_packet)); @@ -417,70 +505,69 @@ int get_dhcp_offer(int sock){ result=receive_dhcp_packet(&offer_packet,sizeof(offer_packet),sock,dhcpoffer_timeout,&source); if(result!=OK){ -#ifdef DEBUG - printf("Result=ERROR\n"); -#endif + if (verbose) + printf(_("Result=ERROR\n")); + continue; } else{ -#ifdef DEBUG - printf("Result=OK\n"); -#endif + if (verbose) + printf(_("Result=OK\n")); + responses++; } -#ifdef DEBUG - printf("DHCPOFFER from IP address %s\n",inet_ntoa(source.sin_addr)); - printf("DHCPOFFER XID: %lu (0x%X)\n",ntohl(offer_packet.xid),ntohl(offer_packet.xid)); -#endif + if (verbose) { + printf(_("DHCPOFFER from IP address %s\n"),inet_ntoa(source.sin_addr)); + printf("DHCPOFFER XID: %lu (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){ -#ifdef DEBUG - printf("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n",ntohl(offer_packet.xid),packet_xid); -#endif + if (verbose) + printf(_("DHCPOFFER XID (%lu) did not match DHCPDISCOVER XID (%lu) - ignoring packet\n"),ntohl(offer_packet.xid),packet_xid); + continue; } /* check hardware address */ result=OK; -#ifdef DEBUG - printf("DHCPOFFER chaddr: "); -#endif + if (verbose) + printf("DHCPOFFER chaddr: "); + for(x=0;x %s\n",errno,strerror(errno)); -#endif + if (verbose) { + printf(_("recvfrom() failed, ")); + printf("errno: (%d) -> %s\n",errno,strerror(errno)); + } return ERROR; } else{ -#ifdef DEBUG - printf("receive_dhcp_packet() result: %d\n",recv_result); - printf("receive_dhcp_packet() source: %s\n",inet_ntoa(source_address.sin_addr)); -#endif + if (verbose) { + printf(_("receive_dhcp_packet() result: %d\n"),recv_result); + printf(_("receive_dhcp_packet() source: %s\n"),inet_ntoa(source_address.sin_addr)); + } memcpy(address,&source_address,sizeof(source_address)); return OK; @@ -567,7 +650,6 @@ int receive_dhcp_packet(void *buffer, int buffer_size, int sock, int timeout, st } - /* creates a socket for DHCP communication */ int create_dhcp_socket(void){ struct sockaddr_in myname; @@ -585,24 +667,23 @@ int create_dhcp_socket(void){ /* create a socket for DHCP communications */ sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); if(sock<0){ - printf("Error: Could not create socket!\n"); + printf(_("Error: Could not create socket!\n")); exit(STATE_UNKNOWN); } -#ifdef DEBUG - printf("DHCP socket: %d\n",sock); -#endif + if (verbose) + printf("DHCP socket: %d\n",sock); /* set the reuse address flag so we don't get errors when restarting */ flag=1; if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char *)&flag,sizeof(flag))<0){ - printf("Error: Could not set reuse address option on DHCP socket!\n"); + printf(_("Error: Could not set reuse address option on DHCP socket!\n")); exit(STATE_UNKNOWN); } /* set the broadcast option - we need this to listen to DHCP broadcast messages */ if(setsockopt(sock,SOL_SOCKET,SO_BROADCAST,(char *)&flag,sizeof flag)<0){ - printf("Error: Could not set broadcast option on DHCP socket!\n"); + printf(_("Error: Could not set broadcast option on DHCP socket!\n")); exit(STATE_UNKNOWN); } @@ -610,7 +691,7 @@ int create_dhcp_socket(void){ #if defined(__linux__) strncpy(interface.ifr_ifrn.ifrn_name,network_interface_name,IFNAMSIZ); if(setsockopt(sock,SOL_SOCKET,SO_BINDTODEVICE,(char *)&interface,sizeof(interface))<0){ - printf("Error: Could not bind socket to interface %s. Check your privileges...\n",network_interface_name); + printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"),network_interface_name); exit(STATE_UNKNOWN); } @@ -620,7 +701,7 @@ int create_dhcp_socket(void){ /* bind the socket */ if(bind(sock,(struct sockaddr *)&myname,sizeof(myname))<0){ - printf("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n",DHCP_CLIENT_PORT); + printf(_("Error: Could not bind to DHCP socket (port %d)! Check your privileges...\n"),DHCP_CLIENT_PORT); exit(STATE_UNKNOWN); } @@ -628,9 +709,6 @@ int create_dhcp_socket(void){ } - - - /* closes DHCP socket */ int close_dhcp_socket(int sock){ @@ -640,8 +718,6 @@ int close_dhcp_socket(int sock){ } - - /* adds a requested server address to list in memory */ int add_requested_server(struct in_addr server_address){ requested_server *new_server; @@ -657,9 +733,8 @@ int add_requested_server(struct in_addr server_address){ requested_servers++; -#ifdef DEBUG - printf("Requested server address: %s\n",inet_ntoa(new_server->server_address)); -#endif + if (verbose) + printf(_("Requested server address: %s\n"),inet_ntoa(new_server->server_address)); return OK; } @@ -691,43 +766,50 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){ /* get option length */ option_length=offer_packet->options[x++]; -#ifdef DEBUG - printf("Option: %d (0x%02X)\n",option_type,option_length); -#endif + if (verbose) + printf("Option: %d (0x%02X)\n",option_type,option_length); /* get option data */ - if(option_type==DHCP_OPTION_LEASE_TIME) - dhcp_lease_time=ntohl(*((u_int32_t *)&offer_packet->options[x])); - if(option_type==DHCP_OPTION_RENEWAL_TIME) - dhcp_renewal_time=ntohl(*((u_int32_t *)&offer_packet->options[x])); - if(option_type==DHCP_OPTION_REBINDING_TIME) - dhcp_rebinding_time=ntohl(*((u_int32_t *)&offer_packet->options[x])); + if(option_type==DHCP_OPTION_LEASE_TIME) { + memcpy(&dhcp_lease_time, &offer_packet->options[x], + sizeof(dhcp_lease_time)); + dhcp_lease_time = ntohl(dhcp_lease_time); + } + if(option_type==DHCP_OPTION_RENEWAL_TIME) { + memcpy(&dhcp_renewal_time, &offer_packet->options[x], + sizeof(dhcp_renewal_time)); + dhcp_renewal_time = ntohl(dhcp_renewal_time); + } + if(option_type==DHCP_OPTION_REBINDING_TIME) { + memcpy(&dhcp_rebinding_time, &offer_packet->options[x], + sizeof(dhcp_rebinding_time)); + dhcp_rebinding_time = ntohl(dhcp_rebinding_time); + } /* skip option data we're ignoring */ else for(y=0;yserver_address=source; new_offer->offered_address=offer_packet->yiaddr; new_offer->lease_time=dhcp_lease_time; @@ -735,10 +817,10 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){ new_offer->rebinding_time=dhcp_rebinding_time; -#ifdef DEBUG - printf("Added offer from server @ %s",inet_ntoa(new_offer->server_address)); - printf(" of IP address %s\n",inet_ntoa(new_offer->offered_address)); -#endif + if (verbose) { + printf(_("Added offer from server @ %s"),inet_ntoa(new_offer->server_address)); + printf(_(" of IP address %s\n"),inet_ntoa(new_offer->offered_address)); + } /* add new offer to head of list */ new_offer->next=dhcp_offer_list; @@ -748,8 +830,6 @@ int add_dhcp_offer(struct in_addr source,dhcp_packet *offer_packet){ } - - /* frees memory allocated to DHCP OFFER list */ int free_dhcp_offer_list(void){ dhcp_offer *this_offer; @@ -764,8 +844,6 @@ int free_dhcp_offer_list(void){ } - - /* frees memory allocated to requested server list */ int free_requested_server_list(void){ requested_server *this_server; @@ -807,10 +885,10 @@ int get_results(void){ /* see if the servers we wanted a response from talked to us or not */ if(!memcmp(&temp_offer->server_address,&temp_server->server_address,sizeof(temp_server->server_address))){ -#ifdef DEBUG - printf("DHCP Server Match: Offerer=%s",inet_ntoa(temp_offer->server_address)); - printf(" Requested=%s\n",inet_ntoa(temp_server->server_address)); -#endif + if (verbose) { + printf(_("DHCP Server Match: Offerer=%s"),inet_ntoa(temp_offer->server_address)); + printf(_(" Requested=%s\n"),inet_ntoa(temp_server->server_address)); + } requested_responses++; } } @@ -848,21 +926,21 @@ int get_results(void){ /* we didn't receive any DHCPOFFERs */ if(dhcp_offer_list==NULL){ - printf("No DHCPOFFERs were received.\n"); + printf(_("No DHCPOFFERs were received.\n")); return result; } - printf("Received %d DHCPOFFER(s)",valid_responses); + printf(_("Received %d DHCPOFFER(s)"),valid_responses); if(requested_servers>0) - printf(", %s%d of %d requested servers responded",((requested_responses0)?"only ":"",requested_responses,requested_servers); + printf(_(", %s%d of %d requested servers responded"),((requested_responses0)?"only ":"",requested_responses,requested_servers); if(request_specific_address==TRUE) - printf(", requested address (%s) was %soffered",inet_ntoa(requested_address),(received_requested_address==TRUE)?"":"not "); + printf(_(", requested address (%s) was %soffered"),inet_ntoa(requested_address),(received_requested_address==TRUE)?"":_("not ")); - printf(", max lease time = "); + printf(_(", max lease time = ")); if(max_lease_time==DHCP_INFINITE_TIME) - printf("Infinity"); + printf(_("Infinity")); else printf("%lu sec",(unsigned long)max_lease_time); @@ -872,57 +950,6 @@ int get_results(void){ } - - - - -/* print usage help */ -void print_help(void){ - - /*print_revision(progname,"$Revision$");*/ - - printf("Copyright (c) 2001-2004 Ethan Galstad (nagios@nagios.org)\n\n"); - printf("This plugin tests the availability of DHCP servers on a network.\n\n"); - - print_usage(); - - printf - ("\nOptions:\n" - " -s, --serverip=IPADDRESS\n" - " IP address of DHCP server that we must hear from\n" - " -r, --requestedip=IPADDRESS\n" - " IP address that should be offered by at least one DHCP server\n" - " -t, --timeout=INTEGER\n" - " Seconds to wait for DHCPOFFER before timeout occurs\n" - " -i, --interface=STRING\n" - " Interface to to use for listening (i.e. eth0)\n" - " -v, --verbose\n" - " Print extra information (command-line use only)\n" - " -h, --help\n" - " Print detailed help screen\n" - " -V, --version\n" - " Print version information\n\n" - ); - - /*support();*/ - - return; - } - - -/* prints usage information */ -void print_usage(void){ - - printf("Usage: %s [-s serverip] [-r requestedip] [-t timeout] [-i interface]\n",progname); - printf(" %s --help\n",progname); - printf(" %s --version\n",progname); - - return; - } - - - - /* process command-line arguments */ int process_arguments(int argc, char **argv){ int c; @@ -1030,18 +1057,19 @@ int call_getopt(int argc, char **argv){ break; case 'V': /* version */ - - /*print_revision(progname,"$Revision$");*/ + print_revision(progname,revision); exit(STATE_OK); case 'h': /* help */ - print_help(); exit(STATE_OK); - case '?': /* help */ + case 'v': /* verbose */ + verbose=1; + break; - /*usage("Invalid argument\n");*/ + case '?': /* help */ + usage2 (_("Unknown argument"), optarg); break; default: @@ -1053,9 +1081,181 @@ int call_getopt(int argc, char **argv){ } - int validate_arguments(void){ return OK; } +#if defined(__sun__) || defined(__solaris__) || defined(__hpux__) + + /* Kompf 2000-2003 see ACKNOWLEDGEMENTS */ + +/* get a message from a stream; return type of message */ +static int get_msg(int fd) +{ + int flags = 0; + int res, ret; + ctl_area[0] = 0; + dat_area[0] = 0; + ret = 0; + res = getmsg(fd, &ctl, &dat, &flags); + + if(res < 0) { + if(errno == EINTR) { + return(GOT_INTR); + } else { + printf("%s\n", "get_msg FAILED."); + return(GOT_ERR); + } + } + if(ctl.len > 0) { + ret |= GOT_CTRL; + } + if(dat.len > 0) { + ret |= GOT_DATA; + } + return(ret); +} + +/* verify that dl_primitive in ctl_area = prim */ +static int check_ctrl(int prim) +{ + dl_error_ack_t *err_ack = (dl_error_ack_t *)ctl_area; + if(err_ack->dl_primitive != prim) { + printf(_("Error: DLPI stream API failed to get MAC in check_ctrl: %s.\n"), strerror(errno)); + exit(STATE_UNKNOWN); + } + return 0; +} + +/* put a control message on a stream */ +static int put_ctrl(int fd, int len, int pri) +{ + ctl.len = len; + if(putmsg(fd, &ctl, 0, pri) < 0) { + printf(_("Error: DLPI stream API failed to get MAC in put_ctrl/putmsg(): %s.\n"), strerror(errno)); + exit(STATE_UNKNOWN); + } + return 0; +} + +/* put a control + data message on a stream */ +static int put_both(int fd, int clen, int dlen, int pri) +{ + ctl.len = clen; + dat.len = dlen; + if(putmsg(fd, &ctl, &dat, pri) < 0) { + printf(_("Error: DLPI stream API failed to get MAC in put_both/putmsg().\n"), strerror(errno)); + exit(STATE_UNKNOWN); + } + return 0; +} + +/* open file descriptor and attach */ +static int dl_open(const char *dev, int unit, int *fd) +{ + dl_attach_req_t *attach_req = (dl_attach_req_t *)ctl_area; + if((*fd = open(dev, O_RDWR)) == -1) { + printf(_("Error: DLPI stream API failed to get MAC in dl_attach_req/open(%s..): %s.\n"), dev, strerror(errno)); + exit(STATE_UNKNOWN); + } + attach_req->dl_primitive = DL_ATTACH_REQ; + attach_req->dl_ppa = unit; + put_ctrl(*fd, sizeof(dl_attach_req_t), 0); + get_msg(*fd); + return check_ctrl(DL_OK_ACK); +} + +/* send DL_BIND_REQ */ +static int dl_bind(int fd, int sap, u_char *addr) +{ + dl_bind_req_t *bind_req = (dl_bind_req_t *)ctl_area; + dl_bind_ack_t *bind_ack = (dl_bind_ack_t *)ctl_area; + bind_req->dl_primitive = DL_BIND_REQ; + bind_req->dl_sap = sap; + bind_req->dl_max_conind = 1; + bind_req->dl_service_mode = DL_CLDLS; + bind_req->dl_conn_mgmt = 0; + bind_req->dl_xidtest_flg = 0; + put_ctrl(fd, sizeof(dl_bind_req_t), 0); + get_msg(fd); + if (GOT_ERR == check_ctrl(DL_BIND_ACK)) { + printf(_("Error: DLPI stream API failed to get MAC in dl_bind/check_ctrl(): %s.\n"), strerror(errno)); + exit(STATE_UNKNOWN); + } + bcopy((u_char *)bind_ack + bind_ack->dl_addr_offset, addr, + bind_ack->dl_addr_length); + return 0; +} + +/*********************************************************************** + * interface: + * function mac_addr_dlpi - get the mac address of the interface with + * type dev (eg lnc, hme) and unit (0, 1 ..) + * + * parameter: addr: an array of six bytes, has to be allocated by the caller + * + * return: 0 if OK, -1 if the address could not be determined + * + * + ***********************************************************************/ + +long mac_addr_dlpi( const char *dev, int unit, u_char *addr) { + + int fd; + u_char mac_addr[25]; + + if (GOT_ERR != dl_open(dev, unit, &fd)) { + if (GOT_ERR != dl_bind(fd, INSAP, mac_addr)) { + bcopy( mac_addr, addr, 6); + return 0; + } + } + close(fd); + return -1; +} + + /* Kompf 2000-2003 */ + +#endif + + +/* print usage help */ +void print_help(void){ + + print_revision(progname,revision); + + printf("Copyright (c) 2001-2004 Ethan Galstad (nagios@nagios.org)\n\n"); + printf (COPYRIGHT, copyright, email); + + printf(_("This plugin tests the availability of DHCP servers on a network.\n\n")); + + print_usage(); + + printf(_("\ + -s, --serverip=IPADDRESS\n\ + IP address of DHCP server that we must hear from\n\ + -r, --requestedip=IPADDRESS\n\ + IP address that should be offered by at least one DHCP server\n\ + -t, --timeout=INTEGER\n\ + Seconds to wait for DHCPOFFER before timeout occurs\n\ + -i, --interface=STRING\n\ + Interface to to use for listening (i.e. eth0)\n\ + -v, --verbose\n\ + Print extra information (command-line use only)\n\ + -h, --help\n\ + Print detailed help screen\n\ + -V, --version\n\ + Print version information\n")); +} + + +void print_usage(void) +{ + printf("\ +Usage: %s [-s serverip] [-r requestedip] [-t timeout] [-i interface]\n\ + [-v]",progname); +} + + +