首页 > *nix技术, Shell命令 > net-tools编译问题的解决

net-tools编译问题的解决

2012年2月8日 发表评论 阅读评论 12,410 次浏览

net-tools是Linux下一个软件包,里面包含了很多网络工具,比如arp、ifconfig、ipmaddr、iptunnel、route、nameif、mii-tool等等。
具体参看如下链接:
http://net-tools.sourceforge.net/
http://net-tools.berlios.de/
http://en.wikipedia.org/wiki/Ifconfig
http://www.linuxfoundation.org/collaborate/workgroups/networking/net-tools
从sourceforge上下载最新的net-tools-1.60源码之后解压编译:

[root@localhost net-tools-1.60]# uname -a
Linux localhost.localdomain 2.6.38.8 #4 SMP Mon Oct 31 20:49:48 CST 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost net-tools-1.60]# ls
ABOUT-NLS     COPYING     INSTALLING  lib         nameif.c      po           route.c       TODO
arp.c         hostname.c  intl.h      Makefile    netstat.c     rarp.c       RPM
config.in     ifconfig.c  ipmaddr.c   man         nls           README       slattach.c
configure.sh  include     iptunnel.c  mii-tool.c  plipconfig.c  README.ipv6  statistics.c
[root@localhost net-tools-1.60]# make config
rm -f config.h
Configuring the Linux net-tools (NET-3 Base Utilities)...
...
[root@localhost net-tools-1.60]# make
make[1]: Entering directory `/home/lenky/nic/test/net-tools-1.60/man'
make[1]: Nothing to be done for `all'.
...
inet_sr.c: In function ‘INET_setroute’:
inet_sr.c:107: error: label at end of compound statement
make[1]: *** [inet_sr.o] Error 1
make[1]: Leaving directory `/home/lenky/nic/test/net-tools-1.60/lib'
make: *** [subdirs] Error 2
[root@localhost net-tools-1.60]# 

出错,打上补丁,gcc-3.4.patch补丁代码为:

diff -Nur net-tools-1.60/hostname.c net-tools-1.60-fixed/hostname.c
--- net-tools-1.60/hostname.c	2001-04-08 19:04:23.000000000 +0200
+++ net-tools-1.60-fixed/hostname.c	2004-05-29 20:29:50.526423387 +0200
@@ -98,6 +98,7 @@
 	    fprintf(stderr, _("%s: name too long\n"), program_name);
 	    break;
 	default:
+      ;
 	}
 	exit(1);
     };
@@ -117,6 +118,7 @@
 	    fprintf(stderr, _("%s: name too long\n"), program_name);
 	    break;
 	default:
+      ;
 	}
 	exit(1);
     };
@@ -174,6 +176,7 @@
 	printf("%s\n", hp->h_name);
 	break;
     default:
+  ;
     }
 }
 
diff -Nur net-tools-1.60/lib/inet_sr.c net-tools-1.60-fixed/lib/inet_sr.c
--- net-tools-1.60/lib/inet_sr.c	2000-02-20 22:46:45.000000000 +0100
+++ net-tools-1.60-fixed/lib/inet_sr.c	2004-05-29 20:29:42.490447616 +0200
@@ -105,6 +105,7 @@
     case 2:
        isnet = 0; break;
     default:
+       ;
     }
 
     /* Fill in the other fields. */

编译还是出错:

[root@localhost net-tools-1.60]# patch -Np1 -i gcc-3.4.patch 
patching file hostname.c
patching file lib/inet_sr.c
[root@localhost net-tools-1.60]# make
make[1]: Entering directory `/home/lenky/nic/test/net-tools-1.60/man'
make[1]: Nothing to be done for `all'.
...
cc -D_GNU_SOURCE -O2 -Wall -g  -I. -idirafter ./include/ -Ilib -I/home/lenky/nic/test/net-tools-1.60 -idirafter /home/lenky/nic/test/net-tools-1.60/include    -c -o x25_sr.o x25_sr.c
x25_sr.c: In function ‘X25_setroute’:
x25_sr.c:80: error: ‘x25_address’ undeclared (first use in this function)
x25_sr.c:80: error: (Each undeclared identifier is reported only once
x25_sr.c:80: error: for each function it appears in.)
make[1]: *** [x25_sr.o] Error 1
make[1]: Leaving directory `/home/lenky/nic/test/net-tools-1.60/lib'
make: *** [subdirs] Error 2
[root@localhost net-tools-1.60]# 

再打补丁,net-tools-1.60-2.patch补丁代码为:

diff --exclude CVS -uNr net-tools-1.60/lib/x25_sr.c net-tools-1.60.modified/lib/x25_sr.c
--- net-tools-1.60/lib/x25_sr.c	Sat May 20 14:38:10 2000
+++ net-tools-1.60.modified/lib/x25_sr.c	Mon Jan 31 14:18:46 2005
@@ -22,6 +22,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <linux/x25.h>
+#include <linux/version.h>
 #include <ctype.h>
 #include <errno.h>
 #include <netdb.h>
@@ -77,7 +78,12 @@
   rt.sigdigits=sigdigits;
 
   /* x25_route_struct.address isn't type struct sockaddr_x25, Why? */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) 
+#warning this is a 2.4 kernel
   memcpy(&rt.address, &sx25.sx25_addr, sizeof(x25_address));
+#else
+  memcpy(&rt.address, &sx25.sx25_addr, sizeof(struct x25_address));
+#endif
 
   while (*args) {
 	if (!strcmp(*args,"device") || !strcmp(*args,"dev")) {

再编译,可以了:

[root@localhost net-tools-1.60]# patch -Np1 -i net-tools-1.60-2.patch 
patching file lib/x25_sr.c
[root@localhost net-tools-1.60]# make
make[1]: Entering directory `/home/lenky/nic/test/net-tools-1.60/man'
make[1]: Nothing to be done for `all'.
...
cc  -Llib -o plipconfig plipconfig.o -lnet-tools
cc -D_GNU_SOURCE -O2 -Wall -g  -I. -idirafter ./include/ -Ilib   -c -o nameif.o nameif.c
cc  -Llib -o nameif nameif.o 
[root@localhost net-tools-1.60]# ls
ABOUT-NLS      configure.sh   ifconfig.o  man         net-tools-1.60-2.patch  rarp.o       slattach.c
arp            COPYING        include     mii-tool.c  nls                     README       slattach.o
arp.c          gcc-3.4.patch  INSTALLING  nameif      plipconfig              README.ipv6  statistics.c
arp.o          hostname       intl.h      nameif.c    plipconfig.c            route        statistics.o
config.h       hostname.c     ipmaddr.c   nameif.o    plipconfig.o            route.c      TODO
config.in      hostname.o     iptunnel.c  netstat     po                      route.o      version.h
config.make    ifconfig       lib         netstat.c   rarp                    RPM
config.status  ifconfig.c     Makefile    netstat.o   rarp.c                  slattach
[root@localhost net-tools-1.60]# ./ifconfig eth3
eth3      Link encap:Ethernet  HWaddr 00:0C:29:45:2E:8B  
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:68351 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1437 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:5367314 (5.1 Mb)  TX bytes:210091 (205.1 Kb)

[root@localhost net-tools-1.60]# 

转载请保留地址:http://www.lenky.info/archives/2012/02/1024http://lenky.info/?p=1024


备注:如无特殊说明,文章内容均出自Lenky个人的真实理解而并非存心妄自揣测来故意愚人耳目。由于个人水平有限,虽力求内容正确无误,但仍然难免出错,请勿见怪,如果可以则请留言告之,并欢迎来讨论。另外值得说明的是,Lenky的部分文章以及部分内容参考借鉴了网络上各位网友的热心分享,特别是一些带有完全参考的文章,其后附带的链接内容也许更直接、更丰富,而我只是做了一下归纳&转述,在此也一并表示感谢。关于本站的所有技术文章,欢迎转载,但请遵从CC创作共享协议,而一些私人性质较强的心情随笔,建议不要转载。

法律:根据最新颁布的《信息网络传播权保护条例》,如果您认为本文章的任何内容侵犯了您的权利,请以Email或书面等方式告知,本站将及时删除相关内容或链接。

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.