ARM上的linux如何实现无线网卡的冷插拔和热插拔(4)
- UID
- 1029342
- 性别
- 男
|
ARM上的linux如何实现无线网卡的冷插拔和热插拔(4)
# Calculate the network configuration value#如果没有上面的动态分配且不存在子网掩码,就需要分配一个
if [ -z "${netmask}" ] ; then
eval $(/bin/ipcalc --netmask ${ipaddr})
fi
#Configure for the WiFi interface IP address and bring up it
#静态分配ip地址和掩码。
ifconfig $DEVICE $ipaddr netmask $netmask up
#Set the default route
#把DEFROUTE选项都转化为大写。
DEFROUTE=$(echo $DEFROUTE | awk '{ print toupper($0) }')
#如果GATEWAY字符长度不为0且DEFROUTE选项为YES时,
if [ -n "$GATEWAY" -a "$DEFROUTE" = "YES" ]; then
#ip route add ${NETWORK}/${PREFIX} via $GATEWAY > /dev/null 2>&1
ip route replace default via $GATEWAY
fi
#Start wpa_supplicant to work now
mkdir -p /var/run/wpa_supplicant
/apps/tools/wpa_supplicant -B -Dwext -i$DEVICE -c${network_cfg_dir}/wpa_supplicant.conf
}
#通过将rt2070/rt3070配置为AP模式后,我们的笔记本和手机就能连接到wlan0上来,再通过netfilter/iptables构建的防火墙,使eth0接有线连接到internet上,我们的笔记本和手机就能通过它上网 -_-||
configure_wifi_ap()
{
parser_ip
#Configure for the WiFi interface IP address and bring up it
#如果ipaddr长度为0,就静态分配ipaddr
if [ -z "$ipaddr" ] ; then
ipaddr=192.168.1.166
netmask=255.255.255.0
fi
ifconfig $DEVICE $ipaddr netmask $netmask up
#Enable DHCP server
#使能DHCP服务功能,这样我们就不用为每台连接到开发板上的电脑和手机静态分配ip地址,而是通过开发板上的DHCP服务为每一台连接的终端设备动态分配地址。
DHCP_SERVER=$(echo $DHCP_SERVER | awk '{ print toupper($0) }')
#如果$DHCP_SERVER 长度不为空,且$DHCP_SERVER为YES时才为真。
if [ -n "$DHCP_SERVER" -a "$DHCP_SERVER" = "YES" ]; then
#定义一些配置文件:/tmp/dhcpd_wlan0.config , /tmp/dhcpd_wlan0.leases , /var/run/dhcpd_wlan0.pid
conf_file="/tmp/dhcpd_${DEVICE}.conf"
lease_file="/tmp/dhcpd_${DEVICE}.leases"
pid_file="/var/run/dhcpd_${DEVICE}.pid"
#[lingyun@localhost ~]$ ipcalc -h
ipcalc: ip address expected
Usage: ipcalc [OPTION...]
-c, --check Validate IP address for specified address family
-4, --ipv4 IPv4 address family (default)
-6, --ipv6 IPv6 address family
-b, --broadcast Display calculated broadcast address(显示指定ip和子网掩码的广播地址)
-h, --hostname Show hostname determined via DNS(显示指定ip的主机名)
-m, --netmask Display default netmask for IP (class A, B, or C)(显示指定ip的子网掩码--特指默认,实际未必是)
-n, --network Display network address(显示指定ip的网络地址)
-p, --prefix Display network prefix(显示网络前缀)
-s, --silent Don't ever display error messages (不显示错误信息)
Help options:
-?, --help Show this help message
--usage Display brief usage message
#[lingyun@localhost ~]$ipcalc -p 192.168.1.1 255.255.255.0
PREFIX=24
#[lingyun@localhost ~]$ipcalc -n 192.168.1.1 255.255.255.0
NETWORK=192.168.1.0
#[lingyun@localhost ~]$ipcalc -h 192.168.1.1
HOSTNAME=dbrg-2
#[lingyun@localhost ~]$ipcalc -m 192.168.1.1
NETMASK=255.255.255.0
#[lingyun@localhost ~]$ipcalc -pnbm 192.168.1.1 255.255.255.0
NETMASK=255.255.255.0
PREFIX=24
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
#[lingyun@localhost ~]$
所以下面的意图是取得子网的网络地址。例如
[lingyun@localhost ~]$ ipcalc -n 192.168.5.1 255.255.255.0
NETWORK=192.168.5.0
[lingyun@localhost ~]$ ipcalc -n 192.168.5.1 255.255.255.0 | awk -F "=" '{print $2}'
192.168.5.0
[lingyun@localhost ~]$
DHCP_SUBNET=`ipcalc -n $DHCP_START_IP $DHCP_NETMASK | awk -F "=" '{print $ 2}` |
|
|
|
|
|