我试了两种方法,都能成功配置第二个网口:
1.静态配置,在生成内核时,配置内核
include IFCONFIG_2模块,设置参数为:
“ifname”,“devname motetsec1”,“inet 192.168.1.66/24”,“gateway 192.168.1.1”
rebuild生成vxWorks映像,ok。
2.动态配置,通过命令行调用函数,也可在usrAppInit.c文件中调用函数。
需要添加必要的头文件,也可添加对应的内核功能模块,请参考vxWorks help。
#include <ipProto.h>
#include <ifLib.h>
绑定第二个网络接口:
ipAttach(1,“motetsec”);
ifMaskSet(“motetsec1”,0xffffff00);
ifAddrSet(“motetsec1”,"192.168.1.66);
之后我在命令行运行->ifconfig “motetsec1 up”
运行->ifconfig “-a”
motetsec1 Link type:Ethernet HWaddr ec:9e💿0f:90:03 Queue:none
capabilities: TXCSUM TX6CSUM
inet 192.168.1.66 mask 255.255.255.0 broadcast 192.168.1.255
UP SIMPLEX BROADCAST MULTICAST
MTU:1500 metric:1 VR:0 ifindex:3
RX packets:0 mcast:0 errors:0 dropped:0
TX packets:0 mcast:0 errors:0
collisions:0 unsupported proto:0
RX bytes:0 TX bytes:0
其中有个UP表示网口启用,如果没有运行->ifconfig "motetsec1 up"是没有UP的,会ping不通。
接好网线的另一端,运行->ifconfig "-a"会多出一个RUNNING,表示网口运行状态。
ping通,OK。