rxw的RK3568的evb1公板,有2個以太口,
默認(rèn)UI界面只能配置eth0,無法配置eth1,
實(shí)際應(yīng)用中,有時需要一旦有網(wǎng)線插入,就需要該地址設(shè)置為指定IP地址。
本文介紹2個最簡單的方法實(shí)現(xiàn)固定IP。
一、通過修改ipconfig.txt
安卓設(shè)備以太口的配置信息保存在以下文件中:
/data/misc/ethernet/ipconfig.txt
該文件是二進(jìn)制文件,而且默認(rèn)只有eth0的配置信息,一口君通過一些特殊方法,生成了包含eth0、eth1的兩個網(wǎng)口配置的配置文件,
并且rxw原廠的ui界面可以識別該配置文件。
配置文件用16進(jìn)制格式打開內(nèi)容如下:
0000000000000003000C697041737369676E6D65......ipAssignme 000000106E740006535441544943000B6C696E6Bnt..STATIC..link 0000002041646472657373000D3139322E313638Address..192.168 000000302E34302E333400000018000767617465.40.34......gate 000000407761790000000000000001000C313932way..........192 000000502E3136382E34302E310003646E730007.168.40.1..dns.. 00000060302E302E302E300003646E730007302E0.0.0.0..dns..0. 00000070302E302E30000D70726F7879536574740.0.0..proxySett 00000080696E677300044E4F4E45000269640004ings..NONE..id.. 00000090657468300003656F73000C6970417373eth0..eos..ipAss 000000A069676E6D656E74000653544154494300ignment..STATIC. 000000B00B6C696E6B41646472657373000D3139.linkAddress..19 000000C0322E3136382E322E31323500000018002.168.2.125..... 000000D007676174657761790000000000000001.gateway........ 000000E0000B3139322E3136382E322E31000364..192.168.2.1..d 000000F06E730007302E302E302E300003646E73ns..0.0.0.0..dns 000001000007302E302E302E30000D70726F7879..0.0.0.0..proxy 0000011053657474696E677300044E4F4E450002Settings..NONE.. 0000012069640004657468310003656F73------id..eth1..eos
用 ascii格式打開如下【因?yàn)槭嵌M(jìn)制文件,會有部分內(nèi)容是亂碼】:
ipAssignmentSTATIClinkAddress 192.168.40.34gateway192.168.40.1dns0.0.0.0dns0.0.0.0 proxySettingsNONEideth0eosipAssignmentSTATIClinkAddress 192.168.2.125gateway192.168.2.1dns0.0.0.0dns0.0.0.0 proxySettingsNONEideth1eos
總結(jié)一下,主要配置信息如下:
|網(wǎng)口|ip|網(wǎng)關(guān)| |-----------------------------------------| |eth0|192.168.40.34|192.168.40.1| |eth1|192.168.2.125|192.168.2.1|
將該文件push進(jìn)開發(fā)板,重啟即可
adbroot adbremount adbpull/data/misc/ethernet/ipconfig.txt
這樣只要eth1對應(yīng)的以太口up,就會自動設(shè)置ip地址192.168.2.125
同時并不影響UI配置eth0接口
“
注意:
這種方法僅在rxw3568+android11上測試通過,其他平臺或者android版本沒有測試。
”
二、通過開源項目ifplugd
除了第一種種方法還可以通過一個開源的項目ifplugd來實(shí)現(xiàn)。
通過ifplugd工具監(jiān)聽網(wǎng)口熱插拔信息,然后執(zhí)行指定腳本,將配置命令存放在腳本中即可。
ifplugd的移植需要用到libdaemon庫,該庫主要提供守護(hù)進(jìn)程以及l(fā)og接口功能。
1. 移植步驟
1)準(zhǔn)備文件:
libdaemon-0.14.tar.gz ifplugd-0.14.tar.gz
后臺回復(fù):eth,既可以獲取
“
沒有采用最新的libdaemon、ifplugd,會有版本兼容問題
”
本實(shí)例基于ndk編譯器編譯,
為了方便起見,我把libdaemon、ifplugd源文件全部拷貝到ndk實(shí)例工程下,libdaemon的頭文件,拷貝了2次,
方便c文件包含。
.....src-ifplugd$tree./ ./ ├──Application.mk ├──daemon.h ├──dexec.c ├──dexec.h ├──dfork.c ├──dfork.h ├──dlog.c ├──dlog.h ├──dnonblock.c ├──dnonblock.h ├──dpid.c ├──dpid.h ├──dsignal.c ├──dsignal.h ├──ethtool-kernel.h ├──ethtool-local.h ├──ifplugd.c ├──ifstatus.c ├──include ├──interface.c ├──interface.h ├──libdaemon │├──daemon.h │├──dexec.h │├──dfork.h │├──dlog.h │├──dnonblock.h │├──dpid.h │└──dsignal.h ├──svn-revision.h └──YROS.mk 2directories,29files
2)修改配置文件
編譯描述信息位于文件YROS.mk中,
【讀者根據(jù)自己工程,文件會有所不同】
YROS.mk修改如下:
LOCAL_PATH:=$(callmy-dir) include$(CLEAR_VARS) LOCAL_SRC_FILES:= ifplugd.cinterface.cdexec.cdfork.cdlog.cdnonblock.cdpid.cdsignal.c LOCAL_SHARED_LIBRARIES:= LOCAL_MODULE_TAGS:=optional LOCAL_CLANG:=true LOCAL_MODULE:=ethcheckd include$(BUILD_EXECUTABLE)
3)編譯
編譯錯誤1
λbuild.bat ndk-build.cmd [armeabi-v7a]Compilethumb:ifplugd<=?ifplugd.c????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c13:?error:?use?of?undeclared?identifier?'SYSCONFDIR'??????????????????????????????????????????????????????????????? char?*run?=?SYSCONFDIR"/ifplugd/ifplugd.action";???????????????????????????????????????????????????????????????????????????????????? ????????????^??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c23:?error:?expected?';'?after?top?level?declarator????????????????????????????????????????????????????????????????? char?*run?=?SYSCONFDIR"/ifplugd/ifplugd.action";???????????????????????????????????????????????????????????????????????????????????? ??????????????????????^????????????????????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????;????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c18:?warning:?multiple?unsequenced?modifications?to?'sigfd'?[-Wunsequenced]???????????????????????????????????????? ????FD_SET(sigfd?=?daemon_signal_fd(),?&rfds);?????????????????????????????????????????????????????????????????????????????????????? ?????????????????^?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h50:?note:?expanded?from?macro?'FD_SET'???????????????????????????? #define?FD_SET(fd,?set)?(__FDS_BITS(set)[__FDELT(fd)]?|=?__FDMASK(fd))?????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????^????????????????~~???????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h23:?note:?expanded?from?macro?'__FDELT'??????????????????????????? #define?__FDELT(fd)?((fd)?/?NFDBITS)???????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????^????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c36:?error:?expected?')'??????????????????????????????????????????????????????????????????????????????????????????? ????daemon_log(LOG_INFO,?"ifplugd?"VERSION"?successfully?initialized,?link?beat?%sdetected.",?status?==?IFSTATUS_UP???""?:?"not?");? ???????????????????????????????????^???????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c15:?note:?to?match?this?'('??????????????????????????????????????????????????????????????????????????????????????? ????daemon_log(LOG_INFO,?"ifplugd?"VERSION"?successfully?initialized,?link?beat?%sdetected.",?status?==?IFSTATUS_UP???""?:?"not?");? ??????????????^????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c18:?warning:?multiple?unsequenced?modifications?to?'sigfd'?[-Wunsequenced]???????????????????????????????????????? ????FD_SET(sigfd?=?daemon_signal_fd(),?&rfds);?????????????????????????????????????????????????????????????????????????????????????? ?????????????????^?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h50:?note:?expanded?from?macro?'FD_SET'???????????????????????????? #define?FD_SET(fd,?set)?(__FDS_BITS(set)[__FDELT(fd)]?|=?__FDMASK(fd))?????????????????????????????????????????????????????????????? ?????????????????????????????????????????????????^????????????????~~???????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h23:?note:?expanded?from?macro?'__FDELT'??????????????????????????? #define?__FDELT(fd)?((fd)?/?NFDBITS)???????????????????????????????????????????????????????????????????????????????????????????????? ??????????????????????^????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c26:?error:?expected?')'??????????????????????????????????????????????????????????????????????????????????????????? ????????printf("ifplugd?"VERSION"?(SVN:?"SVN_REVISION") ");???????????????????????????????????????????????????????????????????????? ?????????????????????????^?????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c15:?note:?to?match?this?'('??????????????????????????????????????????????????????????????????????????????????????? ????????printf("ifplugd?"VERSION"?(SVN:?"SVN_REVISION") ");???????????????????????????????????????????????????????????????????????? ??????????????^????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 2?warnings?and?4?errors?generated.?????????????????????????????????????????????????????????????????????????????????????????????????? make:?***?[obj/local/armeabi-v7a/objs/ifplugd/ifplugd.o]?Error?1????????????????????????????????????????????????????????????????????請?zhí)砑訄D片描述
修改文件ifplugd.c
59#defineVARRUN"/system" 63#defineSYSCONFDIR"" 64#defineVERSION"yikoulinux"
編譯錯誤2
λbuild.bat ndk-build.cmd [armeabi-v7a]Compilethumb:ifplugd<=?dexec.c [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dfork.c [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dlog.c [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dnonblock.c [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dpid.c src/dpid.c43:?error:?use?of?undeclared?identifier?'LOCALSTATEDIR' ????snprintf(fn,?sizeof(fn),?"%s/%s.pid",?VARRUN,?daemon_pid_file_ident???daemon_pid_file_ident?:?"unknown"); ??????????????????????????????????????????^ src/dpid.c16:?note:?expanded?from?macro?'VARRUN' #define?VARRUN?LOCALSTATEDIR?"/run" ???????????????^ 1?error?generated. make:?***?[obj/local/armeabi-v7a/objs/ifplugd/dpid.o]?Error?1
修改文件dpid.c
50#defineLOCALSTATEDIR
4) 編譯成功
編譯成功log如下:
H:compileforandroid λbuild.bat ndk-build.cmd [armeabi-v7a]Compilethumb:ifplugd<=?ifplugd.c?????????????????????????????????????????????????????????????????????? src/ifplugd.c53:?warning:?missing?sentinel?in?function?call?[-Wsentinel]???????????????????????????????????????????? ????????execl(run,?run,?interface,?arg,?extra_arg,?0);??????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????^???????????????????????????????????????????????????????????????????? ????????????????????????????????????????????????????,?NULL??????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includeunistd.h5:?note:?function?has?been?explicitly?marked?sentinel?here int?execl(const?char*?__path,?const?char*?__arg0,?...)?__attribute__((__sentinel__));???????????????????????????????????? ????^???????????????????????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c18:?warning:?multiple?unsequenced?modifications?to?'sigfd'?[-Wunsequenced]????????????????????????????? ????FD_SET(sigfd?=?daemon_signal_fd(),?&rfds);??????????????????????????????????????????????????????????????????????????? ?????????????????^??????????????????????????????????????????????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h50:?note:?expanded?from?macro?'FD_SET'????????????????? #define?FD_SET(fd,?set)?(__FDS_BITS(set)[__FDELT(fd)]?|=?__FDMASK(fd))??????????????????????????????????????????????????? ?????????????????????????????????????????????????^????????????????~~????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h23:?note:?expanded?from?macro?'__FDELT'???????????????? #define?__FDELT(fd)?((fd)?/?NFDBITS)????????????????????????????????????????????????????????????????????????????????????? ??????????????????????^?????????????????????????????????????????????????????????????????????????????????????????????????? src/ifplugd.c18:?warning:?multiple?unsequenced?modifications?to?'sigfd'?[-Wunsequenced]????????????????????????????? ????FD_SET(sigfd?=?daemon_signal_fd(),?&rfds);??????????????????????????????????????????????????????????????????????????? ?????????????????^??????????????????????????????????????????????????????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h50:?note:?expanded?from?macro?'FD_SET'????????????????? #define?FD_SET(fd,?set)?(__FDS_BITS(set)[__FDELT(fd)]?|=?__FDMASK(fd))??????????????????????????????????????????????????? ?????????????????????????????????????????????????^????????????????~~????????????????????????????????????????????????????? H:/yros-ndk-windows/build//../sysroot/usr/includesys/select.h23:?note:?expanded?from?macro?'__FDELT'???????????????? #define?__FDELT(fd)?((fd)?/?NFDBITS)????????????????????????????????????????????????????????????????????????????????????? ??????????????????????^?????????????????????????????????????????????????????????????????????????????????????????????????? 3?warnings?generated.???????????????????????????????????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?interface.c???????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dexec.c???????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dfork.c???????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dlog.c????????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dnonblock.c???????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dpid.c????????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Compile?thumb??:?ifplugd?<=?dsignal.c?????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Executable?????:?ifplugd??????????????????????????????????????????????????????????????????????????????????? [armeabi-v7a]?Install????????:?ifplugd?=>libs/armeabi-v7a/ifplugd在這里插入圖片描述
程序位置如下:
libsarmeabi-v7aifplugd
測試
1. 查看ifplugd參數(shù)
ifplugd-h
rk3568_r:/#ifplugd-h ifplugd[options] -a--no-autoDonotenableinterfaceautomatically(off) -n--no-daemonDonotdaemonize(fordebugging)(off) -s--no-syslogDonotusesyslog,usestderrinstead(fordebugging)(off) -b--no-beepDonotbeep(off) -f--ignore-failIgnoredetectionfailure,retryinstead(failureistreatedasDOWN)(off) -F--ignore-fail-positiveIgnoredetectionfailure,retryinstead(failureistreatedasUP)(off) -i--iface=IFACESpecifyethernetinterface(eth0) -r--run=EXECSpecifyprogramtoexecute(/ifplugd/ifplugd.action) -I--ignore-retvalDon'texitonnonzeroreturnvalueofprogramexecuted(off) -t--poll-time=SECSSpecifypolltimeinseconds(1) -u--delay-up=SECSSpecifydelayforconfiguringinterface(0) -d--delay-down=SECSSpecifydelayfordeconfiguringinterface(5) -m--api-mode=MODEForceAPImode(mii,priv,ethtool,wlan,auto)(auto) -q--no-shutdownDon'trunscriptondaemonquit(off) -w--wait-on-forkWaituntildaemonforkfinished(off) -x--extra-argSpecifyanextraargumentforactionscript -h--helpShowthishelp -k--killKillarunningdaemon -c--check-runningCheckifadaemoniscurrentlyrunning -v--versionShowversion -S--suspendSuspendrunningdaemon -R--resumeResumerunningdaemon -z--infoWritestatusofrunningdaemontosyslog
2. 增加腳本if.sh
當(dāng)網(wǎng)口eth1 up后,ifplugd會執(zhí)行如下命令【下面動作由ifplugd自動執(zhí)行】:
/system/if.sheth1up
根據(jù)參數(shù)順序,編寫腳本if.sh如下:
#!/bin/bash IPADDR=192.168.40.8 ETHPORT=eth1 echo"danielpengset"$ETHPORT$IPADDR echo$# echo$0 echo$1 echo$2 if[$#-eq2];then if[$1=$ETHPORT];then echo$ETHPORT if[$2="up"];then ifconfig$ETHPORT$IPADDR sleep1 ipruleaddfromalllookupmainpref9000 sleep1 echo1>/proc/sys/net/ipv4/ip_forward iptables-F echo"set"$ETHPORT"done" elif[$2="down"];then echo"down" elif[$2="disable"];then echo"disable" elif[$2="error"];then echo"error" fi fi fi
功能:
網(wǎng)口eth1 up后,設(shè)置該網(wǎng)口地址為IPADDR,即:192.168.40.8
讀者可以根據(jù)自己的需要編寫相應(yīng)的腳本。
3. 運(yùn)行ifplugd
ifplugd監(jiān)聽網(wǎng)口eth1并且執(zhí)行后面的腳本文件
在板子上輸入以下命令:
ifplugd-ieth1-r"sh/system/if.sh"
查看該守護(hù)進(jìn)程:
H:compileforandroid λadbshell rk3568_r:/#ifplugd-ieth1-r"sh/system/if.sh" rk3568_r:/#ps-ef|grepif wifi280100952?0000android.hardware.wifi@1.0-service wifi385100953?0000wificond root1826101006?0000ifplugd-ieth1-rsh/system/if.sh root1834181921017pts/00000grepif
一旦網(wǎng)口插入網(wǎng)線后,地址就會被自動設(shè)置。
補(bǔ)充
ifplugd的確可以實(shí)現(xiàn)監(jiān)測網(wǎng)卡的狀態(tài),并執(zhí)行相應(yīng)腳本,
但是有個前提,就是網(wǎng)口已經(jīng)注冊到系統(tǒng)中,即用ifconfig -a能查看到
如何是usb網(wǎng)口這種設(shè)備,在插入usb口之后網(wǎng)口設(shè)備才會注冊,
那么這種情況下,要想設(shè)置usb網(wǎng)卡,那么就就需要修改ifplugd程序。
下文,給大家講解如何自己實(shí)現(xiàn)一個簡單的網(wǎng)口檢測并設(shè)置ip的小程序。
審核編輯:湯梓紅
-
接口
+關(guān)注
關(guān)注
33文章
8575瀏覽量
151015 -
二進(jìn)制
+關(guān)注
關(guān)注
2文章
795瀏覽量
41643 -
ip地址
+關(guān)注
關(guān)注
0文章
301瀏覽量
17032 -
開發(fā)板
+關(guān)注
關(guān)注
25文章
5032瀏覽量
97371
原文標(biāo)題:如何固定以太口地址為指定ip?
文章出處:【微信號:良許Linux,微信公眾號:良許Linux】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
評論