Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 62d9a13aefeac3a3917f44cf9933c2e5 > files > 3

ocsinventory-fermi-0.9.9-26.src.rpm

--- ocsinventory-client.pl-24	2016-03-01 13:29:34.000000000 -0600
+++ ocsinventory-client.pl	2016-03-08 13:47:42.000000000 -0600
@@ -501,7 +501,7 @@
 
 sub _networks{
 	#Same way that dmidecode but with ifconfig
-	my ($line, @network, $dhcp, $gateway, $n, $flag, $lease, @values);
+	my ($line, @network, $dhcp, $gateway, $n, $flag_up, $flag_inet ,$lease, @values,$interface, $type , $macaddr);
 
 	# Looking for the default gateway
 	for(`$route_path`){
@@ -510,51 +510,44 @@
 
 	# Retrieving network settings
 	my $e ;
-	$flag = 0 ;
+	$flag_up = 0 ;
+	$flag_inet = 0 ;
 	#Switching from ifconfig to ip because more consistent between releases
 	for $line (@ip_addr){
 		#print "line: " . $line . "\n" ;
 		#Search for next entry ,  formated as d:
-		#Entry num is $n , reset flag
+		#Entry num is $e , reset flags
 		if ($line =~ /^(\d+):/ ) {
 		    $e = $1 ;
-		#    print "eeeee: " . $e . "\n" ;
-		    $flag = 0 ;
-		}
-		#Only care about some interfaces indicated by $flag
-		#if($line =~ /^([eai](m|b|th)\S+)/i){
-		#Added np2s for minnowboard
-		if($line =~ /([eai](m|b|th|np2s)(\d+)):/i){
-			defined($n)?($n++):($n = 0);
-			$request{'CONTENT'}{'NETWORKS'}[$n]{'DESCRIPTION'} = [ $1 ];
-			push @values, $1;
-		# 	print "interface: " . $1 . "\n";
-			#Care about this interface
-			$flag = 1;
-		        if($line =~ /\s*,UP,/i ){ 
-			    $request{'CONTENT'}{'NETWORKS'}[$n]{'STATUS'}= [ 'Up' ];
+		    #print "eeeee: " . $e . "\n" ;
+		    $flag_up = 0 ;
+		    $flag_inet = 0 ;
+		}
+		#Only care about some interfaces indicated by $flag_up and $flag_inet
+		if($line =~ /^(\d+): (\S+): /i){
+		        $interface = $2 ;
+			#Should we care about this interface
+		        if($line =~ /\s*,UP[,>]/  ){
+			    #Skip loopback
+			    if ( $interface !~ 'lo' ){ 
+			       defined($n)?($n++):($n = 0);
+                               #Means we found a Up, not 'lo' still need a inet or inet6
+			       $flag_up = 1;
+		               #print "interface: " . $interface . "\n";
+			    }
 		        }
 		}
 
-		if( ! $flag ) {
+		if( ! $flag_up ) {
 		   #We can skip lines until we hit the next "entry" head line
 		   next ;
 		}
-		#print "flag: " . $flag . "\n" ;
-		if (!$request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} ){ 
-		     $request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} = [ $gateway ]; 
-		#	print "gateway: " . $gateway . "\n";
-		        push @values, $gateway;
-		};
 		if($line =~ /link\/(ether) (\S+)/i ){ 
-			$request{'CONTENT'}{'NETWORKS'}[$n]{'TYPE'}= [ 'Ethernet'];
-			push @values, [ 'Ethernet'];
-		#	print "type: " . "Ethernet" . "\n";
-
-		        $request{'CONTENT'}{'NETWORKS'}[$n]{'MACADDR'}= [ $2 ];
-			push @values, $2;			
-		#	print "mac: " . $2 . "\n";
-		};
+		   $type = 'Ethernet';
+		   #print "type: " . $type . "\n";
+		   $macaddr = $2;			
+		   #print "mac: " . $macaddr . "\n";
+                };
 		if($line =~ /inet6 (\S+)/i ){ 
 		    my $ipv6 = $1 ;
 		    if($line =~ /scope global/ ){ 
@@ -563,13 +556,13 @@
 
 	 		push @values, $ipv6;
 		# 	print "ipv6: " . $ipv6 . "\n";
+		  	$flag_inet = 1 ;
 		    }
 		};
 		if($line =~ /inet (\S+)/i ){ 
 			#ip addr does not show netmask so convert cidr 
     			my($network, $netbit) = split m'/', $1; 
     		#	print "netbit: " . $netbit  . "\n";
-
     			# Decimal representation of mask
     			my $mask  = (2 ** $netbit - 1) << (32 - $netbit); 
     			# convert decimal representation to our familiar form
@@ -577,14 +570,32 @@
 			$request{'CONTENT'}{'NETWORKS'}[$n]{'IPMASK'}= [ $netmask ];
 			push @values, $netmask;
 		#	print "ipmask: " . $netmask . "\n";
-
 			#ip addr returns ipaddress/netmask so have to remove /net
 			$1 =~ /^(.*)\// ;
 			$request{'CONTENT'}{'NETWORKS'}[$n]{'IPADDRESS'}= [ $1 ];
 			push @values, $1;
-		#	print "inet: " . $1 . "\n";
+		 	#print "inet: " . $1 . "\n";
+
+		  	$flag_inet = 1 ;
+
+		        if ( $1 !~ /^192/ ) {
+		            $request{'CONTENT'}{'NETWORKS'}[$n]{'IPGATEWAY'} = [ $gateway ]; 
+		            push @values, $gateway;
+		            #print "gateway: " . $gateway . "\n";
+		        }
 		};
+	        #Only save if we find a inet or inet6 line
+		if ( $flag_inet ) {
+		   $request{'CONTENT'}{'NETWORKS'}[$n]{'TYPE'}= [ $type ];
+		   push @values, [ $type ];
+	           $request{'CONTENT'}{'NETWORKS'}[$n]{'DESCRIPTION'} = [ $interface ];
+	           push @values, $interface;
+		   $request{'CONTENT'}{'NETWORKS'}[$n]{'STATUS'}= [ 'Up' ];
+		   push @values, ['Up'];
+		   $request{'CONTENT'}{'NETWORKS'}[$n]{'MACADDR'}= [ $macaddr ];
+		   push @values, $macaddr;			
 
+		};
 	}
 	#Checksum
 	&_has_changed('networks', md5_base64(@values));