void set_factory_ip() { struct ip_addr ipaddr, netmask, gw; memcpy(EEPROM_Data.BoxIPAddress, DEFAULT_Data.BoxIPAddress , 4); memcpy(EEPROM_Data.SubNetMask, DEFAULT_Data.SubNetMask , 4); memcpy(EEPROM_Data.GetwayAddress, DEFAULT_Data.GetwayAddress , 4); ipaddr.addr = get32( EEPROM_Data.BoxIPAddress ); netmask.addr = get32( EEPROM_Data.SubNetMask ); gw.addr = get32( EEPROM_Data.GetwayAddress ); #if 0 //ZOTIPS netif_set_ipaddr(WLanface, &ipaddr); netif_set_netmask(WLanface, &netmask); netif_set_gw(WLanface, &gw); #endif //ZOTIPS netif_set_ipaddr(Lanface, &ipaddr); netif_set_netmask(Lanface, &netmask); netif_set_gw(Lanface, &gw); mib_DHCP_p->IPAddr = DWordSwap(Lanface->ip_addr.addr); mib_DHCP_p->SubnetMask = DWordSwap(Lanface->netmask.addr); mib_DHCP_p->GwyAddr = DWordSwap(Lanface->gw.addr); }
void set_factory_ip() { struct ip_addr ipaddr, netmask, gw; memcpy(EEPROM_Data.BoxIPAddress, DEFAULT_Data.BoxIPAddress , 4); memcpy(EEPROM_Data.SubNetMask, DEFAULT_Data.SubNetMask , 4); memcpy(EEPROM_Data.GetwayAddress, DEFAULT_Data.GetwayAddress , 4); ipaddr.addr = NGET32( EEPROM_Data.BoxIPAddress ); netmask.addr = NGET32( EEPROM_Data.SubNetMask ); gw.addr = NGET32( EEPROM_Data.GetwayAddress ); #if defined(WIRELESS_CARD) if(WLanface != NULL){ netif_set_ipaddr(WLanface, &ipaddr); netif_set_netmask(WLanface, &netmask); netif_set_gw(WLanface, &gw); } #endif netif_set_ipaddr(Lanface, &ipaddr); netif_set_netmask(Lanface, &netmask); netif_set_gw(Lanface, &gw); mib_DHCP_p->IPAddr = DWordSwap(Lanface->ip_addr.addr); mib_DHCP_p->SubnetMask = DWordSwap(Lanface->netmask.addr); mib_DHCP_p->GwyAddr = DWordSwap(Lanface->gw.addr); }
static err_t dhcp_release(struct dhcp_state *state) { err_t result; u16_t msecs; DEBUGF(DHCP_DEBUG, ("dhcp_release()\n")); // and idle DHCP client dhcp_set_state(state, DHCP_OFF); // create and initialize the DHCP message header result = dhcp_create_request(state); if (result == ERR_OK) { dhcp_option(state, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN); dhcp_option_byte(state, DHCP_RELEASE); dhcp_option_trailer(state); pbuf_realloc(state->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + state->options_out_len); udp_bind(state->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT); udp_connect(state->pcb, &state->server_ip_addr, DHCP_SERVER_PORT); udp_send(state->pcb, state->p_out); dhcp_delete_request(state); } state->tries++; msecs = state->tries < 10 ? state->tries * 1000 : 10 * 1000; state->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS; DEBUGF(DHCP_DEBUG, ("dhcp_release(): request timeout %u msecs\n", msecs)); // remove IP address from interface netif_set_ipaddr(state->netif, IP_ADDR_ANY); netif_set_gw(state->netif, IP_ADDR_ANY); netif_set_netmask(state->netif, IP_ADDR_ANY); return result; }
// This sets the IP configuration on-the-fly void ethernet_set_configuration(IPAddress ipAddress, IPAddress netMask, IPAddress gateWay) { if ((gs_net_if.flags & NETIF_FLAG_DHCP) != 0) { // stop DHCP if it was used before dhcp_stop(&gs_net_if); } struct ip_addr x_ip_addr, x_net_mask, x_gateway; x_ip_addr.addr = ipAddress.GetV4LittleEndian(); x_net_mask.addr = netMask.GetV4LittleEndian(); x_gateway.addr = gateWay.GetV4LittleEndian(); if (x_ip_addr.addr == 0) { // start DHCP and request a dynamic IP address dhcp_start(&gs_net_if); } else { // use static IP address netif_set_ipaddr(&gs_net_if, &x_ip_addr); netif_set_netmask(&gs_net_if, &x_net_mask); netif_set_gw(&gs_net_if, &x_gateway); // don't forget to set it up again netif_set_up(&gs_net_if); } }
int netstack_set_gatewayip(u8 *addr) { ip_addr_t gw; IP4_ADDR(&gw, addr[0],addr[1],addr[2],addr[3]); netif_set_gw(&lns.nif, &gw); return VMM_OK; }
// This sets the IP configuration on-the-fly void ethernet_set_configuration(const uint8_t ipAddress[], const uint8_t netMask[], const uint8_t gateWay[]) { if ((gs_net_if.flags & NETIF_FLAG_DHCP) != 0) { // stop DHCP if it was used before dhcp_stop(&gs_net_if); } struct ip_addr x_ip_addr, x_net_mask, x_gateway; IP4_ADDR(&x_ip_addr, ipAddress[0], ipAddress[1], ipAddress[2], ipAddress[3]); IP4_ADDR(&x_net_mask, netMask[0], netMask[1], netMask[2], netMask[3]); IP4_ADDR(&x_gateway, gateWay[0], gateWay[1], gateWay[2], gateWay[3]); if (x_ip_addr.addr == 0) { // start DHCP and request a dynamic IP address dhcp_start(&gs_net_if); } else { // use static IP address netif_set_ipaddr(&gs_net_if, &x_ip_addr); netif_set_netmask(&gs_net_if, &x_net_mask); netif_set_gw(&gs_net_if, &x_gateway); // don't forget to set it up again netif_set_up(&gs_net_if); } }
cmd_state_t cmd_set_ip(int argc, char* argv[], void* ctx) { struct net_cfg *ncfg = ctx; struct ip_addr lwip_addr; struct netif *nif = ncfg->netif; if (argc == 2 && (strncmp(argv[1], "none", 4) == 0)) { ncfg->dhcp_enabled = 1; return CMD_DONE; } else if (argc != 4 ) { printk("usage: ip <ip> <netmask> <gateway-ip>\n"); printk(" or : ip none (to enable DHCP)\n"); return CMD_DONE; } /* IP address */ lwip_addr = str2ip(argv[1]); netif_set_ipaddr(nif, &lwip_addr); /* Netmask */ lwip_addr = str2ip(argv[2]); netif_set_netmask(nif, &lwip_addr); /* Default Gateway address */ lwip_addr = str2ip(argv[3]); netif_set_gw(nif, &lwip_addr); /* Disable DHCP */ ncfg->dhcp_enabled = 0; return CMD_DONE; }
void set_if(char* ip_addr, char* gw_addr, char* nm_addr) { struct ip_addr *ip; struct in_addr addr; ip = (struct ip_addr *)&addr; /* set ip address */ if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr)) { netif_set_ipaddr(netif_default, ip); } /* set gateway address */ if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr)) { netif_set_gw(netif_default, ip); } /* set netmask address */ if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr)) { netif_set_netmask(netif_default, ip); } }
/** * Change IP address configuration for a network interface (including netmask * and default gateway). * * @param netif the network interface to change * @param ipaddr the new IP address * @param netmask the new netmask * @param gw the new default gateway */ void netif_set_addr(struct netif *netif, ip_addr_t *ipaddr, ip_addr_t *netmask, ip_addr_t *gw) { netif_set_ipaddr(netif, ipaddr); netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); }
/** * @ingroup netif_ip4 * Change IP address configuration for a network interface (including netmask * and default gateway). * * @param netif the network interface to change * @param ipaddr the new IP address * @param netmask the new netmask * @param gw the new default gateway */ void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw) { if (ip4_addr_isany(ipaddr)) { /* when removing an address, we have to remove it *before* changing netmask/gw to ensure that tcp RST segment can be sent correctly */ netif_set_ipaddr(netif, ipaddr); netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); } else { netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); /* set ipaddr last to ensure netmask/gw have been set when status callback is called */ netif_set_ipaddr(netif, ipaddr); } }
void netif_set_addr(struct netif *netif,struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) { netif_set_ipaddr(netif, ipaddr); netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); }
/** * Change IP address configuration for a network interface (including netmask * and default gateway). * * @param netif the network interface to change * @param ipaddr the new IP address * @param netmask the new netmask * @param gw the new default gateway */ void netif_set_addr(struct netif *netif, const ip4_addr_t *ipaddr, const ip4_addr_t *netmask, const ip4_addr_t *gw) { netif_set_netmask(netif, netmask); netif_set_gw(netif, gw); /* set ipaddr last to ensure netmask/gw have been set when status callback is called */ netif_set_ipaddr(netif, ipaddr); }
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) { struct ip_addr *ip; struct in_addr addr; struct netif * netif = netif_list; struct ip_param ipcfg; int netno; if(strlen(netif_name) > sizeof(netif->name)) { printf_syn("network interface name too long!\r\n"); return; } netno = 0; while(netif != RT_NULL) { if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0) break; ++netno; netif = netif->next; if( netif == RT_NULL ) { printf_syn("network interface: %s not found!\n", netif_name); return; } } read_syscfgdata_tbl(SYSCFGDATA_TBL_IPCFG, netno, &ipcfg); ip = (struct ip_addr *)&addr; /* set ip address */ if ((ip_addr != RT_NULL) && inet_aton(ip_addr, &addr)) { netif_set_ipaddr(netif, ip); ipcfg.ipaddr.addr = ntohl(addr.s_addr); } /* set gateway address */ if ((gw_addr != RT_NULL) && inet_aton(gw_addr, &addr)) { netif_set_gw(netif, ip); ipcfg.gw.addr = ntohl(addr.s_addr); } /* set netmask address */ if ((nm_addr != RT_NULL) && inet_aton(nm_addr, &addr)) { netif_set_netmask(netif, ip); ipcfg.netmask.addr = ntohl(addr.s_addr); } write_syscfgdata_tbl(SYSCFGDATA_TBL_IPCFG, netno, &ipcfg); return; }
/** * Bind the interface to the offered IP address. * */ static void dhcp_bind(struct dhcp_state *state) { struct ip_addr sn_mask, gw_addr; dhcp_set_state(state, DHCP_BOUND); if (state->offered_t1_renew != 0xffffffffUL) { DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t1 renewal timer %u secs\n", state->offered_t1_renew)); state->t1_timeout = (state->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; if (state->t1_timeout == 0) state->t1_timeout = 1; DEBUGF(DHCP_DEBUG, ("dhcp_bind(): request timeout %u msecs\n", state->offered_t1_renew*1000)); } if (state->offered_t2_rebind != 0xffffffffUL) { DEBUGF(DHCP_DEBUG, ("dhcp_bind(): t2 rebind timer %u secs\n", state->offered_t2_rebind)); state->t2_timeout = (state->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS; if (state->t2_timeout == 0) state->t2_timeout = 1; DEBUGF(DHCP_DEBUG, ("dhcp_bind(): request timeout %u msecs\n", state->offered_t2_rebind*1000)); } ip_addr_set(&sn_mask, &state->offered_sn_mask); // subnet mask not given if (sn_mask.addr == 0) { // choose a safe subnet mask given the network class u8_t first_octet = ip4_addr1(&sn_mask); if (first_octet <= 127) sn_mask.addr = htonl(0xff000000); else if (first_octet >= 192) sn_mask.addr = htonl(0xffffff00); else sn_mask.addr = htonl(0xffff0000); } DEBUGF(DHCP_DEBUG, ("dhcp_bind(): SN: 0x%08x\n", sn_mask.addr)); netif_set_netmask(state->netif, &sn_mask); ip_addr_set(&gw_addr, &state->offered_gw_addr); // gateway address not given if (gw_addr.addr == 0) { gw_addr.addr &= sn_mask.addr; gw_addr.addr |= 0x01000000; } DEBUGF(DHCP_DEBUG, ("dhcp_bind(): GW: 0x%08x\n", gw_addr.addr)); netif_set_gw(state->netif, &gw_addr); DEBUGF(DHCP_DEBUG, ("dhcp_bind(): IP: 0x%08x\n", state->offered_ip_addr.addr)); netif_set_ipaddr(state->netif, &state->offered_ip_addr); l4e_printf("dhcp: %hd.%hd.%hd.%hd/%hd.%hd.%hd.%hd, gw %hd.%hd.%hd.%hd\n", ip_split(&state->offered_ip_addr), ip_split(&sn_mask), ip_split(&gw_addr)); }
static void nic_ioctl_set_gateway(__unused struct socket * sock, struct nic * nic, message * m) { nwio_route_t route; int err; err = copy_from_user(m->m_source, &route, sizeof(route), (cp_grant_id_t) m->IO_GRANT, 0); if (err != OK) send_reply(m, err); netif_set_gw(&nic->netif, (ip_addr_t *)&route.nwr_gateway); send_reply(m, OK); }
void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr) { struct ip_addr *ip; struct in_addr addr; struct netif * netif = netif_list; if(strlen(netif_name) > sizeof(netif->name)) { printf("network interface name too long!\r\n"); return; } while(netif != NULL) { if(strncmp(netif_name, netif->name, sizeof(netif->name)) == 0) break; netif = netif->next; if( netif == NULL ) { printf("network interface: %s not found!\r\n", netif_name); return; } } ip = (struct ip_addr *)&addr; /* set ip address */ if ((ip_addr != NULL) && inet_aton(ip_addr, &addr)) { netif_set_ipaddr(netif, ip); } /* set gateway address */ if ((gw_addr != NULL) && inet_aton(gw_addr, &addr)) { netif_set_gw(netif, ip); } /* set netmask address */ if ((nm_addr != NULL) && inet_aton(nm_addr, &addr)) { netif_set_netmask(netif, ip); } }
int ps2ip_setconfig(t_ip_info* pInfo) { NetIF* pNetIF=netif_find(pInfo->netif_name); if (pNetIF==NULL) { return 0; } netif_set_ipaddr(pNetIF,(IPAddr*)&pInfo->ipaddr); netif_set_netmask(pNetIF,(IPAddr*)&pInfo->netmask); netif_set_gw(pNetIF,(IPAddr*)&pInfo->gw); #if LWIP_DHCP //Enable dhcp here if (pInfo->dhcp_enabled) { if (!pNetIF->dhcp) { //Start dhcp client dhcp_start(pNetIF); } } else { if (pNetIF->dhcp) { //Stop dhcp client dhcp_stop(pNetIF); } } #endif return 1; }
/********************************************************************************************************* ** 函数名称: __rtSetGwCallback ** 功能描述: 设置网络接口的网关(在 TCPIP 上下文中执行) ** 输 入 : pipaddrGw 网关地址 ** uiGwFlags 网关设置属性 ** pcNetifName 网络接口名 ** 输 出 : ERROR_NONE ** 全局变量: ** 调用模块: *********************************************************************************************************/ static INT __rtSetGwCallback (ip_addr_t *pipaddrGw, UINT uiGwFlags, CPCHAR pcNetifName) { #define LW_RT_GW_FLAG_SET 0x1 #define LW_RT_GW_FLAG_DEFAULT 0x2 struct netif *pnetif = netif_find((PCHAR)pcNetifName); if (pnetif) { if (uiGwFlags & LW_RT_GW_FLAG_SET) { netif_set_gw(pnetif, pipaddrGw); } if (uiGwFlags & LW_RT_GW_FLAG_DEFAULT) { netif_set_default(pnetif); } return (ERROR_NONE); } else { _ErrorHandle(ENXIO); return (PX_ERROR); } }
/** * Configure interface for use with current LL IP-Address * * @param netif network interface to configure with current LL IP-Address */ static err_t autoip_bind(struct netif *netif) { struct autoip *autoip = netif->autoip; struct ip_addr sn_mask, gw_addr; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_bind(netif=%p) %c%c%"U16_F" 0x%08"X32_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num, autoip->llipaddr.addr)); IP4_ADDR(&sn_mask, 255, 255, 0, 0); IP4_ADDR(&gw_addr, 0, 0, 0, 0); netif_set_ipaddr(netif, &autoip->llipaddr); netif_set_netmask(netif, &sn_mask); netif_set_gw(netif, &gw_addr); /* bring the interface up */ netif_set_up(netif); return ERR_OK; }
/** * Configure interface for use with current LL IP-Address * * @param netif network interface to configure with current LL IP-Address */ static err_t ICACHE_FLASH_ATTR autoip_bind(struct netif *netif) { struct autoip *autoip = netif->autoip; ip_addr_t sn_mask, gw_addr; LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_bind(netif=%p) %c%c%"U16_F" %"U16_F".%"U16_F".%"U16_F".%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num, ip4_addr1_16(&autoip->llipaddr), ip4_addr2_16(&autoip->llipaddr), ip4_addr3_16(&autoip->llipaddr), ip4_addr4_16(&autoip->llipaddr))); IP4_ADDR(&sn_mask, 255, 255, 0, 0); IP4_ADDR(&gw_addr, 0, 0, 0, 0); netif_set_ipaddr(netif, &autoip->llipaddr); netif_set_netmask(netif, &sn_mask); netif_set_gw(netif, &gw_addr); /* bring the interface up */ netif_set_up(netif); return ERR_OK; }
int main(int argc, char *argv[]) { int c; int keep_alive; int non_local; struct netif *netif; int dns_count; char *str; char *endptr; int mtu; int fd_in; int fd_out; ip4_addr_t ipaddr; ip4_addr_t netmask; ip4_addr_t gateway; ip4_addr_t dns; struct event_base *base; char *pcap_file; struct conn_info *local; struct conn_info *remote; struct conn_info *socks; struct conn_info *info; ip_addr_set_zero(&ipaddr); ip_addr_set_zero(&netmask); ip_addr_set_zero(&gateway); local = remote = socks = NULL; dns_count = 0; keep_alive = 0; fd_in = 0; fd_out = 1; mtu = 0; pcap_file = NULL; non_local = 0; signal(SIGPIPE, SIG_IGN); base = event_base_new(); lwip_init(); libevent_timeouts_init(base); if ((str = getenv("INTERNAL_IP4_ADDRESS"))) ip4addr_aton(str, &ipaddr); if ((str = getenv("INTERNAL_IP4_MTU"))) mtu = strtoul(str, NULL, 0); if ((str = getenv("VPNFD"))) fd_in = fd_out = strtoul(str, NULL, 0); if ((str = getenv("CISCO_DEF_DOMAIN"))) { endptr = str; while ((str = tokenize(endptr, ", ", &endptr))) host_add_search(str); } if ((str = getenv("INTERNAL_IP4_DNS"))) { endptr = str; while ((str = tokenize(endptr, ", ", &endptr))) { ip4addr_aton(str, &dns); dns_setserver(dns_count++, &dns); free(str); } } while ((c = getopt(argc, argv, "L:D:R:k:m:s:d:i:n:G:p:gh")) != -1) { switch (c) { case 'L': info = parse_conn_info(optarg, 4); if (!info) print_usage(argv[0]); info->next = local; local = info; break; case 'D': info = parse_conn_info(optarg, 2); if (!info) print_usage(argv[0]); info->next = socks; socks = info; break; case 'R': info = parse_conn_info(optarg, 4); if (!info) print_usage(argv[0]); info->next = remote; remote = info; break; case 'k': keep_alive = strtoul(optarg, &endptr, 0); if (*endptr) print_usage(argv[0]); keep_alive *= 1000; break; case 'm': mtu = strtoul(optarg, &endptr, 0); if (*endptr) print_usage(argv[0]); break; case 's': while ((str = tokenize(optarg, ", ", &optarg))) host_add_search(str); break; case 'd': while ((str = tokenize(optarg, ", ", &optarg))) { ip4addr_aton(str, &dns); dns_setserver(dns_count++, &dns); free(str); } break; case 'i': ip4addr_aton(optarg, &ipaddr); break; case 'n': ip4addr_aton(optarg, &netmask); break; case 'G': ip4addr_aton(optarg, &gateway); break; #ifdef USE_PCAP case 'p': pcap_file = strdup(optarg); break; #endif case 'g': non_local = 1; break; default: print_usage(argv[0]); } } while (local) { info = local; str = info->bind && info->bind[0] ? info->bind : NULL; if (!non_local) str = str ? : "localhost"; if (forward_local(base, str, info->bind_port, info->host, info->host_port, keep_alive) < 0) return -1; local = info->next; free_conn_info(info); } while (socks) { info = socks; str = info->bind && info->bind[0] ? info->bind : NULL; if (!non_local) str = str ? : "localhost"; if (socks_listen(base, str, info->bind_port, keep_alive) < 0) return -1; socks = socks->next; free_conn_info(info); } while (remote) { info = remote; if (forward_remote(base, info->bind_port, info->host, info->host_port, keep_alive) < 0) return -1; remote = info->next; free_conn_info(info); } netif = tunif_add(base, fd_in, fd_out, pcap_file); netif_set_ipaddr(netif, &ipaddr); netif_set_netmask(netif, &netmask); netif_set_gw(netif, &gateway); if (mtu) netif->mtu = mtu; netif_set_up(netif); event_base_dispatch(base); return 0; }
/* * Set the IP, mask and gateway of the IF */ void networking_set_addr(struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) { netif_set_ipaddr(the_interface, ipaddr); netif_set_netmask(the_interface, netmask); netif_set_gw(the_interface, gw); }