momo zone

调核人的blog

搞定arposion的移植

首先确定需要哪些工具包 , arposion 依赖libnet ,所以要这两个都要下载。libnet 在suse的源里面就有源码包,rpm -ivv libnet*.src.rpm 安装之后直接把libnet*.tar.gz 解压:

|– CVS
|   |– Entries
|   |– Repository
|   `– Root
|– Makefile
|– Makefile.am
|– Makefile.am.common
|– Makefile.in
|– README
|– VERSION
|– acconfig.h
|– acinclude.m4
|– aclocal.m4
|– autom4te.cache
|   |– CVS
|   |   |– Entries
|   |   |– Repository
|   |   `– Root
|   |– output.0
|   |– requests
|   `– traces.0
|– config.guess
|– config.log
|– config.status
|– config.sub
|– configure
|– configure.in
|– doc
|   |– BUGS
|   |– CHANGELOG
|   |– CONTRIB
|   |– COPYING
|   |– CVS
|   |   |– Entries
|   |   |– Repository
|   |   `– Root
|   |– DESIGN_NOTES
|   |– MIGRATION
|   |– PACKET_BUILDING
|   |– PORTED
|   |– RAWSOCKET_NON_SEQUITUR
|   |– TODO
|   |– html
|   |   |– acconfig_8h-source.html
|   |   |– annotated.html
|   |   |– bpf_8h-source.html
|   |   |– config_8h-source.html
|   |   |– doxygen.css
|   |   |– doxygen.png
|   |   |– files.html
|   |   |– functions.html
|   |   |– functions_vars.html
|   |   |– getopt_8h-source.html
|   |   |– globals.html
|   |   |– globals_defs.html
|   |   |– globals_func.html
|   |   |– gnuc_8h-source.html
|   |   |– graph_legend.dot
|   |   |– graph_legend.html
|   |   |– ifaddrlist_8h-source.html
|   |   |– in__systm_8h-source.html
|   |   |– index.html
|   |   |– libnet-asn1_8h-source.html
|   |   |– libnet-functions_8h-source.html
|   |   |– libnet-functions_8h.html
|   |   |– libnet-headers_8h-source.html
|   |   |– libnet-headers_8h.html
|   |   |– libnet-macros_8h-source.html
|   |   |– libnet-macros_8h.html
|   |   |– libnet-structures_8h-source.html
|   |   |– libnet-types_8h-source.html
|   |   |– libnet_8h-source.html
|   |   |– libnet_8h.html
|   |   |– structlibnet__802__1q__hdr.html
|   |   `– structlibnet__802__1x__hdr.html
|   |– libnet.doxygen.conf
|   `– man
|       |– CVS
|       |   |– Entries
|       |   |– Repository
|       |   `– Root
|       `– man3
|           |– libnet-functions.h.3
|           |– libnet-headers.h.3
|           |– libnet-macros.h.3
|           |– libnet.h.3
|           |– libnet_802_1q_hdr.3
|           `– libnet_802_1x_hdr.3
|– include
|   |– CVS
|   |   |– Entries
|   |   |– Repository
|   |   `– Root
|   |– Makefile
|   |– Makefile.am
|   |– Makefile.in
|   |– bpf.h
|   |– config.h
|   |– config.h.in
|   |– gnuc.h
|   |– ifaddrlist.h
|   |– libnet
|   |   |– CVS
|   |   |   |– Entries
|   |   |   |– Repository
|   |   |   `– Root
|   |   |– Makefile
|   |   |– Makefile.am
|   |   |– Makefile.in
|   |   |– libnet-asn1.h
|   |   |– libnet-functions.h
|   |   |– libnet-headers.h
|   |   |– libnet-macros.h
|   |   |– libnet-structures.h
|   |   `– libnet-types.h
|   |– libnet.h
|   |– libnet.h.in
|   |– libnet.h~
|   |– stamp-h.in
|   |– stamp-h1
|   `– win32
|       |– CVS
|       |   |– Entries
|       |   |– Repository
|       |   `– Root
|       |– config.h
|       |– getopt.h
|       |– in_systm.h
|       `– libnet.h
|– install-sh
|– libnet-config
|– libnet-config.in
|– libnet.doxygen.conf
|– man
|   `– CVS
|       |– Entries
|       |– Repository
|       `– Root
|– missing
|– mkinstalldirs
|– sample
|   |– CVS
|   |   |– Entries
|   |   |– Repository
|   |   `– Root
|   |– Makefile
|   |– Makefile.am
|   |– Makefile.in
|   |– arp
|   |– arp-new.c
|   |– arp.c
|   |– arp.o
|   |– bgp4_hdr
|   |– bgp4_hdr.c
|   |– bgp4_hdr.o
|   |– bgp4_notification
|   |– bgp4_notification.c
|   |– bgp4_notification.o
|   |– bgp4_open
|   |– bgp4_open.c
|   |– bgp4_open.o
|   |– bgp4_update
|   |– bgp4_update.c
|   |– bgp4_update.o
|   |– cdp
|   |– cdp.c
|   |– cdp.o
|   |– dhcp_discover
|   |– dhcp_discover.c
|   |– dhcp_discover.o
|   |– dns
|   |– dns.c
|   |– dns.o
|   |– dot1x
|   |– dot1x.c
|   |– dot1x.o
|   |– fddi_tcp1
|   |– fddi_tcp1.c
|   |– fddi_tcp1.o
|   |– fddi_tcp2
|   |– fddi_tcp2.c
|   |– fddi_tcp2.o
|   |– get_addr
|   |– get_addr.c
|   |– get_addr.o
|   |– gre
|   |– gre.c
|   |– gre.o
|   |– icmp6_echoreq
|   |– icmp6_echoreq.c
|   |– icmp6_echoreq.o
|   |– icmp_echo_cq
|   |– icmp_echo_cq.c
|   |– icmp_echo_cq.o
|   |– icmp_redirect
|   |– icmp_redirect.c
|   |– icmp_redirect.o
|   |– icmp_timeexceed
|   |– icmp_timeexceed.c
|   |– icmp_timeexceed.o
|   |– icmp_timestamp
|   |– icmp_timestamp.c
|   |– icmp_timestamp.o
|   |– icmp_unreach
|   |– icmp_unreach.c
|   |– icmp_unreach.o
|   |– ieee
|   |– ieee.c
|   |– ieee.o
|   |– ip_link
|   |– ip_link.c
|   |– ip_link.o
|   |– ip_raw
|   |– ip_raw.c
|   |– ip_raw.o
|   |– isl
|   |– isl.c
|   |– isl.o
|   |– libnet_test.h
|   |– mpls
|   |– mpls.c
|   |– mpls.o
|   |– ntp
|   |– ntp.c
|   |– ntp.o
|   |– ospf_hello
|   |– ospf_hello.c
|   |– ospf_hello.o
|   |– ospf_lsa
|   |– ospf_lsa.c
|   |– ospf_lsa.o
|   |– ping_of_death
|   |– ping_of_death.c
|   |– ping_of_death.o
|   |– rpc_tcp
|   |– rpc_tcp.c
|   |– rpc_tcp.o
|   |– rpc_udp
|   |– rpc_udp.c
|   |– rpc_udp.o
|   |– sebek
|   |– sebek.c
|   |– sebek.o
|   |– smurf
|   |– smurf.c
|   |– smurf.o
|   |– stp
|   |– stp.c
|   |– stp.o
|   |– synflood
|   |– synflood.c
|   |– synflood.o
|   |– synflood6
|   |– synflood6.c
|   |– synflood6.o
|   |– synflood6_frag
|   |– synflood6_frag.c
|   |– synflood6_frag.o
|   |– tcp1
|   |– tcp1.c
|   |– tcp1.o
|   |– tcp2
|   |– tcp2.c
|   |– tcp2.o
|   |– tftp
|   |– tftp.c
|   |– tftp.o
|   |– tring_tcp1
|   |– tring_tcp1.c
|   |– tring_tcp1.o
|   |– tring_tcp2
|   |– tring_tcp2.c
|   |– tring_tcp2.o
|   |– udp1
|   |– udp1.c
|   |– udp1.o
|   |– udp2
|   |– udp2.c
|   |– udp2.o
|   `– win32
|       |– CVS
|       |   |– Entries
|       |   |– Repository
|       |   `– Root
|       |– arp
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– arp.vcproj
|       |– cdp
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– cdp.vcproj
|       |– dhcp_discover
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– dhcp_discover.vcproj
|       |– dns
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– dns.vcproj
|       |– get_addr
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– get_addr.vcproj
|       |– getopt.c
|       |– icmp_echo_cq
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– icmp_echo_cq.vcproj
|       |– tcp1
|       |   |– CVS
|       |   |   |– Entries
|       |   |   |– Repository
|       |   |   `– Root
|       |   `– tcp1.vcproj
|       `– udp1
|           |– CVS
|           |   |– Entries
|           |   |– Repository
|           |   `– Root
|           |– dns.vcproj
|           `– udp1.vcproj
|– src
|   |– CVS
|   |   |– Entries
|   |   |– Repository
|   |   `– Root
|   |– Makefile
|   |– Makefile.am
|   |– Makefile.in
|   |– libnet.a
|   |– libnet_advanced.c
|   |– libnet_advanced.o
|   |– libnet_asn1.c
|   |– libnet_asn1.o
|   |– libnet_build_802.1q.c
|   |– libnet_build_802.1q.o
|   |– libnet_build_802.1x.c
|   |– libnet_build_802.1x.o
|   |– libnet_build_802.2.c
|   |– libnet_build_802.2.o
|   |– libnet_build_802.3.c
|   |– libnet_build_802.3.o
|   |– libnet_build_arp.c
|   |– libnet_build_arp.o
|   |– libnet_build_bgp.c
|   |– libnet_build_bgp.o
|   |– libnet_build_cdp.c
|   |– libnet_build_cdp.o
|   |– libnet_build_data.c
|   |– libnet_build_data.o
|   |– libnet_build_dhcp.c
|   |– libnet_build_dhcp.o
|   |– libnet_build_dns.c
|   |– libnet_build_dns.o
|   |– libnet_build_ethernet.c
|   |– libnet_build_ethernet.o
|   |– libnet_build_fddi.c
|   |– libnet_build_fddi.o
|   |– libnet_build_gre.c
|   |– libnet_build_gre.o
|   |– libnet_build_icmp.c
|   |– libnet_build_icmp.o
|   |– libnet_build_igmp.c
|   |– libnet_build_igmp.o
|   |– libnet_build_ip.c
|   |– libnet_build_ip.o
|   |– libnet_build_ipsec.c
|   |– libnet_build_ipsec.o
|   |– libnet_build_isl.c
|   |– libnet_build_isl.o
|   |– libnet_build_link.c
|   |– libnet_build_mpls.c
|   |– libnet_build_mpls.o
|   |– libnet_build_ntp.c
|   |– libnet_build_ntp.o
|   |– libnet_build_ospf.c
|   |– libnet_build_ospf.o
|   |– libnet_build_rip.c
|   |– libnet_build_rip.o
|   |– libnet_build_rpc.c
|   |– libnet_build_rpc.o
|   |– libnet_build_sebek.c
|   |– libnet_build_sebek.o
|   |– libnet_build_snmp.c
|   |– libnet_build_snmp.o
|   |– libnet_build_stp.c
|   |– libnet_build_stp.o
|   |– libnet_build_tcp.c
|   |– libnet_build_tcp.o
|   |– libnet_build_token_ring.c
|   |– libnet_build_token_ring.o
|   |– libnet_build_udp.c
|   |– libnet_build_udp.o
|   |– libnet_build_vrrp.c
|   |– libnet_build_vrrp.o
|   |– libnet_checksum.c
|   |– libnet_checksum.o
|   |– libnet_cq.c
|   |– libnet_cq.o
|   |– libnet_crc.c
|   |– libnet_crc.o
|   |– libnet_dll.c
|   |– libnet_error.c
|   |– libnet_error.o
|   |– libnet_if_addr.c
|   |– libnet_if_addr.o
|   |– libnet_init.c
|   |– libnet_init.o
|   |– libnet_internal.c
|   |– libnet_internal.o
|   |– libnet_link_bpf.c
|   |– libnet_link_dlpi.c
|   |– libnet_link_linux.c
|   |– libnet_link_linux.o
|   |– libnet_link_nit.c
|   |– libnet_link_none.c
|   |– libnet_link_pf.c
|   |– libnet_link_snit.c
|   |– libnet_link_snoop.c
|   |– libnet_link_win32.c
|   |– libnet_pblock.c
|   |– libnet_pblock.o
|   |– libnet_port_list.c
|   |– libnet_port_list.o
|   |– libnet_prand.c
|   |– libnet_prand.o
|   |– libnet_raw.c
|   |– libnet_raw.o
|   |– libnet_resolve.c
|   |– libnet_resolve.o
|   |– libnet_version.c
|   |– libnet_version.o
|   |– libnet_write.c
|   `– libnet_write.o
|– version.h
|– version.h.in
`– win32
    |– CVS
    |   |– Entries
    |   |– Repository
    |   `– Root
    |– Libnet-1.1.1-2002.sln
    |– Libnet-1.1.1-2003.ncb
    |– Libnet-1.1.1-2003.sln
    |– Libnet-1.1.1-2003.suo
    |– Libnet-1.1.1.vcproj
    |– Libnet-latest.ncb
    |– Libnet-latest.opt
    |– Libnet-latest.sln
    |– Libnet-latest.suo
    |– Libnet-latest.vcproj
    |– Libnet.dsp
    |– Libnet.dsw
    |– README.txt
    `– libnet_dll.def
该库的项目使用了automake。libnet库的核心就是那几个头文件和几个*.c文件(被编译成静态连接库*.o,最后还将被打包成ar包)
./configure CC=~/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-uclibc-gcc –host=mipsel-linux
再看一下arposion
.
|– LICENSE
|– Makefile
|– README
|– TODO
|– arpoison
|– arpoison.8
|– arpoison.c
`– lookup.c
相对简单很多,只用到了make,核心就是arposion.c。 lookup.c 是根据hostname查ip,实际并没有被用到。

先编译libnet: 
设置configure,使用: 
./configure CC=~/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/mipsel-linux-uclibc-gcc –host=mipsel-linux  
这里的–host=mipsel-linux是必须的,生成的config在文件config.status。
执行make:
Making all in include
make[1]: Entering directory `/root/libnet/include’
make  all-recursive
make[2]: Entering directory `/root/libnet/include’
Making all in libnet
make[3]: Entering directory `/root/libnet/include/libnet’
make[3]: Nothing to be done for `all’.
make[3]: Leaving directory `/root/libnet/include/libnet’
make[3]: Entering directory `/root/libnet/include’
make[3]: Leaving directory `/root/libnet/include’
make[2]: Leaving directory `/root/libnet/include’
make[1]: Leaving directory `/root/libnet/include’
Making all in src
make[1]: Entering directory `/root/libnet/src’
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/mipsel-linux/bin/gcc -DHAVE_CONFIG_H -I. -I. -I../include     -g -O2 -Wall -c `test -f ‘libnet_asn1.c’ || echo ‘./’`libnet_asn1.c
In file included from libnet_asn1.c:60:
../include/libnet.h:117:10: macro names must be identifiers
make[1]: *** [libnet_asn1.o] Error 1
make[1]: Leaving directory `/root/libnet/src’
make: *** [all-recursive] Error 1
报错信息很明确../include/libnet.h第117行有问题,看了一下该行定义了一个空的宏
#include <errno.h>
#include <stdarg.h>

#define LIBNET_VERSION  "1.1.2.1"
#define  1

#include "./libnet/libnet-types.h"
#include "./libnet/libnet-macros.h"
#include "./libnet/libnet-headers.h"
#include "./libnet/libnet-structures.h"
#include "./libnet/libnet-asn1.h"
#include "./libnet/libnet-functions.h"
mark 掉就能通过了,然后继续杯具:
libnet_build_ip.c: In function `libnet_build_ipv4′:
libnet_build_ip.c:80: error: structure has no member named `ip_v’
libnet_build_ip.c:81: error: structure has no member named `ip_hl’
libnet_build_ip.c:96: error: structure has no member named `ip_hl’
libnet_build_ip.c: In function `libnet_autobuild_ipv4′:
libnet_build_ip.c:282: error: structure has no member named `ip_v’
libnet_build_ip.c:283: error: structure has no member named `ip_hl’
libnet_build_ip.c:298: error: structure has no member named `ip_hl’
libnet_build_ip.c: In function `libnet_build_ipv4_options’:
libnet_build_ip.c:435: error: structure has no member named `ip_hl’
make[1]: *** [libnet_build_ip.o] Error 1
make[1]: Leaving directory `/root/libnet/src’
make: *** [all-recursive] Error 1
找不到结构成员ip_v,ip_hl ,wiki 了一下发现应该是ip header 的结构,在头文件<netinet/ip.h>中。难道是没有包含该头文件?不假思索地在libnet_build_ip中include <netinet/ip.h> 然后尝试编译仍然报错。继续分析,发现这两个成员属于ip_hdr ,而不是glibc中的<netinet/ip.h>。ip_hdr的原型是libnet_ipv4,可以想象libnet的头文件重定义了标准头文件的一些结构。 那么这个libnet_ipv4在哪里呢 ? 翻了半天最终在include/libnet/libnet-headers.h中找到了:
struct libnet_ipv4_hdr
{
#if (LIBNET_LIL_ENDIAN)
    u_int8_t ip_hl:4,      /* header length */
           ip_v:4;         /* version */
#endif
#if (LIBNET_BIG_ENDIAN)
    u_int8_t ip_v:4,       /* version */
           ip_hl:4;        /* header length */
#endif
    u_int8_t ip_tos;       /* type of service */
#ifndef IPTOS_LOWDELAY
#define IPTOS_LOWDELAY      0x10
……..
}
应该是这个头文件没有被正确include进去吧
我把这一段结构直接贴到libnet_build_ip.c中然后编译,竟然还是不行。
这个真是杯具了,看来要卡死在这里了,找不到真正原因。
第二天继续看这个结构,我突然发现这里ip_v,ip_hl 都是条件编译! 
哦,明白了,应该是编译器既没有定义宏LIBNET_BIG_ENDIAN也没有定义LIBNET_LIL_ENDIAN ,所以这两个变量直接就pass了。
ok,直接在该文件头定义:
#include LIBNET_LIL_ENDIAN 1 //MIPSEL is LITTLE ENDIAN
这样编译就通过了,没有任何错误。生成了libnet.a ,庆祝一下~~
回过头来想这个头文件其实处理的很好,真正好的做法还是应该通过编译选项把这个宏定义出来,但我就不知道具体该怎么做了,还要继续深入研究一下了。

接下来就需要编译了arposion
首先把编译好的libnet.a 放到mipsel-linux-uclibc-gcc 可以搜索到的路径中, 先查看一下搜索顺序: 
#./mipsel-linux-uclibc-gcc -print-search-dirs
install: /home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/lib/gcc/mipsel-linux-uclibc/3.4.4/

programs: =/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../libexec/gcc/mipsel-linux-uclibc/3.4.4/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../libexec/gcc/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/libexec/gcc/mipsel-linux-uclibc/3.4.4/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/libexec/gcc/mipsel-linux-uclibc/3.4.4/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/libexec/gcc/mipsel-linux-uclibc/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/lib/gcc/mipsel-linux-uclibc/3.4.4/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/lib/gcc/mipsel-linux-uclibc/:
/usr/libexec/gcc/mipsel-linux-uclibc/3.4.4/:
/usr/libexec/gcc/mipsel-linux-uclibc/:
/usr/lib/gcc/mipsel-linux-uclibc/3.4.4/:
/usr/lib/gcc/mipsel-linux-uclibc/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/../../../../mipsel-linux-uclibc/bin/mipsel-linux-uclibc/3.4.4/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/../../../../mipsel-linux-uclibc/bin/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/mipsel-linux-uclibc/bin/mipsel-linux-uclibc/3.4.4/:/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/mipsel-linux-uclibc/bin/

libraries: =/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/lib/gcc/mipsel-linux-uclibc/3.4.4/:
/usr/lib/gcc/mipsel-linux-uclibc/3.4.4/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/../../../../mipsel-linux-uclibc/lib/mipsel-linux-uclibc/3.4.4/:
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/../../../../mipsel-linux-uclibc/lib/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/mipsel-linux-uclibc/lib/mipsel-linux-uclibc/3.4.4/:
/home/nbd/wr/whiterussian-0.9/staging_dir_mipsel/mipsel-linux-uclibc/lib/
一大堆看晕了,其实按照红色路径去放就对了
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/

头文件就放在
/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/bin/../lib/gcc/mipsel-linux-uclibc/3.4.4/include 
包括libnet.h 和libnet 目录

然后编辑Makefile :
BINBASE=/root/OpenWrt-SDK-Linux-i686-1/staging_dir_mipsel/mipsel-linux-uclibc/bin

CC=${BINBASE}/gcc

all:
        ${CC} -Wall `libnet-config –defines` arpoison.c -o arpoison `libnet-config –libs`
#       gcc –host=mipsel-linux -Wall `libnet-config –defines` arpoison.c -o arpoison `libnet-config –libs`
clean:

        rm arpoison

然后make 没有任何输出就证明编译成功~~ 
再次祝贺一下
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: