移植DHCP client 到micro2440 linux-3.1.4(by liukun321咕唧咕唧)

 

可以用两种方法来实现DHCP客户端,下面简单说明一下操作过程:

1.用busybox的udhcpc工具.

首先配置内核使其支持DHCP,以及socket

[*] Networking support  ---><*> Packet socket

                                                  [*]     IP: DHCP support

                                                 [*] Network packet filtering framework (Netfilter)  --->

然后配置busybox

Networking Utilities --->
udhcp Server/Client --->
        [ * ] udhcp Server (udhcpd)       
udhcp Client (udhcpc)                                     
       [ * ] Lease display utility (dumpleases)                         
        [ * ] Log udhcp messages to syslog (instead of stdout)         
       [ * ] Compile udhcp with noisy debugging messages

make

make install

编译完并安装busybox后,将busybox源码目录下的 example/udhcpc/simple.script 脚本cp到根文件系统的/usr/share/udhcpc/default.script

然后运行udhcpc,由于udhcpc默认是给eth0配置DHCP服务,而我要初始化wlan0

[root@FriendlyLEG /]# udhcpc  -i wlan0

udhcpc (v1.17.4) started
Setting IP address 0.0.0.0 on wlan0
Sending discover...
Sending select for 192.168.0.12...
Lease of 192.168.0.12 obtained, lease time 86400
Setting IP address 192.168.0.12 on wlan0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.0.1
Recreating /etc/resolv.conf
 Adding DNS server 219.147.1.66
 Adding DNS server 219.146.1.66

然后ping一下百度

连接正常.

PS:

# udhcpc --help

  BusyBox v1.14.1 (2010-01-22 10:35:16 CST) multi-call binary

  Usage: udhcpc [-Cfbnqtvo] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]

  [-p pidfile] [-r IP] [-s script] [-O dhcp-option]... [-P N]

  -V CLASSID Vendor class identifier

  -i INTERFACE Interface to use (default: eth0)

  -H,-h HOSTNAME Client hostname

  -c CLIENTID Client identifier

  -C Suppress default client identifier

  -p file Create pidfile

  -r IP IP address to request

  -s file Run file at DHCP events (default /usr/share/udhcpc/default.script)

  -t N Send up to N request packets

  -T N Try to get a lease for N seconds (default 3)

  -A N Wait N seconds (default 20) after failure

  -O OPT Request DHCP option OPT (cumulative)

  -o Do not request any options (unless -O is also given)

  -f Run in foreground

  -b Background if lease is not immediately obtained

  -S Log to syslog too

  -n Exit with failure if lease is not immediately obtained

  -q Quit after obtaining lease

  -R Release IP on quit

  -P N Use port N instead of default 68

  -a Use arping to validate offered address

我在移植过程中错用了udhcpc wlan0 命令,没提示错误但一直初始化eth0,我误以为wlan0参数无效 ,就修改了default.script中的interface变量interface=wlan0

但是改后

[root@FriendlyLEG /]# udhcpc  wlan0
udhcpc (v1.17.4) started
Setting IP address 0.0.0.0 on wlan0
Sending discover...
Sending select for 192.168.1.100...
Lease of 192.168.1.100 obtained, lease time 7200
Setting IP address 192.168.1.100 on wlan0
Deleting routers
route: SIOCDELRT: No such process
Adding router 192.168.1.1
Recreating /etc/resolv.conf
 Adding DNS server 192.168.1.1

这个结果是不正确的,具体为什么这样初始化我还没看过源码,也没法解释.改成udhcpc  -i wlan0后就可正常获得ip了.

2.下载DHCP源码,编译后得到dhclient工具,实现DHCP client.

(1),下载源码:http://gd.tuwien.ac.at/infosys/servers/isc/dhcp/ ,选中 dhcp-3.1.3.tar.gz;

(2),解压 tar -zxvf dhcp-3.1.3.tar.gz,然后进入./dhcp-3.1.3/,运行配置./configure,之后生成work.linux-2.2文件夹,进入work.linux-2.2/client/,输入make "CC=arm-linux-gcc -static",将编译生成dhclient。
 

(3),拷贝生成的dhclient到mini2440开发板上,为方便使用,可以放在/usr/bin/下;拷贝另外两个配置文件到开发板,分别是

     /dhcp-3.1.3/client/dhclient.conf和/dhcp-3.1.3/client/scripts/linux 到开发板的/sbin/目录下。并改名后一个文件为dhclient-script,并修改该文件的第一行#! /bin/bash 为#! /bin/sh,保存后,修改权限 chmod +x /sbin/dhclient-script。

(4),为eth0 或者wlan0配置dhcp服务,输入dhclient eth0 或者dhclient wlan0 即可.

你可能感兴趣的:(server,socket,File,interface,networking,debugging)