有什么方法可以获取本地ip,或者网关

发布于 2020-01-10 21:49:29    浏览:530
硬件:潘多拉开发板STM32L475
移植了wifi,可以连到手机app的udp服务器。然后想建立socket,就是找不到api接口可以获取本地的ip或者网关?
翻了一晚上,看到有这个接口
/**
* @ingroup netif
* Find a network interface by searching for its name
*
* @param name the name of the netif (like netif->name) plus concatenated number
* in ascii representation (e.g. 'en0')
*/
struct netif *
netif_find(const char *name)
{
struct netif *netif;
u8_t num;

if (name == NULL) {
return NULL;
}

num = (u8_t)(name[2] - '0');

for (netif = netif_list; netif != NULL; netif = netif->next) {
if (num == netif->num &&
name[0] == netif->name[0] &&
name[1] == netif->name[1]) {
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: found %c%c\n", name[0], name[1]));
return netif;
}
}
LWIP_DEBUGF(NETIF_DEBUG, ("netif_find: didn't find %c%c\n", name[0], name[1]));
return NULL;
}

但是直接在应用程序里面,加了头文件也没用 #include "lwip/netif.h":Q



查看更多

1 个回答
Mr.Liu
Mr.Liu 2020-01-11
This guy hasn't written anything yet
int netdev_ifconfig(int argc, char **argv)
{
if (argc == 1)
{
netdev_list_if();
}
else if (argc == 5)
{
rt_kprintf("config : %s\n", argv[1]);
rt_kprintf("IP addr: %s\n", argv[2]);
rt_kprintf("Gateway: %s\n", argv[3]);
rt_kprintf("netmask: %s\n", argv[4]);
netdev_set_if(argv[1], argv[2], argv[3], argv[4]);
}
else
{
rt_kprintf("bad parameter! e.g: ifconfig e0 192.168.1.30 192.168.1.1 255.255.255.0\n");
}

return 0;
}

撰写答案

请登录后再发布答案,点击登录
关注者
0
被浏览
530

发布
问题

分享
好友

手机
浏览

扫码手机浏览