HRESULT LWIP_SOCKETS_Driver::LoadAdapterConfiguration( UINT32 interfaceIndex, SOCK_NetworkConfiguration* config ) { NATIVE_PROFILE_PAL_NETWORK(); if(interfaceIndex >= NETWORK_INTERFACE_COUNT) { return CLR_E_INVALID_PARAMETER; } memcpy(config, &g_NetworkConfig.NetworkInterfaces[interfaceIndex], sizeof(g_NetworkConfig.NetworkInterfaces[interfaceIndex])); if(config->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP) { struct netif *pNetIf; if (pNetIf = netif_find_interface(g_LWIP_SOCKETS_Driver.m_interfaces[interfaceIndex].m_interfaceNumber)) { config->ipaddr = pNetIf->ip_addr.addr; config->subnetmask = pNetIf->netmask.addr; config->gateway = pNetIf->gw.addr; #if LWIP_DNS config->dnsServer1 = dns_getserver(0).addr; config->dnsServer2 = dns_getserver(1).addr; #endif } else { config->ipaddr = 0; config->subnetmask = 0; config->gateway = 0; } } return S_OK; }
/** * Get the DNS ip address. * @param dns_no * @return IPAddress DNS Server IP */ IPAddress ESP8266WiFiSTAClass::dnsIP(uint8_t dns_no) { #if LWIP_VERSION_MAJOR == 1 ip_addr_t dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip.addr); #else return IPAddress(dns_getserver(dns_no)); #endif }
/** * @brief PPP status callback which is called on PPP status change (up, down, …) by lwIP core thread * * @param pcb PPP control block * @param err_code Error code * @param ctx Context of callback */ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx) { struct netif *pppif = ppp_netif(pcb); modem_dte_t *dte = (modem_dte_t *)(ctx); esp_modem_dte_t *esp_dte = __containerof(dte, esp_modem_dte_t, parent); ppp_client_ip_info_t ipinfo = {0}; switch (err_code) { case PPPERR_NONE: /* Connected */ ipinfo.ip = pppif->ip_addr.u_addr.ip4; ipinfo.gw = pppif->gw.u_addr.ip4; ipinfo.netmask = pppif->netmask.u_addr.ip4; ipinfo.ns1 = dns_getserver(0).u_addr.ip4; ipinfo.ns2 = dns_getserver(1).u_addr.ip4; esp_event_post_to(esp_dte->event_loop_hdl, ESP_MODEM_EVENT, MODEM_EVENT_PPP_CONNECT, &ipinfo, sizeof(ipinfo), 0); break; case PPPERR_PARAM: ESP_LOGE(MODEM_TAG, "Invalid parameter"); break; case PPPERR_OPEN: ESP_LOGE(MODEM_TAG, "Unable to open PPP session"); break; case PPPERR_DEVICE: ESP_LOGE(MODEM_TAG, "Invalid I/O device for PPP"); break; case PPPERR_ALLOC: ESP_LOGE(MODEM_TAG, "Unable to allocate resources"); break; case PPPERR_USER: /* User interrupt */ esp_event_post_to(esp_dte->event_loop_hdl, ESP_MODEM_EVENT, MODEM_EVENT_PPP_STOP, NULL, 0, 0); /* Free the PPP control block */ pppapi_free(esp_dte->ppp); break; case PPPERR_CONNECT: /* Connection lost */ esp_event_post_to(esp_dte->event_loop_hdl, ESP_MODEM_EVENT, MODEM_EVENT_PPP_DISCONNECT, NULL, 0, 0); break; case PPPERR_AUTHFAIL: ESP_LOGE(MODEM_TAG, "Failed authentication challenge"); break; case PPPERR_PROTOCOL: ESP_LOGE(MODEM_TAG, "Failed to meet protocol"); break; case PPPERR_PEERDEAD: ESP_LOGE(MODEM_TAG, "Connection timeout"); break; case PPPERR_IDLETIMEOUT: ESP_LOGE(MODEM_TAG, "Idle Timeout"); break; case PPPERR_CONNECTTIME: ESP_LOGE(MODEM_TAG, "Max connect time reached"); break; case PPPERR_LOOPBACK: ESP_LOGE(MODEM_TAG, "Loopback detected"); break; default: ESP_LOGE(MODEM_TAG, "Unknown error code %d", err_code); break; } }
struct tls_ethif * tls_netif_get_ethif(void) { ip_addr_t dns1,dns2; MEMCPY((char *)ðif->ip_addr.addr, &nif->ip_addr.addr, 4); MEMCPY((char *)ðif->netmask.addr, &nif->netmask.addr, 4); MEMCPY((char *)ðif->gw.addr, &nif->gw.addr, 4); dns1 = dns_getserver(0); MEMCPY(ðif->dns1.addr, (char *)&dns1.addr, 4); dns2 = dns_getserver(1); MEMCPY(ðif->dns2.addr, (char *)&dns2.addr, 4); ethif->status = nif->flags&NETIF_FLAG_UP; return ethif; }
void list_if() { rt_ubase_t index; rt_kprintf("Default network interface: %c%c\n", netif_default->name[0], netif_default->name[1]); rt_kprintf("MTU: %d\n", netif_default->mtu); rt_kprintf("MAC: "); for (index = 0; index < netif_default->hwaddr_len; index ++) rt_kprintf("%02x ", netif_default->hwaddr[index]); rt_kprintf("\nFLAGS:"); if (netif_default->flags & NETIF_FLAG_UP) rt_kprintf(" UP"); else rt_kprintf(" DOWN"); if (netif_default->flags & NETIF_FLAG_LINK_UP) rt_kprintf(" LINK_UP"); else rt_kprintf(" LINK_DOWN"); if (netif_default->flags & NETIF_FLAG_DHCP) rt_kprintf(" DHCP"); if (netif_default->flags & NETIF_FLAG_POINTTOPOINT) rt_kprintf(" PPP"); if (netif_default->flags & NETIF_FLAG_ETHARP) rt_kprintf(" ETHARP"); if (netif_default->flags & NETIF_FLAG_IGMP) rt_kprintf(" IGMP"); rt_kprintf("\n"); rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->ip_addr)))); rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->gw)))); rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->netmask)))); #if LWIP_DNS { struct ip_addr ip_addr; ip_addr = dns_getserver(0); rt_kprintf("dns server: %s\n", inet_ntoa(*((struct in_addr*)&(ip_addr)))); } #endif }
/********************************************************************************************************* ** 函数名称: __netIfShowAll ** 功能描述: 显示所有网络接口信息 (ip v4) ** 输 入 : NONE ** 输 出 : NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ static VOID __netIfShowAll (VOID) { struct netif *netif = netif_list; INT iCounter = 0; INT i; CHAR cName[5] = "null"; /* 当前默认路由网络接口名 */ for (; netif != LW_NULL; netif = netif->next) { __netIfShow(LW_NULL, netif); iCounter++; } #if LWIP_DNS > 0 for (i = 0; i < DNS_MAX_SERVERS; i++) { ip_addr_t ipaddr = dns_getserver((u8_t)i); printf("dns%d: %d.%d.%d.%d\n", (i), ip4_addr1(&ipaddr), ip4_addr2(&ipaddr), ip4_addr3(&ipaddr), ip4_addr4(&ipaddr)); } #endif /* LWIP_DNS */ if (netif_default) { cName[0] = netif_default->name[0]; cName[1] = netif_default->name[1]; cName[2] = (CHAR)(netif_default->num + '0'); cName[3] = PX_EOS; } printf("default device is: %s\n", cName); /* 显示路由端口 */ printf("total net interface: %d\n", iCounter); }
void add_dns_addr(struct netif *lwip_netif) { const ip_addr_t *ip_addr = mbed_lwip_get_ip_addr(true, lwip_netif); if (ip_addr) { if (IP_IS_V6(ip_addr)) { const ip_addr_t *dns_ip_addr; bool dns_addr_exists = false; for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) { dns_ip_addr = dns_getserver(numdns); if (!ip_addr_isany(dns_ip_addr)) { dns_addr_exists = true; break; } } if (!dns_addr_exists) { /* 2001:4860:4860::8888 google */ ip_addr_t ipv6_dns_addr = IPADDR6_INIT( PP_HTONL(0x20014860UL), PP_HTONL(0x48600000UL), PP_HTONL(0x00000000UL), PP_HTONL(0x00008888UL)); dns_setserver(0, &ipv6_dns_addr); } } } }
STATIC mp_obj_t ppp_ifconfig(size_t n_args, const mp_obj_t *args) { ppp_if_obj_t *self = MP_OBJ_TO_PTR(args[0]); ip_addr_t dns; if (n_args == 1) { // get if (self->pcb != NULL) { dns = dns_getserver(0); struct netif *pppif = ppp_netif(self->pcb); mp_obj_t tuple[4] = { netutils_format_ipv4_addr((uint8_t*)&pppif->ip_addr, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)&pppif->gw, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)&pppif->netmask, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)&dns, NETUTILS_BIG), }; return mp_obj_new_tuple(4, tuple); } else { mp_obj_t tuple[4] = { mp_const_none, mp_const_none, mp_const_none, mp_const_none }; return mp_obj_new_tuple(4, tuple); } } else { mp_obj_t *items; mp_obj_get_array_fixed_n(args[1], 4, &items); netutils_parse_ipv4_addr(items[3], (uint8_t*)&dns.u_addr.ip4, NETUTILS_BIG); dns_setserver(0, &dns); return mp_const_none; } }
/* numdns 0/1 --> dns 1/2 */ void tls_dhcps_setdns(u8_t numdns) { ip_addr_t dns; dns = dns_getserver(numdns); DHCPS_SetDns(numdns, dns.addr); return; }
void enc28j60_status_callback(struct netif *netif) { if(LwipLastIpAddress != netif->ip_addr.addr) { Network_PostEvent( NETWORK_EVENT_TYPE_ADDRESS_CHANGED, 0 ); LwipLastIpAddress = netif->ip_addr.addr; } #if !defined(BUILD_RTM) lcd_printf("\f\n\n\n\n\n\nLink Update: %s\n", (netif_is_up(netif) ? "UP " : "DOWN") ); lcd_printf(" IP: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); lcd_printf(" SM: %d.%d.%d.%d\n", (netif->netmask.addr >> 0) & 0xFF, (netif->netmask.addr >> 8) & 0xFF, (netif->netmask.addr >> 16) & 0xFF, (netif->netmask.addr >> 24) & 0xFF); lcd_printf(" GW: %d.%d.%d.%d\n", (netif->gw.addr >> 0) & 0xFF, (netif->gw.addr >> 8) & 0xFF, (netif->gw.addr >> 16) & 0xFF, (netif->gw.addr >> 24) & 0xFF); debug_printf("IP Address: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); #if LWIP_DNS if(netif->flags & NETIF_FLAG_DHCP) { struct ip_addr dns1 = dns_getserver(0); struct ip_addr dns2 = dns_getserver(1); lcd_printf(" dns1: %d.%d.%d.%d\n",(dns1.addr >> 0) & 0xFF, (dns1.addr >> 8) & 0xFF, (dns1.addr >> 16) & 0xFF, (dns1.addr >> 24) & 0xFF); lcd_printf(" dns2: %d.%d.%d.%d\n",(dns2.addr >> 0) & 0xFF, (dns2.addr >> 8) & 0xFF, (dns2.addr >> 16) & 0xFF, (dns2.addr >> 24) & 0xFF); } #endif #endif }
void LWIP_SOCKETS_Driver::Status_callback(struct netif *netif) { if (!PostAddressChangedContinuation.IsLinked()) PostAddressChangedContinuation.Enqueue(); #if !defined(BUILD_RTM) lcd_printf("\f\n\n\n\n\n\nLink Update: %s\n", (netif_is_up(netif) ? "UP " : "DOWN")); lcd_printf(" IP: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); lcd_printf(" SM: %d.%d.%d.%d\n", (netif->netmask.addr >> 0) & 0xFF, (netif->netmask.addr >> 8) & 0xFF, (netif->netmask.addr >> 16) & 0xFF, (netif->netmask.addr >> 24) & 0xFF); lcd_printf(" GW: %d.%d.%d.%d\n", (netif->gw.addr >> 0) & 0xFF, (netif->gw.addr >> 8) & 0xFF, (netif->gw.addr >> 16) & 0xFF, (netif->gw.addr >> 24) & 0xFF); debug_printf("IP Address: %d.%d.%d.%d\n", (netif->ip_addr.addr >> 0) & 0xFF, (netif->ip_addr.addr >> 8) & 0xFF, (netif->ip_addr.addr >> 16) & 0xFF, (netif->ip_addr.addr >> 24) & 0xFF); #if LWIP_DNS if (netif->flags & NETIF_FLAG_DHCP) { struct ip_addr dns1 = dns_getserver(0); struct ip_addr dns2 = dns_getserver(1); lcd_printf(" dns1: %d.%d.%d.%d\n", (dns1.addr >> 0) & 0xFF, (dns1.addr >> 8) & 0xFF, (dns1.addr >> 16) & 0xFF, (dns1.addr >> 24) & 0xFF); lcd_printf(" dns2: %d.%d.%d.%d\n", (dns2.addr >> 0) & 0xFF, (dns2.addr >> 8) & 0xFF, (dns2.addr >> 16) & 0xFF, (dns2.addr >> 24) & 0xFF); } #endif #endif Events_Set(SYSTEM_EVENT_FLAG_SOCKET); Events_Set(SYSTEM_EVENT_FLAG_NETWORK); }
static void netif_status_callback(struct netif *netif) { cbIP_IPv4Settings ipV4Settings; cbIP_IPv6Settings ipV6Settings; ipV4Settings.address.value = netif->ip_addr.addr; ipV4Settings.netmask.value = netif->netmask.addr; ipV4Settings.gateway.value = netif->gw.addr; ipV4Settings.dns0.value = dns_getserver(0).addr; ipV4Settings.dns1.value = dns_getserver(1).addr; memcpy(&ipV6Settings.linklocal.value, netif->ip6_addr[0].addr, sizeof (cbIP_IPv6Address)); if (netif->flags & NETIF_FLAG_UP) { panIf.statusCallback(cbIP_NETWORK_UP, panIf.callbackArg, &ipV4Settings, &ipV6Settings); } else { panIf.statusCallback(cbIP_NETWORK_DOWN, panIf.callbackArg, &ipV4Settings, &ipV6Settings); } }
void list_if(void) { rt_ubase_t index; struct netif * netif; rt_enter_critical(); netif = netif_list; while( netif != NULL ) { printf("network interface: %c%c%s\n", netif->name[0], netif->name[1], (netif == netif_default)?" (Default)":""); printf("MTU: %d\n", netif->mtu); printf("MAC: "); for (index = 0; index < netif->hwaddr_len; index ++) printf("%02x ", netif->hwaddr[index]); printf("\nFLAGS:"); if (netif->flags & NETIF_FLAG_UP) printf(" UP"); else printf(" DOWN"); if (netif->flags & NETIF_FLAG_LINK_UP) printf(" LINK_UP"); else printf(" LINK_DOWN"); if (netif->flags & NETIF_FLAG_DHCP) printf(" DHCP"); if (netif->flags & NETIF_FLAG_POINTTOPOINT) printf(" PPP"); if (netif->flags & NETIF_FLAG_ETHARP) printf(" ETHARP"); if (netif->flags & NETIF_FLAG_IGMP) printf(" IGMP"); printf("\n"); printf("ip address: %s\n", ipaddr_ntoa(&(netif->ip_addr))); printf("gw address: %s\n", ipaddr_ntoa(&(netif->gw))); printf("net mask : %s\n", ipaddr_ntoa(&(netif->netmask))); printf("\r\n"); netif = netif->next; } #if LWIP_DNS { struct ip_addr ip_addr; for(index=0; index<DNS_MAX_SERVERS; index++) { ip_addr = dns_getserver(index); printf("dns server #%d: %s\n", index, ipaddr_ntoa(&(ip_addr))); } } #endif /**< #if LWIP_DNS */ rt_exit_critical(); }
static nsapi_error_t mbed_lwip_add_dns_server(nsapi_stack_t *stack, nsapi_addr_t addr) { // Shift all dns servers down to give precedence to new server for (int i = DNS_MAX_SERVERS-1; i > 0; i--) { dns_setserver(i, dns_getserver(i-1)); } ip_addr_t ip_addr; if (!convert_mbed_addr_to_lwip(&ip_addr, &addr)) { return NSAPI_ERROR_PARAMETER; } dns_setserver(0, &ip_addr); return 0; }
void LWIP::add_dns_addr(struct netif *lwip_netif) { // Check for existing dns address for (char numdns = 0; numdns < DNS_MAX_SERVERS; numdns++) { const ip_addr_t *dns_ip_addr = dns_getserver(numdns); if (!ip_addr_isany(dns_ip_addr)) { return; } } // Get preferred ip version const ip_addr_t *ip_addr = get_ip_addr(false, lwip_netif); u8_t addr_type = IPADDR_TYPE_ANY; // Add preferred ip version dns address to index 0 if (ip_addr) { addr_type = get_ip_addr_type(ip_addr); add_dns_addr_to_dns_list_index(addr_type, 0); } #if LWIP_IPV4 && LWIP_IPV6 if (!ip_addr) { // Get address for any ip version ip_addr = get_ip_addr(true, lwip_netif); if (!ip_addr) { return; } addr_type = get_ip_addr_type(ip_addr); // Add the dns address to index 0 add_dns_addr_to_dns_list_index(addr_type, 0); } if (addr_type == IPADDR_TYPE_V4) { // If ipv4 is preferred and ipv6 is available add ipv6 dns address to index 1 ip_addr = get_ipv6_addr(lwip_netif); } else if (addr_type == IPADDR_TYPE_V6) { // If ipv6 is preferred and ipv4 is available add ipv4 dns address to index 1 ip_addr = get_ipv4_addr(lwip_netif); } else { ip_addr = NULL; } if (ip_addr) { addr_type = get_ip_addr_type(ip_addr); add_dns_addr_to_dns_list_index(addr_type, 1); } #endif }
void list_if() { rt_kprintf("Default network interface: %c%c\n", netif_default->name[0], netif_default->name[1]); rt_kprintf("ip address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->ip_addr)))); rt_kprintf("gw address: %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->gw)))); rt_kprintf("net mask : %s\n", inet_ntoa(*((struct in_addr*)&(netif_default->netmask)))); #if LWIP_DNS { struct ip_addr ip_addr; ip_addr = dns_getserver(0); rt_kprintf("dns server: %s\n", inet_ntoa(*((struct in_addr*)&(ip_addr)))); } #endif }
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // Get IP addresses const ip_addr_t *dns = dns_getserver(0); mp_obj_t tuple[4] = { netutils_format_ipv4_addr((uint8_t*)&netif->ip_addr, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)&netif->netmask, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)&netif->gw, NETUTILS_BIG), netutils_format_ipv4_addr((uint8_t*)dns, NETUTILS_BIG), }; return mp_obj_new_tuple(4, tuple); } else if (args[0] == MP_OBJ_NEW_QSTR(MP_QSTR_dhcp)) { // Start the DHCP client if (dhcp_supplied_address(netif)) { dhcp_renew(netif); } else { dhcp_stop(netif); dhcp_start(netif); } // Wait for DHCP to get IP address uint32_t start = mp_hal_ticks_ms(); while (!dhcp_supplied_address(netif)) { if (mp_hal_ticks_ms() - start > 10000) { mp_raise_msg(&mp_type_OSError, "timeout waiting for DHCP to get IP address"); } mp_hal_delay_ms(100); } return mp_const_none; } else { // Release and stop any existing DHCP dhcp_release(netif); dhcp_stop(netif); // Set static IP addresses mp_obj_t *items; mp_obj_get_array_fixed_n(args[0], 4, &items); netutils_parse_ipv4_addr(items[0], (uint8_t*)&netif->ip_addr, NETUTILS_BIG); netutils_parse_ipv4_addr(items[1], (uint8_t*)&netif->netmask, NETUTILS_BIG); netutils_parse_ipv4_addr(items[2], (uint8_t*)&netif->gw, NETUTILS_BIG); ip_addr_t dns; netutils_parse_ipv4_addr(items[3], (uint8_t*)&dns, NETUTILS_BIG); dns_setserver(0, &dns); return mp_const_none; } }
nsapi_error_t LWIP::get_dns_server(int index, SocketAddress *address, const char *interface_name) { int dns_entries = 0; for (int i = 0; i < DNS_MAX_SERVERS; i++) { const ip_addr_t *ip_addr = dns_getserver(i, interface_name); if (!ip_addr_isany(ip_addr)) { if (index == dns_entries) { nsapi_addr_t addr; convert_lwip_addr_to_mbed(&addr, ip_addr); address->set_addr(addr); return NSAPI_ERROR_OK; } dns_entries++; } } return NSAPI_ERROR_NO_ADDRESS; }
// Lua: s = net.dns.getdnsserver([index]) static int net_getdnsserver( lua_State* L ) { int numdns = luaL_optint(L, 1, 0); if (numdns >= DNS_MAX_SERVERS) return luaL_error( L, "server index out of range [0-%d]", DNS_MAX_SERVERS - 1); ip_addr_t ipaddr; dns_getserver(numdns,&ipaddr); if ( ip_addr_isany(&ipaddr) ) { lua_pushnil( L ); } else { char temp[20] = {0}; c_sprintf(temp, IPSTR, IP2STR( &ipaddr ) ); lua_pushstring( L, temp ); } return 1; }
// Lua: s = net.dns.getdnsserver([index]) static int net_getdnsserver( lua_State* L ) { int numdns = luaL_optint(L, 1, 0); if (numdns >= DNS_MAX_SERVERS) return luaL_error( L, "server index out of range [0-%d]", DNS_MAX_SERVERS - 1); // ip_addr_t ipaddr; // dns_getserver(numdns,&ipaddr); // Bug fix by @md5crypt https://github.com/nodemcu/nodemcu-firmware/pull/500 ip_addr_t ipaddr = dns_getserver(numdns); if ( ip_addr_isany(&ipaddr) ) { lua_pushnil( L ); } else { char temp[20] = {0}; c_sprintf(temp, IPSTR, IP2STR( &ipaddr.addr ) ); lua_pushstring( L, temp ); } return 1; }
int ethApplyIPConfig(void) { t_ip_info ip_info; struct ip_addr ipaddr, netmask, gw, dns, dns_curr; int result; if((result = ps2ip_getconfig("sm0", &ip_info)) >= 0) { IP4_ADDR(&ipaddr, ps2_ip[0], ps2_ip[1], ps2_ip[2], ps2_ip[3]); IP4_ADDR(&netmask, ps2_netmask[0], ps2_netmask[1], ps2_netmask[2], ps2_netmask[3]); IP4_ADDR(&gw, ps2_gateway[0], ps2_gateway[1], ps2_gateway[2], ps2_gateway[3]); IP4_ADDR(&dns, ps2_dns[0], ps2_dns[1], ps2_dns[2], ps2_dns[3]); dns_curr = dns_getserver(0); //Check if it's the same. Otherwise, apply the new configuration. if((ps2_ip_use_dhcp != ip_info.dhcp_enabled) || (!ps2_ip_use_dhcp && (!ip_addr_cmp(&ipaddr, (struct ip_addr*)&ip_info.ipaddr) || !ip_addr_cmp(&netmask, (struct ip_addr*)&ip_info.netmask) || !ip_addr_cmp(&gw, (struct ip_addr*)&ip_info.gw) || !ip_addr_cmp(&dns, &dns_curr)))) { if(ps2_ip_use_dhcp){ IP4_ADDR((struct ip_addr*)&ip_info.ipaddr, 169, 254, 0, 1); IP4_ADDR((struct ip_addr*)&ip_info.netmask, 255, 255, 0, 0); IP4_ADDR((struct ip_addr*)&ip_info.gw, 0, 0, 0, 0); IP4_ADDR(&dns, 0, 0, 0, 0); ip_info.dhcp_enabled = 1; }else{ ip_addr_set((struct ip_addr*)&ip_info.ipaddr, &ipaddr); ip_addr_set((struct ip_addr*)&ip_info.netmask, &netmask); ip_addr_set((struct ip_addr*)&ip_info.gw, &gw); ip_info.dhcp_enabled = 0; } dns_setserver(0, &dns); result = ps2ip_setconfig(&ip_info); }else result = 0; } return result; }
IPAddress MTD_FLASHMEM NSLookup::getDNSServer(uint32_t num) { return IPAddress(dns_getserver(num)); }
/** * Get the DNS ip address. * @param dns_no * @return IPAddress DNS Server IP */ IPAddress WiFiSTAClass::dnsIP(uint8_t dns_no) { ip_addr_t dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip.u_addr.ip4.addr); }
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; } } }
/** * Get the DNS ip address. * @param dns_no * @return IPAddress DNS Server IP */ IPAddress ESP8266WiFiSTAClass::dnsIP(uint8_t dns_no) { ip_addr_t dns_ip = dns_getserver(dns_no); return IPAddress(dns_ip.addr); }
/* * Device Information View * Device: Win32 or Cortex-M3 etc * Memory: * Thread: * IP Address: * Gateway: * DNS: */ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) { switch (event->type) { case RTGUI_EVENT_PAINT: { struct rtgui_dc* dc; struct rtgui_rect rect; char* line; rt_uint32_t total, used, max_used; line = rtgui_malloc(256); if (line == RT_NULL) return RT_FALSE; dc = rtgui_dc_begin_drawing(widget); if (dc == RT_NULL) { rtgui_free(line); return RT_FALSE; } rtgui_widget_get_rect(widget, &rect); /* fill background */ rtgui_dc_fill_rect(dc, &rect); rect.y2 = rect.y1 + 18; { rt_uint32_t dev_index, rev_index; dev_index = DBGMCU_GetDEVID(); dev_index = (dev_index - 0x410)/2; rev_index = DBGMCU_GetREVID(); switch (rev_index) { case 0x1000: case 0x0000: rev_index = 0; /* Revision A */ break; case 0x1001: case 0x2001: rev_index = 3; /* Revision Z */ break; case 0x2000: rev_index = 1; /* Revision B */ break; case 0x2002: rev_index = 2; /* Revision Y */ break; default: rev_index = 4; /* Unknown */ break; }; /* check device index */ if (dev_index > 4) dev_index = 3; /* draw each information */ sprintf(line, "设备: %s %s", stm32_devname[dev_index], stm32_revname[rev_index]); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; } rt_memory_info(&total, &used, &max_used); sprintf(line, "内存: 当前使用 %d 字节", used); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; { rt_uint16_t rect_width; rtgui_color_t saved; rtgui_rect_t mem_rect = rect; rtgui_rect_inflate(&mem_rect, -2); rtgui_dc_draw_rect(dc, &mem_rect); rtgui_rect_inflate(&mem_rect, -1); rect_width = rtgui_rect_width(mem_rect); saved = RTGUI_WIDGET_BACKGROUND(widget); RTGUI_WIDGET_BACKGROUND(widget) = light_grey; mem_rect.x2 = mem_rect.x1 + (max_used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); RTGUI_WIDGET_BACKGROUND(widget) = blue; mem_rect.x2 = mem_rect.x1 + (used * rect_width / total); rtgui_dc_fill_rect(dc, &mem_rect); /* restore color */ RTGUI_WIDGET_BACKGROUND(widget) = saved; } rect.y1 += 18; rect.y2 += 18; sprintf(line, "线程数: %d", get_thread_cnt()); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #ifdef RT_USING_LWIP { struct ip_addr ip_addr; struct _ip_addr { rt_uint8_t addr0, addr1, addr2, addr3; } *addr; addr = (struct _ip_addr*)&netif_default->ip_addr.addr; sprintf(line, "IP地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->gw.addr; sprintf(line, "网关地址: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; addr = (struct _ip_addr*)&netif_default->netmask.addr; sprintf(line, "网络掩码: %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #if LWIP_DNS ip_addr = dns_getserver(0); addr = (struct _ip_addr*)&ip_addr; sprintf(line, "DNS地址 : %d.%d.%d.%d", addr->addr0, addr->addr1, addr->addr2, addr->addr3); rtgui_dc_draw_text(dc, line, &rect); rect.y1 += 16; rect.y2 += 16; #endif } #endif rtgui_dc_end_drawing(dc); rtgui_free(line); return RT_FALSE; } case RTGUI_EVENT_KBD: { struct rtgui_event_kbd* ekbd; ekbd = (struct rtgui_event_kbd*)event; if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN) { rtgui_workbench_t* workbench; workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(device_view)->parent); rtgui_workbench_remove_view(workbench, device_view); rtgui_view_destroy(device_view); device_view = RT_NULL; } } return RT_FALSE; } /* use parent event handler */ return rtgui_view_event_handler(widget, event); }