- Timestamp:
- Feb 17, 2016, 1:37:44 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/MondoRescue/bin/mr-net-get-config
r3278 r3512 131 131 my ($scheme, $account, $host, $port, $path) = pb_get_uri($url); 132 132 133 # If ho t is a name transform into an IP133 # If host is a name transform into an IP 134 134 my $hostip = inet_ntoa(scalar gethostbyname($host || 'localhost')); 135 136 my $found = 0; 135 137 136 138 # We need to loop on all if to see which one is on the same LAN as the server … … 138 140 # Skip fake interfaces 139 141 next if (not defined $if->address); 140 my $netfs_ipaddr = $if->address;141 my $netfs_netmask = $if->netmask;142 my $netfs_broadcast = $if->broadcast;143 my $netfs_hwaddr = $if->hwaddr;144 142 pb_log(2, "interface = $if\n"); 145 143 pb_log(2, "--\n"); 146 pb_log(2, "addr = $ netfs_ipaddr\n",147 "broadcast = $ netfs_broadcast\n",148 "netmask = $ netfs_netmask\n",144 pb_log(2, "addr = $if->address\n", 145 "broadcast = $if->broadcast\n", 146 "netmask = $if->netmask\n", 149 147 "dstaddr = ",$if->dstaddr,"\n", 150 "hwaddr = $ netfs_hwaddr\n",148 "hwaddr = $if->hwaddr\n", 151 149 "mtu = ",$if->mtu,"\n", 152 150 "metric = ",$if->metric,"\n", … … 162 160 pb_log(2, "--\n"); 163 161 if (ipv4_in_network($if->address, $if->netmask, $hostip)) { 164 pb_log(1, "Netfs server $host is in network $netfs_ipaddr/$netfs_netmask\n"); 162 pb_log(1, "Netfs server $host is in network $if->address/$if->netmask\n"); 163 $found = 1; 165 164 # So generate conf file 166 print $fd "netfs-dev $if\n"; 167 print $fd "netfs-proto $scheme\n"; 168 print $fd "netfs-client-ipaddr $netfs_ipaddr\n"; 169 print $fd "netfs-client-netmask $netfs_netmask\n"; 170 print $fd "netfs-client-broadcast $netfs_broadcast\n"; 171 print $fd "netfs-client-hwaddr $netfs_hwaddr\n"; 172 print $fd "netfs-server-mount $ARGV[0]\n"; 173 print $fd "netfs-server-user $account\n"; 174 print $fd "netfs-server-ipaddr $hostip\n"; 175 open(ROUTE, "/proc/net/route") || die "Unable to read /proc/net/route: $!"; 176 while (<ROUTE>) { 177 my ($iface,$dest,$gw,$foo) = split(/\s+/,$_); 178 # Keep only default route 179 next if ($dest !~ /^00000000$/); 180 $gw =~ s/([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})/hex($4).".".hex($3).".".hex($2).".".hex($1)/eg; 181 print $fd "netfs-client-defgw $gw\n"; 182 } 183 close(ROUTE); 165 my ($iface,$gw) = mr_net_get_def_gw(); 166 mr_net_print_conf($fd, $if, $scheme, $if->address, $if->netmask, $if->broadcast, $if->hwaddr, $ARGV[0], $account, $hostip, $gw); 184 167 last if ($pbdebug > 1); 185 168 } 186 169 } 170 if ($found == 0) { 171 # Not found yet, so use the default GW to reach the server 172 my ($iface,$gw) = mr_net_get_def_gw(); 173 my $if = IO::Interface::Simple->new($iface); 174 mr_net_print_conf($fd, $if, $scheme, $if->address, $if->netmask, $if->broadcast, $if->hwaddr, $ARGV[0], $account, $hostip, $gw); 175 } 176 187 177 close($fd); 178 179 sub mr_net_get_def_gw { 180 181 my ($iface,$dest,$gw,$foo); 182 183 open(ROUTE, "/proc/net/route") || die "Unable to read /proc/net/route: $!"; 184 while (<ROUTE>) { 185 ($iface,$dest,$gw,$foo) = split(/\s+/,$_); 186 # Keep only default route 187 next if ($dest !~ /^00000000$/); 188 $gw =~ s/([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})([A-z0-9]{2})/hex($4).".".hex($3).".".hex($2).".".hex($1)/eg; 189 last; 190 } 191 close(ROUTE); 192 return($iface,$gw); 193 } 194 195 sub mr_net_print_conf { 196 197 my ($fd, $iface, $scheme, $netfs_ipaddr, $netfs_netmask, $netfs_broadcast, $netfs_hwaddr, $netfs_server_mount, $account, $hostip, $gw) = @_; 198 199 print $fd "netfs-dev $iface\n"; 200 print $fd "netfs-proto $scheme\n"; 201 print $fd "netfs-client-ipaddr $netfs_ipaddr\n"; 202 print $fd "netfs-client-netmask $netfs_netmask\n"; 203 print $fd "netfs-client-broadcast $netfs_broadcast\n"; 204 print $fd "netfs-client-hwaddr $netfs_hwaddr\n"; 205 print $fd "netfs-server-mount $ARGV[0]\n"; 206 print $fd "netfs-server-user $account\n"; 207 print $fd "netfs-server-ipaddr $hostip\n"; 208 print $fd "netfs-client-defgw $gw\n"; 209 }
Note:
See TracChangeset
for help on using the changeset viewer.