/*********************************************************************** * function:NetInit() * brief:网口初始化,两个IP地址网段要不同 * ***********************************************************************/ void UDP_NetInit(void) { //ipAttach (0, "mottsec"); //ifconfig ("mottsec0 192.168.4.110 up"); ipAttach (1, "mottsec"); ifconfig ("mottsec1 192.168.5.126 up"); }
static int sal_if_do_deconfig(char *pfx, END_OBJ *eo, char *if_name, int if_unit) /* * Function: * Purpose: * Parameters: * Returns: */ { #if VX_VERSION == 66 || VX_VERSION == 68 char ifconfigstr[32]; #endif /* VX_VERSION == 66 || VX_VERSION == 68 */ LOG_INFO(BSL_LS_APPL_END, (BSL_META("%s: Stopping %s %d %08x \n"), pfx, if_name, if_unit, (uint32)eo)); if (OK != muxDevStop(eo)) { cli_out("%s: Error: muxDevStop failed: %s%d\n", pfx, if_name, if_unit); return(-1); } #if VX_VERSION == 66 || VX_VERSION == 68 sprintf(ifconfigstr, "%s%d down", if_name, if_unit); if (ERROR == ifconfig(ifconfigstr)) { cli_out("%s: ifconfig down failed: %s%d <-- %s\n", pfx, if_name, if_unit, ifconfigstr); return(-1); } sprintf(ifconfigstr, "%s%d detach", if_name, if_unit); if (ERROR == ifconfig(ifconfigstr)) { cli_out("%s: ifconfig down failed: %s%d <-- %s\n", pfx, if_name, if_unit, ifconfigstr); return(-1); } #else /* VX_VERSION == 66 || VX_VERSION == 68 */ LOG_INFO(BSL_LS_APPL_END, (BSL_META("%s: Clearing Routes\n"), pfx)); #ifdef VXWORKS_NETWORK_STACK_6_5 #ifdef VXWORKS_NETWORK_STACK_FIXME_SHOW #error VXWORKS_NETWORK_STACK_FIXME_SHOW #endif #else ifRouteDelete(if_name, if_unit); #endif /* VXWORKS_NETWORK_STACK_6_5 */ LOG_INFO(BSL_LS_APPL_END, (BSL_META("%s: Unloading\n"), pfx)); if (OK != muxDevUnload(if_name, if_unit)) { cli_out("%s: Error: muxDevUnload failed: %s%d\n", pfx, if_name, if_unit); return(-1); } LOG_INFO(BSL_LS_APPL_END, (BSL_META("%s: Stopped and Unloaded: %s%d\n"), pfx, if_name, if_unit)); #endif /* VX_VERSION == 66 || VX_VERSION == 68 */ return(0); }
main() { char ch; long ipaddr; char ipaddr_string[16]; printf ("Wi-Fi DHCP or Static sample\n"); do { // Prompt for configuration method printf("Select method (s=static, d=dhcp): "); ch=getchar(); // Give feedback on the choice printf("%c\n",ch); if(ch=='s' || ch=='S') { // Bring the interface up statically configured printf ("configuring interface for static IP\n"); ifconfig(IF_WIFI0, IFS_IPADDR,aton(_PRIMARY_STATIC_IP), IFS_NETMASK, aton(_PRIMARY_NETMASK), IFS_ROUTER_SET, aton(MY_GATEWAY), IFS_END); break; } else if(ch=='d' || ch=='D') { // Bring the interface up with DCHP printf ("configuring interface for DHCP\n"); ifconfig(IF_WIFI0, IFS_DHCP, 1, IFS_END); break; } else { printf("Invalid selection\n\n"); } } while(1); // Initialize the TCP/IP stack sock_init_or_exit(1); // Print the IP Address to stdio ifconfig(IF_WIFI0,IFG_IPADDR,&ipaddr,IFS_END); printf("IP Address: %s -- responding to pings\n",inet_ntoa(ipaddr_string,ipaddr)); // Give the stack time... Ready to be PINGed while(1) { tcp_tick(NULL); } }
void stop_modem_ndis(void) { int i, modem_devnum = 0; char node_fname[64]; char ndis_ifname[16] = {0}; system("killall -q usb_modeswitch"); system("killall -q eject"); if (get_modem_ndis_ifname(ndis_ifname, &modem_devnum)) { disconnect_ndis(modem_devnum); if (is_interface_exist(ndis_ifname)) ifconfig(ndis_ifname, 0, "0.0.0.0", NULL); } for (i=0; i<MAX_USB_NODE; i++) { sprintf(node_fname, "%s/ttyUSB%d", MODEM_NODE_DIR, i); unlink(node_fname); sprintf(node_fname, "%s/cdc-wdm%d", MODEM_NODE_DIR, i); unlink(node_fname); sprintf(node_fname, "%s/weth%d", MODEM_NODE_DIR, i); unlink(node_fname); sprintf(node_fname, "%s/wwan%d", MODEM_NODE_DIR, i); unlink(node_fname); } }
void usrNetIfconfigInit (void) { char * ifString; /* Configure up to 10 interfaces with ifconfig */ ifString = IFCONFIG_ENTRY_1; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_1); ifString = IFCONFIG_ENTRY_2; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_2); ifString = IFCONFIG_ENTRY_3; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_3); ifString = IFCONFIG_ENTRY_4; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_4); ifString = IFCONFIG_ENTRY_5; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_5); ifString = IFCONFIG_ENTRY_6; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_6); ifString = IFCONFIG_ENTRY_7; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_7); ifString = IFCONFIG_ENTRY_8; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_8); ifString = IFCONFIG_ENTRY_9; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_9); ifString = IFCONFIG_ENTRY_10; if ((ifString != NULL)) ifconfig (IFCONFIG_ENTRY_10); }
static void openvpn_tunif_stop(const char *ifname) { if (is_interface_exist(ifname)) { ifconfig(ifname, 0, NULL, NULL); doSystem("%s %s --dev %s", OPENVPN_EXE, "--rmtun", ifname); } }
char *myurl() { static char URL[64]; char tmpstr[32]; long ipval; ifconfig(IF_DEFAULT, IFG_IPADDR, &ipval, IFS_END); sprintf(URL, "http://%s/index.shtml", inet_ntoa(tmpstr, ipval)); return URL; }
int Wireless::closeNetwork() { int status = 0; status = iw( WLAN_DEV, "disconnect", "" ); status = killall( "wpa_supplicant" ); status = ifconfig( WLAN_DEV, "up", "" ); return status; }
/* configure loopback interface */ void config_loopback(void) { /* Bring up loopback interface */ ifconfig("lo", IFUP, "127.0.0.1", "255.0.0.0"); /* Add to routing table */ route_add("lo", 0, "127.0.0.0", "0.0.0.0", "255.0.0.0"); }
/**************************************************************************** scan_assoc_callback Much like scan_callback above, this function is called as a result of a Wi-Fi scan. The main difference is that this function gives the user the option of associating with one of the BSS's. It uses scan_callback above to sort and print the scan results. Inputs: data -- far pointer to wifi_scan_data structure, which contains a count of the number of responses, and an array of _wifi_wln_scan_bss structures, with the first `count' containing valid data for the responses. ****************************************************************************/ root void scan_assoc_callback(far wifi_scan_data* data) { char c, ssid[WLN_SSID_SIZE+1]; int ssid_len; far _wifi_wln_scan_bss *bss; // Sort and print the scan results scan_callback(data); bss = data->bss; printf("\nSelect a new BSS or quit ([0-%x, q to quit)]\n", data->count-1); while (1) { tcp_tick(NULL); // While we're waiting, continue to tick. if (kbhit()) { c = getchar(); // Echo the character printf("%c\n", c); // Convert character to numeric value. if ('0' <= c && c <= '9') { c = c - '0'; } else if (isxdigit(c)) { c = (tolower(c) - 'a' + 10); } else if (tolower(c) == 'q') { printf("Quitting scan selection\n"); break; } if (c >= data->count) { printf("Unlisted option, quitting...\n"); break; } // c is now the index of the BSS the user opted to associate with bss = &(data->bss[c]); ssid_len = bss->ssid_len; // Need near copy of SSID to call ifconfig. ssid will be promoted to // far for this call, but the results will be in ssid as a near // variable _f_memcpy(ssid, bss->ssid, ssid_len); #ifdef IFC_WIFI_WPA_PSK_PASSPHRASE printf("Resetting the passphrase--this will take some time.\n"); #endif // Set the SSID. Also, if a passphrase has been defined as a macro, // then reconfigure the passphrase. This is necessary because the // passphrase and SSID together are used to generate the key. If the // SSID changes, then the generated key must change. Note that // regenerating the key will take about another 20 seconds on an // RCM54xxW. if (ifconfig (IF_WIFI0, IFS_WIFI_SSID, ssid_len, ssid, #ifdef IFC_WIFI_WPA_PSK_PASSPHRASE IFS_WIFI_WPA_PSK_PASSPHRASE, IFC_WIFI_WPA_PSK_PASSPHRASE, #endif IFS_END)) { printf (" error setting SSID\n"); } wifi_ssid_to_str (ssid, ssid, ssid_len); printf("Selected BSS is [%s]. Wait a bit, then check MAC status\n", ssid); break; } } }
void main(void) { int iferr; char ipbuf[16]; printf("Starting the network interface..."); sock_init(); printf("done.\nConfiguring the network interface..."); iferr = ifconfig(IF_DEFAULT, IFS_DHCP, 0, IFS_IPADDR, DHCPD_ADDRESS, IFS_NETMASK, DHCPD_NETMASK, IFS_UP, IFS_END); printf("done (result %d).\n\n", iferr); printf("Starting the dhcp server (v%s).\n", DHCPD_VER_STR); if (dhcpd_init(IF_DEFAULT)) { printf("dhcpd_init() failed, program terminated.\n"); } else { printf(" server ip: %s\n", inet_ntoa (ipbuf, DHCPD_ADDRESS)); printf("subnet mask: %s\n", inet_ntoa (ipbuf, DHCPD_NETMASK)); printf("dhcpd serving addresses from .1 to .%u\n", DHCPD_MAX_HOST); #ifdef PERMANENT_LEASE_MAC_ADDRESS // IP address .1 goes to PERMANENT_LEASE_MAC_ADDRESS dhcpd_add_permanent(1, PERMANENT_LEASE_MAC_ADDRESS); #endif // dump the complete DHCP leases table, including empty entries dhcpd_dump_leases(1); printf("Press 'D' to dump the table of DHCP leases.\n"); while (1) { tcp_tick(NULL); dhcpd_tick(); if (kbhit()) { switch (getchar()) { case 'd': case 'D': // dump only the used entries in the DHCP leases table dhcpd_dump_leases(0); break; } } } } }
static int bound(void) // udhcpc bound here, also call wanup { char *wan_ifname = safe_getenv("interface"); char *value; char tmp[100], prefix[] = "wanXXXXXXXXXX_"; int unit; if ((unit = wan_ifunit(wan_ifname)) < 0) strcpy(prefix, "wanx_"); else snprintf(prefix, sizeof(prefix), "wan%d_", unit); if ((value = getenv("ip"))) nvram_set(strcat_r(prefix, "ipaddr", tmp), trim_r(value)); if ((value = getenv("subnet"))) nvram_set(strcat_r(prefix, "netmask", tmp), trim_r(value)); if ((value = getenv("router"))) nvram_set(strcat_r(prefix, "gateway", tmp), trim_r(value)); if ((value = getenv("dns"))) nvram_set(strcat_r(prefix, "dns", tmp), trim_r(value)); if ((value = getenv("wins"))) nvram_set(strcat_r(prefix, "wins", tmp), trim_r(value)); nvram_set(strcat_r(prefix, "routes", tmp), getenv("routes")); nvram_set(strcat_r(prefix, "msroutes", tmp), getenv("msroutes")); #if 0 if ((value = getenv("hostname"))) sethostname(trim_r(value), strlen(value) + 1); #endif if ((value = getenv("domain"))) nvram_set(strcat_r(prefix, "domain", tmp), trim_r(value)); if ((value = getenv("lease"))) { nvram_set(strcat_r(prefix, "lease", tmp), trim_r(value)); expires(wan_ifname, atoi(value)); } ifconfig(wan_ifname, IFUP, nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), nvram_safe_get(strcat_r(prefix, "netmask", tmp))); spinlock_lock(SPINLOCK_DHCPRenew); nvram_set("dhcp_renew", "0"); // for detectWAN spinlock_unlock(SPINLOCK_DHCPRenew); wan_up(wan_ifname); logmessage("dhcp client", "%s IP: %s from %s (prefix: %s)", udhcpstate, nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), nvram_safe_get(strcat_r(prefix, "gateway", tmp)), prefix); wanmessage(""); dprintf("done\n"); return 0; }
char *myurl(void) { static char URL[64]; auto char tmpstr[32]; auto long ipval; ifconfig(IF_DEFAULT, IFG_IPADDR, &ipval, IFS_END); sprintf(URL, "http://%s/", inet_ntoa(tmpstr, ipval)); return URL; }
int wifi_config_region(wifi_region *region_info) { auto int country; auto char index[10]; auto char tmpbuf[64]; auto int i; auto int region; //---------------------------------------------------------------------- // Display Menu for region selection //---------------------------------------------------------------------- printf("\nSelect region:\n"); for(i=0; ; i++) { // Set region to populate region stucture with info // Note: Interface is down, its OK to iterate through settings to // create menu options if (ifconfig (IF_WIFI0, IFS_WIFI_REGION, i, IFS_END)) { break; } // Get info for menu display ifconfig (IF_WIFI0, IFG_WIFI_REGION_INFO, region_info, IFS_END); printf("%d %s.\n", i, region_info->country); } printf("\nSelect Region Index > "); do { country = atoi(gets(tmpbuf)); } while (!((country >= 0) && (country < _END_OF_REGIONS))); // Write region selection to userblock for subsequent reset/power cycle regionInfoEEwr(country); // Set Region from previously saved value read from the userblock, this // will set the runtime limits to be used by the wifi driver. ifconfig (IF_WIFI0, IFS_WIFI_REGION, country, IFS_END); printf("Region selection successfully updated\n\n"); return country; }
static int renew(char *ifname) { char *a, *b; int changed; _dprintf("%s: begin\n", __FUNCTION__); unlink(renewing); changed = env2nv("ip", "wan_ipaddr"); changed |= env2nv("subnet", "wan_netmask"); if (changed) { ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); } if (get_wan_proto() == WP_L2TP) { env2nv_gateway("wan_gateway_buf"); } else { a = strdup(nvram_safe_get("wan_gateway")); env2nv_gateway("wan_gateway"); b = nvram_safe_get("wan_gateway"); if ((a) && (strcmp(a, b) != 0)) { route_del(ifname, 0, "0.0.0.0", a, "0.0.0.0"); route_add(ifname, 0, "0.0.0.0", b, "0.0.0.0"); changed = 1; } free(a); } changed |= env2nv("domain", "wan_get_domain"); changed |= env2nv("dns", "wan_get_dns"); if ((a = getenv("lease")) != NULL) { nvram_set("wan_lease", a); expires(atoi(a)); } if (changed) { set_host_domain_name(); stop_dnsmasq(); dns_to_resolv(); start_dnsmasq(); } _dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr")); _dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask")); _dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway")); _dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain")); _dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns")); _dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease")); _dprintf("%s: end\n", __FUNCTION__); return 0; }
void stop_wan_usbnet(void) { int modem_devnum = 0; char ndis_ifname[16] = {0}; if (get_modem_ndis_ifname(ndis_ifname, &modem_devnum)) { ndis_control_network(ndis_ifname, modem_devnum, 0); if (is_interface_exist(ndis_ifname)) ifconfig(ndis_ifname, 0, "0.0.0.0", NULL); } }
int start_dhcpd(void) { FILE *fp; // char name[100]; char *lan_ifname=nvram_safe_get("lan_ifname"); dprintf("%s %s %s %s\n", nvram_safe_get("lan_ifname"), nvram_safe_get("dhcp_start"), nvram_safe_get("dhcp_end"), nvram_safe_get("lan_lease")); if (nvram_invmatch("dhcp_enable", "1")) return -1; ifconfig(lan_ifname, IFUP, nvram_safe_get("lan_ipaddr"), nvram_safe_get("lan_netmask")); /* Touch leases file */ if (!(fp = fopen("/tmp/udhcpd.leases", "a"))) { perror("/tmp/udhcpd.leases"); return errno; } fclose(fp); /* Write configuration file based on current information */ if (!(fp = fopen("/tmp/udhcpd.conf", "w"))) { perror("/tmp/udhcpd.conf"); return errno; } fprintf(fp, "pidfile /var/run/udhcpd.pid\n"); fprintf(fp, "start %s\n", nvram_safe_get("dhcp_start")); fprintf(fp, "end %s\n", nvram_safe_get("dhcp_end")); fprintf(fp, "interface %s\n", nvram_safe_get("lan_ifname")); fprintf(fp, "remaining yes\n"); fprintf(fp, "lease_file /tmp/udhcpd.leases\n"); fprintf(fp, "option subnet %s\n", nvram_safe_get("lan_netmask")); fprintf(fp, "option router %s\n", nvram_safe_get("lan_ipaddr")); //fprintf(fp, "option dns %s\n", nvram_safe_get("lan_ipaddr")); fprintf(fp, "option lease %s\n", nvram_safe_get("lan_lease")); //snprintf(name, sizeof(name), "%s_wins", nvram_safe_get("dhcp_wins")); //if (nvram_invmatch(name, "")) // fprintf(fp, "option wins %s\n", nvram_get(name)); //snprintf(name, sizeof(name), "%s_domain", nvram_safe_get("dhcp_domain")); if (nvram_invmatch("lan_domain", "")) fprintf(fp, "option domain %s\n", nvram_safe_get("lan_domain")); fclose(fp); system("udhcpd /tmp/udhcpd.conf"); dprintf("done\n"); return 0; }
/* * deconfig: This argument is used when udhcpc starts, and when a * leases is lost. The script should put the interface in an up, but * deconfigured state. */ static int deconfig_lan(void) { char *lan_ifname = safe_getenv("interface"); ifconfig(lan_ifname, IFUP, "0.0.0.0", NULL); expires_lan(lan_ifname, 0); lan_down(lan_ifname); dprintf("done\n"); return 0; }
int get_stored_region(wifi_region *region_info) { auto int country; auto char data[64]; if((country = regionInfoEErd()) < 0 ) { ifconfig (IF_WIFI0, IFG_WIFI_REGION_INFO, region_info, IFS_END); display_info(region_info); return -1; } return country; }
static int bound(char *ifname) { _dprintf("%s: begin\n", __FUNCTION__); unlink(renewing); env2nv("ip", "wan_ipaddr"); env2nv("subnet", "wan_netmask"); env2nv_gateway("wan_gateway"); env2nv("dns", "wan_get_dns"); env2nv("domain", "wan_get_domain"); env2nv("lease", "wan_lease"); expires(atoi(safe_getenv("lease"))); _dprintf("wan_ipaddr=%s\n", nvram_safe_get("wan_ipaddr")); _dprintf("wan_netmask=%s\n", nvram_safe_get("wan_netmask")); _dprintf("wan_gateway=%s\n", nvram_safe_get("wan_gateway")); _dprintf("wan_get_domain=%s\n", nvram_safe_get("wan_get_domain")); _dprintf("wan_get_dns=%s\n", nvram_safe_get("wan_get_dns")); _dprintf("wan_lease=%s\n", nvram_safe_get("wan_lease")); ifconfig(ifname, IFUP, nvram_safe_get("wan_ipaddr"), nvram_safe_get("wan_netmask")); if (get_wan_proto() == WP_L2TP) { int i = 0; /* Delete all default routes */ while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) || (i++ < 10)); /* Set default route to gateway if specified */ route_add(ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), "0.0.0.0"); /* Backup the default gateway. It should be used if L2TP connection is broken */ nvram_set("wan_gateway_buf", nvram_get("wan_gateway")); /* clear dns from the resolv.conf */ nvram_set("wan_get_dns",""); dns_to_resolv(); start_firewall(); start_l2tp(); } else { start_wan_done(ifname); } _dprintf("%s: end\n", __FUNCTION__); return 0; }
/* job_attr_get_netinfo() */ static char * job_attr_get_netinfo(char *key, char *attr) { char *netinfo; /* get network information of node in netinfo, xmalloc'ed */ netinfo = ifconfig(); snprintf(attr, PMI2_MAX_VALLEN, "%s", netinfo); xfree(netinfo); debug3("%s: netinfo %s", __func__, attr); return attr; }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname; char *value; char buf[256]; char tmp[100], prefix[WAN_PREFIX_SZ]; if (ppp_prefix(&wan_ifname, prefix) < 0) return -1; umask(022); /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { if (nvram_invmatch(strcat_r(prefix, "ipaddr", tmp), value)) ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); _ifconfig(wan_ifname, IFUP, value, "255.255.255.255", getenv("IPREMOTE")); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); strcpy(buf, ""); if (getenv("DNS1")) sprintf(buf, "%s", getenv("DNS1")); if (getenv("DNS2")) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", getenv("DNS2")); nvram_set(strcat_r(prefix, "dns", tmp), buf); wan_up(wan_ifname); logmessage(nvram_safe_get("wan_proto_t"), "connected to ISP"); wanmessage(""); dprintf("done\n"); return 0; }
static void check_and_set_comm_if(void) { #ifndef RTCONFIG_RALINK const char *ipaddr; char buf_ip[32]; ipaddr = getifaddr("vlan2", AF_INET, GIF_PREFIXLEN); //_dprintf("%s: %s\n", __func__, ipaddr); if(!ipaddr || (ipaddr && strncmp("169.254", ipaddr, 7))) { pick_a_random_ipv4(buf_ip); ifconfig("vlan2", IFUP, buf_ip, "255.255.0.0"); } if(!check_if_route_exist("vlan2", "169.254.0.1", "255.255.255.255")) route_add("vlan2", 0, "169.254.0.1", "0.0.0.0", "255.255.255.255"); #endif }
/* * Called when link comes up */ int ipup_main(int argc, char **argv) { FILE *fp; char *wan_ifname = safe_getenv("IFNAME"); char *value; char buf[256]; int unit; char tmp[100], prefix[] = "wanXXXXXXXXXX_"; dprintf("%s\n", argv[0]); if ((unit = ppp_ifunit(wan_ifname)) < 0) return -1; snprintf(prefix, sizeof(prefix), "wan%d_", unit); /* Touch connection file */ if (!(fp = fopen(strcat_r("/tmp/ppp/link.", wan_ifname, tmp), "a"))) { perror(tmp); return errno; } fclose(fp); if ((value = getenv("IPLOCAL"))) { ifconfig(wan_ifname, IFUP, value, "255.255.255.255"); nvram_set(strcat_r(prefix, "ipaddr", tmp), value); nvram_set(strcat_r(prefix, "netmask", tmp), "255.255.255.255"); } if ((value = getenv("IPREMOTE"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); strcpy(buf, ""); if (getenv("DNS1")) sprintf(buf, "%s", getenv("DNS1")); if (getenv("DNS2")) sprintf(buf + strlen(buf), "%s%s", strlen(buf) ? " " : "", getenv("DNS2")); nvram_set(strcat_r(prefix, "dns", tmp), buf); wan_up(wan_ifname); dprintf("done\n"); return 0; }
/* * deconfig: This argument is used when udhcpc starts, and when a * leases is lost. The script should put the interface in an up, but * deconfigured state. */ static int deconfig(void) { char *lan_ifname = safe_getenv("interface"); ifconfig(lan_ifname, IFUP, "0.0.0.0", NULL); expires(lan_ifname, 0); lan_down(lan_ifname); logmessage("dhcp client", "%s: lease is lost", udhcpstate); //wanmessage("lost IP from server"); dprintf("done\n"); return 0; }
/* * bound: This argument is used when udhcpc moves from an unbound, to * a bound state. All of the paramaters are set in enviromental * variables, The script should configure the interface, and set any * other relavent parameters (default gateway, dns server, etc). */ static int bound(void) { char *lan_ifname = safe_getenv("interface"); char *value; char tmp[100], prefix[] = "lanXXXXXXXXXX_"; snprintf(prefix, sizeof(prefix), "lan_"); if ((value = getenv("ip"))) nvram_set(strcat_r(prefix, "ipaddr", tmp), value); if ((value = getenv("subnet"))) nvram_set(strcat_r(prefix, "netmask", tmp), value); if ((value = getenv("router"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); if ((value = getenv("dns"))) nvram_set(strcat_r(prefix, "dns", tmp), value); if ((value = getenv("wins"))) nvram_set(strcat_r(prefix, "wins", tmp), value); if ((value = getenv("hostname"))) sethostname(value, strlen(value) + 1); if ((value = getenv("domain"))) nvram_set(strcat_r(prefix, "domain", tmp), value); if ((value = getenv("lease"))) { nvram_set(strcat_r(prefix, "lease", tmp), value); expires(lan_ifname, atoi(value)); } ifconfig(lan_ifname, IFUP, nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), nvram_safe_get(strcat_r(prefix, "netmask", tmp))); lan_up(lan_ifname); logmessage("dhcp client", "%s IP : %s from %s", udhcpstate, nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), nvram_safe_get(strcat_r(prefix, "gateway", tmp))); //wanmessage(""); dprintf("done\n"); return 0; }
static int deconfig(char *ifname) { _dprintf("%s: begin\n", __FUNCTION__); ifconfig(ifname, IFUP, "0.0.0.0", NULL); nvram_set("wan_ipaddr", "0.0.0.0"); nvram_set("wan_netmask", "0.0.0.0"); nvram_set("wan_gateway", "0.0.0.0"); nvram_set("wan_get_dns", ""); nvram_set("wan_lease", "0"); expires(0); // int i = 10; // while ((route_del(ifname, 0, NULL, NULL, NULL) == 0) && (i-- > 0)) { } _dprintf("%s: end\n", __FUNCTION__); return 0; }
/* * deconfig: This argument is used when udhcpc starts, and when a * leases is lost. The script should put the interface in an up, but * deconfigured state. */ static int deconfig(void) { char *wan_ifname = safe_getenv("interface"); if (nvram_match("wan0_proto", "l2tp") || nvram_match("wan0_proto", "pptp")) { /* fix hang-up issue */ logmessage("dhcp client", "skipping resetting IP address to 0.0.0.0"); } else ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); expires(wan_ifname, 0); wan_down(wan_ifname); logmessage("dhcp client", "%s: lease is lost", udhcpstate); wanmessage("lost IP from server"); return 0; }
/* * bound: This argument is used when udhcpc moves from an unbound, to * a bound state. All of the paramaters are set in enviromental * variables, The script should configure the interface, and set any * other relavent parameters (default gateway, dns server, etc). */ static int bound(void) { char *wan_ifname = safe_getenv("interface"); char *value; char tmp[100], prefix[] = "wanXXXXXXXXXX_"; int unit; if ((unit = wan_ifunit(wan_ifname)) < 0) return -1; snprintf(prefix, sizeof(prefix), "wan%d_", unit); if ((value = getenv("ip"))) nvram_set(strcat_r(prefix, "ipaddr", tmp), value); if ((value = getenv("subnet"))) nvram_set(strcat_r(prefix, "netmask", tmp), value); if ((value = getenv("router"))) nvram_set(strcat_r(prefix, "gateway", tmp), value); if ((value = getenv("dns"))) nvram_set(strcat_r(prefix, "dns", tmp), value); if ((value = getenv("wins"))) nvram_set(strcat_r(prefix, "wins", tmp), value); if ((value = getenv("hostname"))) sethostname(value, strlen(value) + 1); if ((value = getenv("domain"))) nvram_set(strcat_r(prefix, "domain", tmp), value); if ((value = getenv("lease"))) { nvram_set(strcat_r(prefix, "lease", tmp), value); expires(wan_ifname, atoi(value)); } ifconfig(wan_ifname, IFUP, nvram_safe_get(strcat_r(prefix, "ipaddr", tmp)), nvram_safe_get(strcat_r(prefix, "netmask", tmp))); wan_up(wan_ifname); dprintf("done\n"); return 0; }
/* * bound: This argument is used when udhcpc moves from an unbound, to * a bound state. All of the paramaters are set in enviromental * variables, The script should configure the interface, and set any * other relavent parameters (default gateway, dns server, etc). */ static int bound_lan(void) { char *lan_ifname = safe_getenv("interface"); char *value; int flags; unsigned long addr, netmask; struct in_addr in_addr, in_netmask; if ((value = getenv("ip"))) nvram_set("lan_ipaddr", value); if ((value = getenv("subnet"))) nvram_set("lan_netmask", value); if ((value = getenv("router"))) nvram_set("lan_gateway", value); if ((value = getenv("lease"))) expires_lan(lan_ifname, atoi(value)); /* Check if we do need to do ifconfig */ if (ifconfig_get(lan_ifname, &flags, &addr, &netmask) == 0) { inet_aton(nvram_safe_get("lan_ipaddr"), &in_addr); inet_aton(nvram_safe_get("lan_netmask"), &in_netmask); if ((flags & IFUP) && addr == in_addr.s_addr && netmask == in_netmask.s_addr) goto done; } ifconfig(lan_ifname, IFUP, nvram_safe_get("lan_ipaddr"), nvram_safe_get("lan_netmask")); lan_up(lan_ifname); #ifdef __CONFIG_WPS__ start_wps(); #endif done: dprintf("done\n"); return 0; }