/** * Change the default gateway for a network interface * * @param netif the network interface to change * @param gw the new default gateway * * @note call netif_set_addr() if you also want to change ip address and netmask */ void netif_set_gw(struct netif *netif, const ip4_addr_t *gw) { ip4_addr_set(ip_2_ip4(&netif->gw), gw); IP_SET_TYPE_VAL(netif->gw, IPADDR_TYPE_V4); LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("netif: GW address of interface %c%c set to %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", netif->name[0], netif->name[1], ip4_addr1_16(netif_ip4_gw(netif)), ip4_addr2_16(netif_ip4_gw(netif)), ip4_addr3_16(netif_ip4_gw(netif)), ip4_addr4_16(netif_ip4_gw(netif)))); }
char *LWIP::Interface::get_gateway(char *buf, nsapi_size_t buflen) { #if LWIP_IPV4 const ip4_addr_t *addr = netif_ip4_gw(&netif); if (!ip4_addr_isany(addr)) { return ip4addr_ntoa_r(addr, buf, buflen); } else { return NULL; } #else return NULL; #endif }
static void netif_status_callback(struct netif *nif) { printf("NETIF: %c%c%d is %s\n", nif->name[0], nif->name[1], nif->num, netif_is_up(nif) ? "UP" : "DOWN"); #if LWIP_IPV4 printf("IPV4: Host at %s ", ip4addr_ntoa(netif_ip4_addr(nif))); printf("mask %s ", ip4addr_ntoa(netif_ip4_netmask(nif))); printf("gateway %s\n", ip4addr_ntoa(netif_ip4_gw(nif))); #endif /* LWIP_IPV4 */ #if LWIP_IPV6 printf("IPV6: Host at %s\n", ip6addr_ntoa(netif_ip6_addr(nif, 0))); #endif /* LWIP_IPV6 */ #if LWIP_NETIF_HOSTNAME printf("FQDN: %s\n", netif_get_hostname(nif)); #endif /* LWIP_NETIF_HOSTNAME */ }
/*-----------------------------------------------------------------------------------*/ err_t delif_init_thread(struct netif *netif) { struct delif *del; LWIP_DEBUGF(DELIF_DEBUG, ("delif_init_thread\n")); del = (struct delif*)malloc(sizeof(struct delif)); if (!del) { return ERR_MEM; } netif->state = del; netif->name[0] = 'd'; netif->name[1] = 'e'; del->netif = (struct netif*)malloc(sizeof(struct netif)); if (!del->netif) { free(del); return ERR_MEM; } #if LWIP_IPV4 netif->output = delif_output4; netif_set_addr(del->netif, netif_ip4_addr(netif), netif_ip4_netmask(netif), netif_ip4_gw(netif)); #endif /* LWIP_IPV4 */ #if LWIP_IPV6 { s8_t i; netif->output_ip6 = delif_output6; for(i=0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { netif_ip6_addr_set(del->netif, i, netif_ip6_addr(netif, i)); } } #endif /* LWIP_IPV6 */ del->input = netif->input; del->netif->input = delif_input; sys_thread_new("delif_thread", delif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); return ERR_OK; }
static snmp_err_t ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) { switch (*column) { case 1: /* ipRouteDest */ if (default_route) { /* default rte has 0.0.0.0 dest */ value->u32 = IP4_ADDR_ANY4->addr; } else { /* netifs have netaddress dest */ ip4_addr_t tmp; ip4_addr_get_network(&tmp, netif_ip4_addr(netif), netif_ip4_netmask(netif)); value->u32 = tmp.addr; } break; case 2: /* ipRouteIfIndex */ value->u32 = netif_to_num(netif); break; case 3: /* ipRouteMetric1 */ if (default_route) { value->s32 = 1; /* default */ } else { value->s32 = 0; /* normal */ } break; case 4: /* ipRouteMetric2 */ case 5: /* ipRouteMetric3 */ case 6: /* ipRouteMetric4 */ value->s32 = -1; /* none */ break; case 7: /* ipRouteNextHop */ if (default_route) { /* default rte: gateway */ value->u32 = netif_ip4_gw(netif)->addr; } else { /* other rtes: netif ip_addr */ value->u32 = netif_ip4_addr(netif)->addr; } break; case 8: /* ipRouteType */ if (default_route) { /* default rte is indirect */ value->u32 = 4; /* indirect */ } else { /* other rtes are direct */ value->u32 = 3; /* direct */ } break; case 9: /* ipRouteProto */ /* locally defined routes */ value->u32 = 2; /* local */ break; case 10: /* ipRouteAge */ /* @todo (sysuptime - timestamp last change) / 100 */ value->u32 = 0; break; case 11: /* ipRouteMask */ if (default_route) { /* default rte use 0.0.0.0 mask */ value->u32 = IP4_ADDR_ANY4->addr; } else { /* other rtes use netmask */ value->u32 = netif_ip4_netmask(netif)->addr; } break; case 12: /* ipRouteMetric5 */ value->s32 = -1; /* none */ break; case 13: /* ipRouteInfo */ value->const_ptr = snmp_zero_dot_zero.id; *value_len = snmp_zero_dot_zero.len * sizeof(u32_t); break; default: return SNMP_ERR_NOSUCHINSTANCE; } return SNMP_ERR_NOERROR; }
static void ppp_link_status_cb(ppp_pcb *pcb, int err_code, void *ctx) { struct netif *pppif = ppp_netif(pcb); LWIP_UNUSED_ARG(ctx); switch(err_code) { case PPPERR_NONE: /* No error. */ { #if LWIP_DNS ip_addr_t ns; #endif /* LWIP_DNS */ fprintf(stderr, "ppp_link_status_cb: PPPERR_NONE\n\r"); #if LWIP_IPV4 fprintf(stderr, " our_ip4addr = %s\n\r", ip4addr_ntoa(netif_ip4_addr(pppif))); fprintf(stderr, " his_ipaddr = %s\n\r", ip4addr_ntoa(netif_ip4_gw(pppif))); fprintf(stderr, " netmask = %s\n\r", ip4addr_ntoa(netif_ip4_netmask(pppif))); #endif /* LWIP_IPV4 */ #if LWIP_IPV6 fprintf(stderr, " our_ip6addr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0))); #endif /* LWIP_IPV6 */ #if LWIP_DNS ns = dns_getserver(0); fprintf(stderr, " dns1 = %s\n\r", ipaddr_ntoa(&ns)); ns = dns_getserver(1); fprintf(stderr, " dns2 = %s\n\r", ipaddr_ntoa(&ns)); #endif /* LWIP_DNS */ #if PPP_IPV6_SUPPORT fprintf(stderr, " our6_ipaddr = %s\n\r", ip6addr_ntoa(netif_ip6_addr(pppif, 0))); #endif /* PPP_IPV6_SUPPORT */ } break; case PPPERR_PARAM: /* Invalid parameter. */ printf("ppp_link_status_cb: PPPERR_PARAM\n"); break; case PPPERR_OPEN: /* Unable to open PPP session. */ printf("ppp_link_status_cb: PPPERR_OPEN\n"); break; case PPPERR_DEVICE: /* Invalid I/O device for PPP. */ printf("ppp_link_status_cb: PPPERR_DEVICE\n"); break; case PPPERR_ALLOC: /* Unable to allocate resources. */ printf("ppp_link_status_cb: PPPERR_ALLOC\n"); break; case PPPERR_USER: /* User interrupt. */ printf("ppp_link_status_cb: PPPERR_USER\n"); break; case PPPERR_CONNECT: /* Connection lost. */ printf("ppp_link_status_cb: PPPERR_CONNECT\n"); break; case PPPERR_AUTHFAIL: /* Failed authentication challenge. */ printf("ppp_link_status_cb: PPPERR_AUTHFAIL\n"); break; case PPPERR_PROTOCOL: /* Failed to meet protocol. */ printf("ppp_link_status_cb: PPPERR_PROTOCOL\n"); break; case PPPERR_PEERDEAD: /* Connection timeout. */ printf("ppp_link_status_cb: PPPERR_PEERDEAD\n"); break; case PPPERR_IDLETIMEOUT: /* Idle Timeout. */ printf("ppp_link_status_cb: PPPERR_IDLETIMEOUT\n"); break; case PPPERR_CONNECTTIME: /* PPPERR_CONNECTTIME. */ printf("ppp_link_status_cb: PPPERR_CONNECTTIME\n"); break; case PPPERR_LOOPBACK: /* Connection timeout. */ printf("ppp_link_status_cb: PPPERR_LOOPBACK\n"); break; default: printf("ppp_link_status_cb: unknown errCode %d\n", err_code); break; } }
static void pppLinkStatusCallback(ppp_pcb *pcb, int errCode, void *ctx) { struct netif *pppif = ppp_netif(pcb); LWIP_UNUSED_ARG(ctx); switch(errCode) { case PPPERR_NONE: { /* No error. */ printf("pppLinkStatusCallback: PPPERR_NONE\n"); #if LWIP_IPV4 printf(" our_ipaddr = %s\n", ip4addr_ntoa(netif_ip4_addr(pppif))); printf(" his_ipaddr = %s\n", ip4addr_ntoa(netif_ip4_gw(pppif))); printf(" netmask = %s\n", ip4addr_ntoa(netif_ip4_netmask(pppif))); #endif /* LWIP_IPV4 */ #if LWIP_DNS printf(" dns1 = %s\n", ipaddr_ntoa(dns_getserver(0))); printf(" dns2 = %s\n", ipaddr_ntoa(dns_getserver(1))); #endif /* LWIP_DNS */ #if PPP_IPV6_SUPPORT printf(" our6_ipaddr = %s\n", ip6addr_ntoa(netif_ip6_addr(pppif, 0))); #endif /* PPP_IPV6_SUPPORT */ break; } case PPPERR_PARAM: { /* Invalid parameter. */ printf("pppLinkStatusCallback: PPPERR_PARAM\n"); break; } case PPPERR_OPEN: { /* Unable to open PPP session. */ printf("pppLinkStatusCallback: PPPERR_OPEN\n"); break; } case PPPERR_DEVICE: { /* Invalid I/O device for PPP. */ printf("pppLinkStatusCallback: PPPERR_DEVICE\n"); break; } case PPPERR_ALLOC: { /* Unable to allocate resources. */ printf("pppLinkStatusCallback: PPPERR_ALLOC\n"); break; } case PPPERR_USER: { /* User interrupt. */ printf("pppLinkStatusCallback: PPPERR_USER\n"); break; } case PPPERR_CONNECT: { /* Connection lost. */ printf("pppLinkStatusCallback: PPPERR_CONNECT\n"); break; } case PPPERR_AUTHFAIL: { /* Failed authentication challenge. */ printf("pppLinkStatusCallback: PPPERR_AUTHFAIL\n"); break; } case PPPERR_PROTOCOL: { /* Failed to meet protocol. */ printf("pppLinkStatusCallback: PPPERR_PROTOCOL\n"); break; } case PPPERR_PEERDEAD: { /* Connection timeout */ printf("pppLinkStatusCallback: PPPERR_PEERDEAD\n"); break; } case PPPERR_IDLETIMEOUT: { /* Idle Timeout */ printf("pppLinkStatusCallback: PPPERR_IDLETIMEOUT\n"); break; } case PPPERR_CONNECTTIME: { /* Max connect time reached */ printf("pppLinkStatusCallback: PPPERR_CONNECTTIME\n"); break; } case PPPERR_LOOPBACK: { /* Loopback detected */ printf("pppLinkStatusCallback: PPPERR_LOOPBACK\n"); break; } default: { printf("pppLinkStatusCallback: unknown errCode %d\n", errCode); break; } } }