Prechádzať zdrojové kódy

check_dhcp: fix mac address and interface number detection on solaris

newer (or x86) solaris implementations have interface names like e1000g0
which includes numbers. So we reverse the interface number detection to
get the last number, instead of the first number.
Sven Nierlein 12 rokov pred
rodič
commit
6e9d16809e
1 zmenil súbory, kde vykonal 9 pridanie a 4 odobranie
  1. 9 4
      plugins-root/check_dhcp.c

+ 9 - 4
plugins-root/check_dhcp.c

@@ -372,11 +372,16 @@ int get_hardware_address(int sock,char *interface_name){
 	char *p;
 	char *p;
 	int unit;
 	int unit;
 
 
-	for(p = interface_name; *p && isalpha(*p); p++)
-		/* no-op */ ;
-	if( p != '\0' ){
+    /* get last number from interfacename, eg lnc0, e1000g0*/
+    int i;
+    p = interface_name + strlen(interface_name) -1;
+	for(i = strlen(interface_name) -1; i > 0; p--) {
+		if(isalpha(*p))
+            break;
+    }
+    p++;
+	if( p != interface_name ){
 		unit = atoi(p) ;
 		unit = atoi(p) ;
-		*p = '\0' ;
 		strncat(dev, interface_name, 6) ;
 		strncat(dev, interface_name, 6) ;
 		}
 		}
 	else{
 	else{