struct netif * ip_router(ip_addr_t *dest, ip_addr_t *source){ struct netif *netif; /* iterate through netifs */ for(netif = netif_list; netif != NULL; netif = netif->next) { /* network mask matches? */ if (netif_is_up(netif)) { if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { /* return netif on which to forward IP packet */ return netif; } } if (netif_is_up(netif)) { if (ip_addr_netcmp(source, &(netif->ip_addr), &(netif->netmask))) { /* return netif on which to forward IP packet */ return netif; } } } if ((netif_default == NULL) || (!netif_is_up(netif_default))) { LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip_route: No route to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest))); IP_STATS_INC(ip.rterr); snmp_inc_ipoutnoroutes(); return NULL; } /* no matching netif found, use default netif */ return netif_default; }
/** * @brief Initializes audio * @param None. * @retval Audio state. */ void VNC_SERVER_Start (void) { if(is_initialized == 0) { is_initialized = 1; /* Create tcp_ip stack thread */ tcpip_init(NULL, NULL); /* Initialize the LwIP stack */ Netif_Config(); /* Check connection */ if (netif_is_up(&gnetif)) { /* Update VNC state machine */ VNC_State = VNC_LINK_UP; VNC_SERVER_StatusChanged(VNC_LINK_UP); } else { /* Update VNC state machine */ VNC_State = VNC_LINK_DOWN; VNC_SERVER_LogMessage ("Cable is not connected \n"); VNC_SERVER_StatusChanged(VNC_LINK_DOWN); } } else if(VNC_State == VNC_INIT) { /* Check connection */ if (netif_is_up(&gnetif)) { /* Update VNC state machine */ VNC_State = VNC_LINK_UP; VNC_SERVER_StatusChanged(VNC_LINK_UP); } else { /* Update VNC state machine */ VNC_State = VNC_LINK_DOWN; VNC_SERVER_LogMessage ("Cable is not connected \n"); VNC_SERVER_StatusChanged(VNC_LINK_DOWN); } } /* Start VNC Task */ if(VNC_ThreadId == 0) { osThreadDef(VNC, VNC_Thread, osPriorityAboveNormal, 0, 1024); VNC_ThreadId = osThreadCreate (osThread(VNC), NULL); } }
void LWIP::Interface::netif_status_irq(struct netif *netif) { LWIP::Interface *interface = our_if_from_netif(netif); nsapi_connection_status_t connectedStatusPrev = interface->connected; if (netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) { bool dns_addr_has_to_be_added = false; if (!(interface->has_addr_state & HAS_ANY_ADDR) && LWIP::get_ip_addr(true, netif)) { if (interface->blocking) { osSemaphoreRelease(interface->has_any_addr); } interface->has_addr_state |= HAS_ANY_ADDR; dns_addr_has_to_be_added = true; } #if PREF_ADDR_TIMEOUT if (!(interface->has_addr_state & HAS_PREF_ADDR) && LWIP::get_ip_addr(false, netif)) { if (interface->blocking) { osSemaphoreRelease(interface->has_pref_addr); } interface->has_addr_state |= HAS_PREF_ADDR; dns_addr_has_to_be_added = true; } #endif #if BOTH_ADDR_TIMEOUT if (!(interface->has_addr_state & HAS_BOTH_ADDR) && LWIP::get_ipv4_addr(netif) && LWIP::get_ipv6_addr(netif)) { if (interface->blocking) { osSemaphoreRelease(interface->has_both_addr); } interface->has_addr_state |= HAS_BOTH_ADDR; dns_addr_has_to_be_added = true; } #endif if (dns_addr_has_to_be_added && !interface->blocking) { add_dns_addr(&interface->netif); } if (interface->has_addr_state & HAS_ANY_ADDR) { interface->connected = NSAPI_STATUS_GLOBAL_UP; } } else if (!netif_is_up(&interface->netif) && netif_is_link_up(&interface->netif)) { interface->connected = NSAPI_STATUS_DISCONNECTED; } if (interface->client_callback && (connectedStatusPrev != interface->connected) && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */ interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); } }
/********************************************************************************************************* ** 函数名称: __tshellIfDown ** 功能描述: 系统命令 "ifdown" ** 输 入 : iArgC 参数个数 ** ppcArgV 参数表 ** 输 出 : 0 ** 全局变量: ** 调用模块: *********************************************************************************************************/ static INT __tshellIfDown (INT iArgC, PCHAR *ppcArgV) { struct netif *netif; if (iArgC != 2) { fprintf(stderr, "argments error!\n"); return (-ERROR_TSHELL_EPARAM); } netif = netif_find(ppcArgV[1]); /* 查询网络接口 */ if (netif == LW_NULL) { fprintf(stderr, "can not find net interface.\n"); return (-ERROR_TSHELL_EPARAM); } if (!netif_is_up(netif)) { fprintf(stderr, "net interface already set down.\n"); return (PX_ERROR); } #if LWIP_DHCP > 0 if (netif->dhcp && netif->dhcp->pcb) { netifapi_netif_common(netif, NULL, dhcp_release); /* 解除 DHCP 租约 */ netifapi_dhcp_stop(netif); /* 释放资源 */ } #endif /* LWIP_DHCP > 0 */ netifapi_netif_set_down(netif); /* 禁用网卡 */ printf("net interface \"%s\" set down.\n", ppcArgV[1]); return (ERROR_NONE); }
/** * @brief Notify the User about the nework interface config status * @param netif: the network interface * @retval None */ void User_notification(struct netif *netif) { if (netif_is_up(netif)) { #ifdef USE_DHCP /* Update DHCP state machine */ DHCP_state = DHCP_START; #else #ifdef USE_LCD uint8_t iptxt[20]; sprintf((char*)iptxt, "%d.%d.%d.%d", IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3); LCD_UsrLog ("Static IP address: %s\n", iptxt); #else /* Turn On LED 1 to indicate ETH and LwIP init success*/ BSP_LED_On(LED1); #endif /* USE_LCD */ #endif /* USE_DHCP */ } else { #ifdef USE_DHCP /* Update DHCP state machine */ DHCP_state = DHCP_LINK_DOWN; #endif /* USE_DHCP */ #ifdef USE_LCD LCD_UsrLog ("The network cable is not connected \n"); #else /* Turn On LED 2 to indicate ETH and LwIP init error */ BSP_LED_On(LED2); #endif /* USE_LCD */ } }
/******************************************************************************* ** Name: WebEthIntit ** Input:void ** Return: void ** Owner:zhuzhe ** Date: 2014.6.24 ** Time: 11:08:41 *******************************************************************************/ _WEB_TASK_WEBTASK_INIT_ INIT FUN void WebEthIntit(void) { WEB_TASK_CTRL_BLOCK* pWebTaskControlBlock = gpstWebCtrlBlock; WEB_EVENT_CLASS TempWebEventItem; struct netif * pNetif = pWebTaskControlBlock->pWifiNetif; uint32 timeout; tcpip_init(NULL, NULL); memset(pWebTaskControlBlock->pWifiNetif, 0, sizeof(struct netif)); netif_add(pWebTaskControlBlock->pWifiNetif, NULL, NULL, NULL, NULL,ethernetif_init, ethernet_input); netif_set_default(pWebTaskControlBlock->pWifiNetif); netif_set_link_up(pWebTaskControlBlock->pWifiNetif); dhcp_start(pWebTaskControlBlock->pWifiNetif); do { vTaskDelay(100); if ( netif_is_up(pWebTaskControlBlock->pWifiNetif)) { rk_printf("IP %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)), ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr))); rk_printf("GW %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", ip4_addr1_16(&(pNetif->ip_addr)), ip4_addr2_16(&(pNetif->ip_addr)), ip4_addr3_16(&(pNetif->ip_addr)), ip4_addr4_16(&(pNetif->ip_addr))); break; } } while (1); }
/** * \brief Status callback used to print assigned IP address. * * \param netif Instance to network interface. */ void status_callback(struct netif *netif) { if (netif_is_up(netif)) { strcat((char*)g_c_ipconfig, inet_ntoa(*(struct in_addr *)&(netif->ip_addr))); g_ip_mode = 3; } }
/********************************************************************************************************* ** 函数名称: __tshellIfUp ** 功能描述: 系统命令 "ifup" ** 输 入 : iArgC 参数个数 ** ppcArgV 参数表 ** 输 出 : 0 ** 全局变量: ** 调用模块: *********************************************************************************************************/ static INT __tshellIfUp (INT iArgC, PCHAR *ppcArgV) { struct netif *netif; BOOL bUseDHCP = LW_FALSE; /* 是否使用自动获取 IP */ BOOL bShutDownDHCP = LW_FALSE; /* 是否强制关闭 DHCP */ if (iArgC < 2) { fprintf(stderr, "argments error!\n"); return (-ERROR_TSHELL_EPARAM); } else if (iArgC > 2) { if (lib_strcmp(ppcArgV[2], "-dhcp") == 0) { bUseDHCP = LW_TRUE; /* 使用 DHCP 启动 */ } else if (lib_strcmp(ppcArgV[2], "-nodhcp") == 0) { bShutDownDHCP = LW_TRUE; } } netif = netif_find(ppcArgV[1]); /* 查询网络接口 */ if (netif == LW_NULL) { fprintf(stderr, "can not find net interface.\n"); return (-ERROR_TSHELL_EPARAM); } if (netif_is_up(netif)) { /* 网卡是否已经启动 */ #if LWIP_DHCP > 0 /* 首先关闭网卡 */ if (netif->dhcp && netif->dhcp->pcb) { netifapi_netif_common(netif, NULL, dhcp_release); /* 解除 DHCP 租约 */ netifapi_dhcp_stop(netif); /* 释放资源 */ } #endif /* LWIP_DHCP > 0 */ netifapi_netif_set_down(netif); /* 禁用网卡 */ } netifapi_netif_set_up(netif); /* 启动网卡 */ #if LWIP_DHCP > 0 if (bUseDHCP) { netif->flags2 |= NETIF_FLAG2_DHCP; /* 使用 DHCP 启动 */ } else if (bShutDownDHCP) { netif->flags2 &= ~NETIF_FLAG2_DHCP; /* 强制关闭 DHCP */ } if (netif->flags2 & NETIF_FLAG2_DHCP) { ip_addr_t inaddrNone; lib_bzero(&inaddrNone, sizeof(ip_addr_t)); netifapi_netif_set_addr(netif, &inaddrNone, &inaddrNone, &inaddrNone); /* 所有地址设置为 0 */ printf("DHCP client starting...\n"); if (netifapi_dhcp_start(netif) < ERR_OK) { printf("DHCP client serious error.\n"); } else { printf("DHCP client start.\n"); } } #endif /* LWIP_DHCP > 0 */ printf("net interface \"%s\" set up.\n", ppcArgV[1]); return (ERROR_NONE); }
static bool mbed_lwip_is_local_addr(const ip_addr_t *ip_addr) { struct netif *netif; for (netif = netif_list; netif != NULL; netif = netif->next) { if (!netif_is_up(netif)) { continue; } #if LWIP_IPV6 if (IP_IS_V6(ip_addr)) { for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && ip6_addr_cmp(netif_ip6_addr(netif, i), ip_2_ip6(ip_addr))) { return true; } } } #endif #if LWIP_IPV4 if (IP_IS_V4(ip_addr)) { if (!ip4_addr_isany(netif_ip4_addr(netif)) && ip4_addr_cmp(netif_ip4_addr(netif), ip_2_ip4(ip_addr))) { return true; } } #endif } return false; }
static void lwip_netif_status_irq(struct netif *lwip_netif) { if (netif_is_up(lwip_netif)) { strcpy(lwip_ip_addr, inet_ntoa(lwip_netif->ip_addr)); sys_sem_signal(&lwip_netif_up); } }
/** * Mapping from local network to loopback for outbound connections. * * Copy "src" to "dst" with ip6_addr_set(dst, src), but if "src" is a * local network address that maps host's loopback address, copy IPv6 * loopback address to "dst". */ int pxremap_outbound_ip6(ip6_addr_t *dst, ip6_addr_t *src) { struct netif *netif; int i; LWIP_ASSERT1(dst != NULL); LWIP_ASSERT1(src != NULL); for (netif = netif_list; netif != NULL; netif = netif->next) { if (!netif_is_up(netif) /* || this is not a proxy netif */) { continue; } for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; ++i) { if (ip6_addr_ispreferred(netif_ip6_addr_state(netif, i)) && ip6_addr_isuniquelocal(netif_ip6_addr(netif, i))) { ip6_addr_t *ifaddr = netif_ip6_addr(netif, i); if (memcmp(src, ifaddr, sizeof(ip6_addr_t) - 1) == 0 && ((IP6_ADDR_BLOCK8(src) & 0xff) == (IP6_ADDR_BLOCK8(ifaddr) & 0xff) + 1)) { ip6_addr_set_loopback(dst); return PXREMAP_MAPPED; } } } } /* not remapped, just copy src */ ip6_addr_set(dst, src); return PXREMAP_ASIS; }
/** * Start AutoIP client * * @param netif network interface on which start the AutoIP client */ err_t autoip_start(struct netif *netif) { struct autoip *autoip = netif->autoip; err_t result = ERR_OK; LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;);
void LWIP::Interface::netif_link_irq(struct netif *netif) { LWIP::Interface *interface = our_if_from_netif(netif); nsapi_connection_status_t connectedStatusPrev = interface->connected; if (netif_is_link_up(&interface->netif) && interface->connected == NSAPI_STATUS_CONNECTING) { nsapi_error_t dhcp_status = interface->set_dhcp(); if (interface->blocking && dhcp_status == NSAPI_ERROR_OK) { osSemaphoreRelease(interface->linked); } else if (dhcp_status != NSAPI_ERROR_OK) { netif_set_down(&interface->netif); } } else { osSemaphoreRelease(interface->unlinked); if (netif_is_up(&interface->netif)) { interface->connected = NSAPI_STATUS_CONNECTING; } netif_set_down(&interface->netif); } if (interface->client_callback && connectedStatusPrev != interface->connected && interface->connected != NSAPI_STATUS_GLOBAL_UP /* advertised by netif_status_irq */ && interface->connected != NSAPI_STATUS_DISCONNECTED) { /* advertised by bring_down */ interface->client_callback(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, interface->connected); } }
void status_callback(struct netif *netif) { if (netif_is_up(netif)) { printf("status_callback==UP, local interface IP is %s\n", ip_ntoa(&netif->ip_addr)); } else { printf("status_callback==DOWN\n"); } }
static void netif_status_callback(struct netif *netif) { if (netif_is_up(netif)) { strcpy(ip_addr, inet_ntoa(netif->ip_addr)); strcpy(gateway, inet_ntoa(netif->gw)); strcpy(networkmask, inet_ntoa(netif->netmask)); netif_up.release(); } }
/** * \brief Callback function used to print the given IP address when the link * is up. * * \param netif The network interface instance. */ void status_callback(struct netif *netif) { int8_t c_mess[20]; if (netif_is_up(netif)) { strcpy((char*)c_mess, "IP="); strcat((char*)c_mess, inet_ntoa(*(struct in_addr *)&(netif->ip_addr))); printf("Network up %s\r\n", (char const*)c_mess); } else { printf("Network down\r\n"); } }
/** * Bind a pcb contained in a netconn * Called from netconn_bind. * * @param msg the api_msg_msg pointing to the connection and containing * the IP address and port to bind to */ void do_bind(struct api_msg_msg *msg) { if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { //[MS_CHANGE] - make sure we are binding to a valid address u8_t validAddr = ip_addr_isany(msg->msg.bc.ipaddr); if(!validAddr) { struct netif *netif; for(netif = netif_list; netif != NULL; netif = netif->next) { /* network mask matches? */ if (netif_is_up(netif)) { if(ip_addr_cmp(msg->msg.bc.ipaddr, &netif->ip_addr)) { validAddr = 1; break; } } } } //[MS_CHANGE] - make sure we are binding to a valid address if(validAddr) { switch (NETCONNTYPE_GROUP(msg->conn->type)) { #if LWIP_RAW case NETCONN_RAW: msg->conn->err = raw_bind(msg->conn->pcb.raw, msg->msg.bc.ipaddr); break; #endif /* LWIP_RAW */ #if LWIP_UDP case NETCONN_UDP: msg->conn->err = udp_bind(msg->conn->pcb.udp, msg->msg.bc.ipaddr, msg->msg.bc.port); break; #endif /* LWIP_UDP */ #if LWIP_TCP case NETCONN_TCP: msg->conn->err = tcp_bind(msg->conn->pcb.tcp, msg->msg.bc.ipaddr, msg->msg.bc.port); break; #endif /* LWIP_TCP */ default: break; } } else { msg->conn->err = ERR_VAL; } } else { /* msg->conn->pcb is NULL */ msg->conn->err = ERR_VAL; } } TCPIP_APIMSG_ACK(msg); }
/*! * \brief status callback used to print address given by DHCP */ void status_callback(struct netif *netif) { char mess[25]; if (netif_is_up(netif)) { display_print("Network up"); strcpy(mess,"IP="); strcat(mess,inet_ntoa(*(struct in_addr*)&(netif->ip_addr))); display_print(mess); } else { display_print("Network down"); } }
const ip_addr_t *LWIP::get_ipv4_addr(const struct netif *netif) { if (!netif_is_up(netif)) { return NULL; } if (!ip4_addr_isany(netif_ip4_addr(netif))) { return netif_ip_addr4(netif); } return NULL; }
static const ip_addr_t *mbed_lwip_get_ipv4_addr(const struct netif *netif) { if (!netif_is_up(netif)) { return NULL; } if (!ip4_addr_isany(netif_ip4_addr(netif))) { return netif_ip_addr4(netif); } return NULL; }
static void netif_status_changed(struct netif *netif) { struct tls_netif_status_event *status_event; ethif->status = netif_is_up(nif); #if TLS_CONFIG_APSTA u8 mode; tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void* )&mode, FALSE); #endif dl_list_for_each(status_event, &netif_status_event.list, struct tls_netif_status_event, list) { if(status_event->status_callback != NULL && netif_is_up(netif)) { if (0 == tls_wifi_get_oneshot_flag()) { #if TLS_CONFIG_APSTA if (IEEE80211_MODE_APSTA == mode) { if (netif_is_up(nif) && !netif_is_up(nif->next)) status_event->status_callback(NETIF_APSTA_STA_NET_UP); else if (netif_is_up(nif) && netif_is_up(nif->next)) status_event->status_callback(NETIF_IP_NET_UP); } else #endif { status_event->status_callback(NETIF_IP_NET_UP); } } } } }
/** * Remove a network interface from the list of lwIP netifs. * * @param netif the network interface to remove */ void netif_remove(struct netif *netif) { if (netif == NULL) { return; } #if LWIP_IGMP /* stop IGMP processing */ if (netif->flags & NETIF_FLAG_IGMP) { igmp_stop(netif); } #endif /* LWIP_IGMP */ #if LWIP_IPV6 && LWIP_IPV6_MLD /* stop MLD processing */ mld6_stop(netif); #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */ if (netif_is_up(netif)) { /* set netif down before removing (call callback function) */ netif_set_down(netif); } snmp_delete_ipaddridx_tree(netif); /* is it the first netif? */ if (netif_list == netif) { netif_list = netif->next; } else { /* look for netif further down the list */ struct netif * tmpNetif; for (tmpNetif = netif_list; tmpNetif != NULL; tmpNetif = tmpNetif->next) { if (tmpNetif->next == netif) { tmpNetif->next = netif->next; break; } } if (tmpNetif == NULL) return; /* we didn't find any netif today */ } snmp_dec_iflist(); /* this netif is default? */ if (netif_default == netif) { /* reset default netif */ netif_set_default(NULL); } #if LWIP_NETIF_REMOVE_CALLBACK if (netif->remove_callback) { netif->remove_callback(netif); } #endif /* LWIP_NETIF_REMOVE_CALLBACK */ LWIP_DEBUGF( NETIF_DEBUG, ("netif_remove: removed netif\n") ); }
/** * \brief Status callback used to print address given by DHCP. * * \param netif Instance to network interface. */ void status_callback(struct netif *netif) { if (netif_is_up(netif)) { TRACE_DEBUG("Network up"); TRACE_DEBUG("IP="); strcat((char*)g_c_ipconfig, inet_ntoa(*(struct in_addr *)&(netif->ip_addr))); TRACE_DEBUG((char const*)g_c_ipconfig); g_ip_mode = 3; } else { printf("Network down"); } }
static void status_callback(struct netif *state_netif) { if (netif_is_up(state_netif)) { #if LWIP_IPV4 printf("status_callback==UP, local interface IP is %s\n", ip4addr_ntoa(netif_ip4_addr(state_netif))); #else printf("status_callback==UP\n"); #endif } else { printf("status_callback==DOWN\n"); } }
/** * @brief Notify the User about the nework interface config status * @param netif: the network interface * @retval None */ void User_notification(struct netif *netif) { if (netif_is_up(netif)) { /* Turn On LED 1 to indicate ETH and LwIP init success*/ BSP_LED_On(LED1); } else { /* Turn On LED 2 to indicate ETH and LwIP init error */ BSP_LED_On(LED2); } }
/** * \brief Status callback used to print address given by DHCP. * * \param netif Instance to network interface. */ void status_callback(struct netif *netif) { int8_t c_mess[25]; if (netif_is_up(netif)) { // printf("Network up\r\n"); // strcpy((char*)c_mess, "IP="); // strcat((char*)c_mess, inet_ntoa(*(struct in_addr *)&(netif->ip_addr))); // printf((char const*)c_mess); // printf("-----------------\r\n"); netif->flags |=NETIF_FLAG_LINK_UP; } else { // printf("Network down\r\n"); } }
static void ip_status_cb(struct netif* netif) { INFO_INIT("IP status cb...\n"); if (netif_is_up(netif)) { set_result_cmd(WL_SUCCESS); printk("bound to %s\n", ip2str(netif->ip_addr)); ifStatus = true; }else{ ifStatus = false; closeConnections(); WARN("Interface not up!\n"); } }
/** * @brief Notify the User about the nework interface config status * @param netif: the network interface * @retval None */ void User_notification(struct netif *netif) { if (netif_is_up(netif)) { /* Turn On LED 1 to indicate ETH and LwIP init success*/ //BSP_LED_On(LED1); HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, GPIO_PIN_SET); } else { /* Turn On LED 2 to indicate ETH and LwIP init error */ //BSP_LED_On(LED2); HAL_GPIO_WritePin(GPIOG, GPIO_PIN_8, GPIO_PIN_SET); } }
const ip_addr_t *LWIP::get_ipv6_addr(const struct netif *netif) { if (!netif_is_up(netif)) { return NULL; } for (int i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { if (ip6_addr_isvalid(netif_ip6_addr_state(netif, i)) && !ip6_addr_islinklocal(netif_ip6_addr(netif, i))) { return netif_ip_addr6(netif, i); } } return NULL; }
/** * Finds the appropriate network interface for a given IP address. It * searches the list of network interfaces linearly. A match is found * if the masked IP address of the network interface equals the masked * IP address given to the function. * * @param dest the destination IP address for which to find the route * @return the netif on which to send to reach dest */ struct netif * ip_route(struct ip_addr *dest) { struct netif *netif; /* iterate through netifs */ for(netif = netif_list; netif != NULL; netif = netif->next) { /* network mask matches? */ if (netif_is_up(netif)) { if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) { /* return netif on which to forward IP packet */ return netif; } } } if ((netif_default == NULL) || (!netif_is_up(netif_default))) { LWIP_DEBUGF(IP_DEBUG | 2, ("ip_route: No route to 0x%"X32_F"\n", dest->addr)); IP_STATS_INC(ip.rterr); snmp_inc_ipoutnoroutes(); return NULL; } /* no matching netif found, use default netif */ return netif_default; }