udhcpc 移植和使用

一、编译内核

1.执行make ARCH=arm CROSS_COMPLIE=arm-linux-  menuconfig,修改内核配置选项

Networking  --->

        [*] Networking support  

                          Networking options  ---> 

                                   <* > Packet socket                             //添加.配置CONFIG_PACKET

                                    [ * ]     IP: DHCP support                  //添加

                                    [ * ] Network packet filtering--->       //添加,后面子选项可不选,配置CONFIG_NETFILTER

2. 若没选<* > Packet socket, [ * ] Network packet filtering (replaces ipchains)  --->选项,在执行udhcpc命令时出现如下错误:

~ # udhcpc

udhcpc (v1.20.2) started

udhcpc: udhcpc (v1.20.2) started

FATAL: couldn't listen on socket, Address family not supported by protocol

udhcpc: FATAL: couldn't listen on socket, Address family not supported by protocol

二、编译busybox

配置busybox,添加以下选项

Networking Utilities  --->

                udhcp Server/Client  --->

                      [] udhcp Server (udhcpd)                          

                     [*] udhcp Client (udhcpc)       //生成udhcpc命令                               

                     [ ] Lease display utility (dumpleases)                        

                     [ ]   Log udhcp messages to syslog (instead of stdout)        

                     [ ]   Compile udhcp with noisy debugging messages

三、使用方法

udhcpc只是获取一个IP,并没有把ip写到指定的网卡中,需要把\busybox\examples\udhcp下的脚本simple.script改名为default.script,放在开发板上的/usr/share/dhcpc/目录下,修改权限为777。

重启开发板,执行udhcpc就可自动获取IP地址了。

udhcpc (v1.20.2) started
Setting IP address 0.0.0.0 on wlan0
Sending discover...
Sending select for 192.168.6.80...
Lease of 192.168.6.80 obtained, lease time 604800
Setting IP address 192.168.6.80 on wlan0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.6.1
Recreating /etc/resolv.conf
 Adding DNS server 219.150.32.132
 Adding DNS server 202.96.209.5
 Adding DNS server 223.5.5.5

 

你可能感兴趣的:(ARM)