Code

Interface patch byor Clemens Resen
authorEthan Galstad <egalstad@users.sourceforge.net>
Sun, 16 Feb 2003 02:46:40 +0000 (02:46 +0000)
committerEthan Galstad <egalstad@users.sourceforge.net>
Sun, 16 Feb 2003 02:46:40 +0000 (02:46 +0000)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@326 f882894a-f735-0410-b71e-b25c423dba1c

contrib/check_dhcp.c

index 24b82f98edf1053c34690a2ae11715b68baea9db..2aea579dc1ff82548c29b443bf5e56c9fb0d53d9 100644 (file)
@@ -515,6 +515,7 @@ 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;
+       struct ifreq interface;
         int sock;
         int flag=1;
 
@@ -549,6 +550,13 @@ int create_dhcp_socket(void){
                exit(STATE_UNKNOWN);
                }
 
+       /* bind socket to interface */
+       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);
+               exit(STATE_UNKNOWN);
+               }
+
         /* 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);