void SetNullIP(const char *pcInterface) { struct bootp wlan_bootp_data; int j = 0; char ipadd[16]; char netmask[16] = "0.0.0.0"; char gateway[16]; char broadcast[16] = "255.255.255.255"; unsigned long ulIP = 0; httpIP2String(ulIP, ipadd); strcpy(gateway, ipadd); DownInterface(pcInterface); diag_printf("IP is %s, NetMask is %s, Gateway is %s,Broadcast is %s\n",ipadd,netmask,gateway,broadcast); build_bootp_record(&wlan_bootp_data, pcInterface, ipadd, netmask,broadcast,gateway,gateway); show_bootp(pcInterface, &wlan_bootp_data); if (!init_net(pcInterface, &wlan_bootp_data)) { diag_printf("failed for %s\n",pcInterface); } for(;j<5;j++) init_loopback_interface(0); }
// ------------------------------------------------------------------------ // The management thread function void dhcp_mgt_entry( cyg_addrword_t loop_on_failure ) { int j; while ( 1 ) { while ( 1 ) { cyg_semaphore_wait( &dhcp_needs_attention ); if ( ! dhcp_bind() ) // a lease expired break; // If we need to re-bind } dhcp_halt(); // tear everything down if ( !loop_on_failure ) return; // exit the thread/return init_all_network_interfaces(); // re-initialize for ( j = 0; j < CYGPKG_NET_NLOOP; j++ ) init_loopback_interface( j ); #ifdef CYGPKG_SNMPAGENT SnmpdShutDown(0); // Cycle the snmpd state #endif } }
void ServerStart(void) { int i, j; char *pcDocRoot = "./"; static int aiPort[] = {80, 0}; #ifndef WLAN FMI_CARD_DETECT_T card; #endif cyg_mutex_init(&g_ptmConfigParam); cyg_mutex_init(&g_ptmState); cyg_mutex_init(&g_ptmTimeSetting); cyg_mutex_init(&g_ptmWebCameraLog); tt_rmutex_init(&g_rmutex); { UINT32 uFlashTotal, uFlashFreeBegin, uFlashFreeEnd; GetFlashCapability(&uFlashTotal, &uFlashFreeBegin, &uFlashFreeEnd); diag_printf("Flash total: %d, free space [%d - %d]\n", uFlashTotal, uFlashFreeBegin, uFlashFreeEnd); } #ifndef WLAN /*init the sd card*/ //do {outpw (REG_CLKCON, inpw (REG_CLKCON) | FMICLK_EN); } while (0); fmiSetFMIReferenceClock(OPT_UPLL_OUT_CLOCK/3/1000); fsFixDriveNumber('D', 'C', 'Z'); fsInitFileSystem(); card.uCard = FMI_SD_CARD; // card type card.uGPIO = 4; // card detect GPIO pin card.uWriteProtect = 16; // card detect GPIO pin card.uInsert = 0; // 0/1 which one is insert card.nPowerPin = 12; // card power pin, -1 means no power pin card.bIsTFlashCard = FALSE; fmiSetCardDetection(&card); fmiInitSDDevice(); diag_printf("Init the SD Card ok!\n"); g_StreamServer_Buf = (char*)(g_StreamServer_Buf1); #endif #ifdef FILESYSTEM /* Check if disk need to be formatted. */ ipcCheckDisk( ); #endif /*register reset interrupt*/ InitResetGPIO(); // Set HIC ready outpw(REG_HICSR, inpw(REG_HICSR) & 0xFFFFFF7F); if (0) { int j = 0; for(;j<5;j++) init_loopback_interface(0); } /* 初始化camera的参数 */ ResetCameraParam(); /* 挂载需要额外处理的URL */ RegisterUrls(); //GetDHCPInfo(); /* 設置进入不同特权领域的提示语 */ httpSetAuthPrompt(CONFIG_LOGIN_PROMPT_USER, CONFIG_LOGIN_PROMPT_ADMIN, NULL); /* 选择从命令行或者配置参数中设定的http端口 */ for (i = 0; i < sizeof(g_ConfigParam.usHttpPort) / sizeof(unsigned short); i++) { if (g_ConfigParam.usHttpPort[i] == 0) g_ConfigParam.usHttpPort[i] = aiPort[i]; } for (i = 0, j = 0; i < sizeof(g_ConfigParam.usHttpPort) / sizeof(unsigned short); i++) { if (g_ConfigParam.usHttpPort[i] != 0) aiPort[j++] = g_ConfigParam.usHttpPort[i]; } aiPort[j] = 0; diag_printf("Port is %d,%d\n",aiPort[0],aiPort[1]); ResetOtherThread(); { cyg_thread_create(PTD_PRIORITY, &MctestThread, (cyg_addrword_t)aiPort, "ptdMctest", ptdMctest_stack, STACKSIZE2, &ptdMctest_handle, &g_ptdMctest); if ( ptdMctest_handle == NULL) { fprintf(stderr, "Thread for mctest creation failed!\n"); return; } cyg_thread_resume(ptdMctest_handle); } cyg_thread_set_priority(cyg_thread_self(), PTD_PRIORITY); // 开始http服务 httpdStartEx(pcDocRoot, aiPort,3600, 30 * 60 * 60 , 20, OnHttpInit, OnRequestBegin); }
void init_all_network_interfaces(void) { cyg_bool_t use_bootp; cyg_bool_t setup_network = false; in_addr_t local_ip_addr = 0; in_addr_t broadcast_addr = 0; in_addr_t server_addr = 0; in_addr_t gateway_addr = 0; in_addr_t network_mask = 0; char server_str[16]; char network_str[16]; char gateway_str[16]; char broadcast_str[16]; char ip_addr_str[16]; int i; int net_up = false; static volatile int in_init_all_network_interfaces = 0; cyg_scheduler_lock(); while ( in_init_all_network_interfaces ) { // Another thread is doing this... cyg_scheduler_unlock(); cyg_thread_delay( 10 ); cyg_scheduler_lock(); } in_init_all_network_interfaces = 1; cyg_scheduler_unlock(); #ifdef CYGHWR_NET_DRIVER_ETH0 // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootn", &setup_network, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); if (setup_network) { // Set defaults as appropriate use_bootp = true; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp", &use_bootp, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_localip_addr", &local_ip_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_localip_mask", &network_mask, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_mygateway_addr", &gateway_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_ubroadcast_addr", &broadcast_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_bootp_serverip_addr", &server_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); if (use_bootp) { // Perform a complete initialization, using BOOTP/DHCP eth0_up = true; //#ifdef CYGHWR_NET_DRIVER_ETH0_DHCP eth0_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease)) //#else //#ifdef CYGPKG_NET_DHCP // eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called //#endif // if (do_bootp(eth0_name, ð0_bootp_data)) //#endif { #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } else { printf("BOOTP/DHCP failed on eth0\n"); eth0_up = false; } } else { eth0_up = true; strncpy(ip_addr_str, inet_ntoa(*(struct in_addr *) &local_ip_addr), 16); strncpy(broadcast_str, inet_ntoa(*(struct in_addr *) &broadcast_addr), 16); strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 16); strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 16); strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 16); /* load flash configuration parameters */ build_bootp_record(ð0_bootp_data, eth0_name, ip_addr_str, network_str, broadcast_str, gateway_str, server_str); #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 setup_network = false; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootn", &setup_network, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); if (setup_network) { // Set defaults as appropriate use_bootp = true; // Fetch values from saved config data, if available CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp", &use_bootp, CYGNUM_FLASH_CFG_OP_CONFIG_BOOL); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_localip_addr", &local_ip_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_localip_mask", &network_mask, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_mygateway_addr", &gateway_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_ubroadcast_addr", &broadcast_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_c_bootp_serverip_addr", &server_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); if (use_bootp) { // Perform a complete initialization, using BOOTP/DHCP eth1_up = true; //#ifdef CYGHWR_NET_DRIVER_ETH1_DHCP eth1_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease)) //#else //#ifdef CYGPKG_NET_DHCP // eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called //#endif // if (do_bootp(eth1_name, ð1_bootp_data)) //#endif { #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } else { printf("BOOTP/DHCP failed on eth1\n"); eth1_up = false; } } else { eth1_up = true; strncpy(ip_addr_str, inet_ntoa(*(struct in_addr *) &local_ip_addr), 16); strncpy(broadcast_str, inet_ntoa(*(struct in_addr *) &broadcast_addr), 16); strncpy(gateway_str, inet_ntoa(*(struct in_addr *) &gateway_addr), 16); strncpy(network_str, inet_ntoa(*(struct in_addr *) &network_mask), 16); strncpy(server_str, inet_ntoa(*(struct in_addr *) &server_addr), 16); /* load flash configuration parameters */ build_bootp_record(ð1_bootp_data, eth1_name, ip_addr_str, network_str, broadcast_str, gateway_str, server_str); #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } } #endif #ifdef CYGHWR_NET_DRIVER_ETH0 if (eth0_up) { if (!init_net(eth0_name, ð0_bootp_data)) { printf("Network initialization failed for eth0\n"); eth0_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX if (!init_net_IPv6(eth0_name, ð0_bootp_data, string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth0\n"); eth0_up = false; // ??? } #endif if (eth0_up) { unsigned int length = 4; struct in_addr temp; diag_printf("\nIP: %s", inet_ntoa(eth0_bootp_data.bp_yiaddr)); get_bootp_option(ð0_bootp_data, TAG_SUBNET_MASK, (void *)&temp, &length); diag_printf("/%s", inet_ntoa(temp)); get_bootp_option(ð0_bootp_data, TAG_GATEWAY, (void *)&temp, &length); // diag_printf(", Gateway: %s\n", inet_ntoa(eth0_bootp_data.bp_giaddr)); diag_printf(", Gateway: %s\n", inet_ntoa(temp)); diag_printf("Server: %s", inet_ntoa(eth0_bootp_data.bp_siaddr)); net_up = true; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if (eth1_up) { if (!init_net(eth1_name, ð1_bootp_data)) { printf("Network initialization failed for eth1\n"); eth1_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX if (!init_net_IPv6(eth1_name, ð1_bootp_data, string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth1\n"); eth1_up = false; // ??? } #endif if (eth1_up) { unsigned int length = 4; struct in_addr temp; diag_printf("\nIP: %s", inet_ntoa(eth1_bootp_data.bp_yiaddr)); get_bootp_option(ð1_bootp_data, TAG_SUBNET_MASK, (void *)&temp, &length); diag_printf("/%s", inet_ntoa(temp)); get_bootp_option(ð1_bootp_data, TAG_GATEWAY, (void *)&temp, &length); // diag_printf(", Gateway: %s\n", inet_ntoa(eth1_bootp_data.bp_giaddr)); diag_printf(", Gateway: %s\n", inet_ntoa(temp)); diag_printf("Server: %s", inet_ntoa(eth1_bootp_data.bp_siaddr)); net_up = true; } } #endif #ifdef CYGPKG_NET_NLOOP #if 0 < CYGPKG_NET_NLOOP // Create a local IP Address for each of the DSP's */ for (i = 0; i < CYGPKG_NET_NLOOP; ++i) init_loopback_interface(i); #endif #endif #ifdef CYGOPT_NET_DHCP_DHCP_THREAD dhcp_start_dhcp_mgt_thread(); #endif #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD ipv6_start_routing_thread(); #endif #ifdef CYGPKG_NS_DNS_BUILD if (net_up) { struct in_addr dns_addr = {0}; int len; char *dns_domainname; CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_dns_ip", &dns_addr, CYGNUM_FLASH_CFG_OP_CONFIG_IP); cyg_dns_res_init(&dns_addr); CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, "app_dns_domain_name", &dns_domainname, CYGNUM_FLASH_CFG_OP_CONFIG_STRING); len = strlen(dns_domainname); setdomainname(dns_domainname,len); diag_printf(", DNS server IP: %s", inet_ntoa(*(struct in_addr *)&dns_addr)); } #endif if (!net_up) { diag_printf("Network Disabled"); } diag_printf("\n\n"); }
BOOL SetIP(enum SET_IP_STATE_E *pIPState) { enum SET_IP_STATE_E ipState; BOOL bOK = TRUE; int i; BOOL bEnable[2]; if (pIPState == NULL) pIPState = &ipState; bEnable[0] = g_ConfigParam.abAsNetEnable[0]; bEnable[1] = g_ConfigParam.abAsNetEnable[1]; #ifndef WLAN if (!bEnable[0] && !bEnable[1]) bEnable[0] = TRUE; #else if (!bEnable[0] && !bEnable[1]) bEnable[1] = TRUE; #endif for (i = sizeof(g_apcNetworkInterface) / sizeof(const char *) - 1; i >= 0; i--) { const char *pcInterface; if (!bEnable[i]) continue; pcInterface = g_apcNetworkInterface[i]; if (g_ConfigParam.aucIPAssignedWay[i] == IP_ASSIGNMENT_MANUALLY) { struct bootp wlan_bootp_data; int j = 0; char ipadd[16]; char netmask[16]; char gateway[16]; char broadcast[16]; httpIP2String(g_ConfigParam.ulAsIPAddress[i],ipadd); httpIP2String(g_ConfigParam.ulAsNetmask[i],netmask); httpIP2String(g_ConfigParam.ulAsGateway[i],gateway); httpIP2String((~g_ConfigParam.ulAsNetmask[i])|g_ConfigParam.ulAsIPAddress[i],broadcast); *pIPState = SET_IP__STATIC_IP_TRYING; DownInterface(pcInterface); diag_printf("IP is %s, NetMask is %s, Gateway is %s,Broadcast is %s\n",ipadd,netmask,gateway,broadcast); build_bootp_record(&wlan_bootp_data, pcInterface, ipadd, netmask,broadcast,gateway,gateway); show_bootp(pcInterface, &wlan_bootp_data); if (!init_net(pcInterface, &wlan_bootp_data)) { *pIPState = SET_IP__STATIC_IP_FAILED; diag_printf("failed for %s\n",pcInterface); } else *pIPState = SET_IP__STATIC_IP_OK; /* Set DNS server */ if (g_ConfigParam.aulAsDNS[0] != 0) { struct in_addr dns_server; dns_server.s_addr = (g_ConfigParam.aulAsDNS[0]); cyg_dns_res_init(&dns_server); } for(;j<5;j++) init_loopback_interface(0); } else { #ifndef WLAN //WRRunDHCPClient(pcInterface, TRUE); #else int j = 0; *pIPState = SET_IP__DHCP_TRYING; DownInterface(pcInterface); diag_printf("Set IP by dhcp\n"); g_WebCamState.bDHCP_Finished = FALSE; init_all_network_interfaces(); for(;j<5;j++) init_loopback_interface(0); if (wlan0_dhcpstate != DHCPSTATE_BOOTP_FALLBACK && wlan0_dhcpstate != DHCPSTATE_BOUND) { bOK = FALSE; SetRandomIP("wlan0"); *pIPState = SET_IP__DHCP_FAILED; } else *pIPState = SET_IP__DHCP_OK; g_WebCamState.bDHCP_Finished = TRUE; #endif } } /*display the ip address*/ { unsigned long ulIP; GetPubIPInfo(&ulIP, NULL, NULL, NULL); diag_printf("******************ip Address====%x\n", ulIP); if (bOK) { if (g_ConfigParam.ucWlanOperationMode == 1) /* Disable suspend in Ad-hoc mode */ g_netIsSuspendAllowed = FALSE; else g_netIsSuspendAllowed = TRUE; } diag_printf("bOK=%d\n", bOK); if (!bOK) return FALSE; else OnSetIP(); } return TRUE; }
// // Initialize network interface[s] using BOOTP/DHCP // void init_all_network_interfaces(void) { static volatile int in_init_all_network_interfaces = 0; #ifdef CYGPKG_IO_PCMCIA cyg_netdevtab_entry_t *t; #endif // CYGPKG_IO_PCMCIA #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD int rs_wait = 40; #endif cyg_scheduler_lock(); while ( in_init_all_network_interfaces ) { // Another thread is doing this... cyg_scheduler_unlock(); cyg_thread_delay( 10 ); cyg_scheduler_lock(); } in_init_all_network_interfaces = 1; cyg_scheduler_unlock(); #ifdef CYGHWR_NET_DRIVER_ETH0 if ( ! eth0_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth0")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth0'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth0'\n"); goto bail_eth0; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth0_up = true; #ifdef CYGHWR_NET_DRIVER_ETH0_DHCP eth0_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease)) #else #ifdef CYGPKG_NET_DHCP eth0_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth0_name, ð0_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH0_BOOTP_SHOW show_bootp(eth0_name, ð0_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth0\n"); eth0_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP) eth0_up = true; build_bootp_record(ð0_bootp_data, eth0_name, string(CYGHWR_NET_DRIVER_ETH0_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH0_ADDRS_SERVER)); show_bootp(eth0_name, ð0_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth0: #endif } #endif // CYGHWR_NET_DRIVER_ETH0 #ifdef CYGHWR_NET_DRIVER_ETH1 if ( ! eth1_up ) { // Make this call idempotent #ifdef CYGPKG_IO_PCMCIA if ((t = eth_drv_netdev("eth1")) != (cyg_netdevtab_entry_t *)NULL) { int tries = 0; while (t->status != CYG_NETDEVTAB_STATUS_AVAIL) { if (tries == 0) { diag_printf("... Waiting for PCMCIA device 'eth1'\n"); } if (++tries == 5) { diag_printf("... Giving up on PCMCIA device 'eth1'\n"); goto bail_eth1; } cyg_thread_delay(100); } } #endif // CYGPKG_IO_PCMCIA #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP // Perform a complete initialization, using BOOTP/DHCP eth1_up = true; #ifdef CYGHWR_NET_DRIVER_ETH1_DHCP eth1_dhcpstate = 0; // Says that initialization is external to dhcp if (do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease)) #else #ifdef CYGPKG_NET_DHCP eth1_dhcpstate = DHCPSTATE_BOOTP_FALLBACK; // so the dhcp machine does no harm if called #endif if (do_bootp(eth1_name, ð1_bootp_data)) #endif { #ifdef CYGHWR_NET_DRIVER_ETH1_BOOTP_SHOW show_bootp(eth1_name, ð1_bootp_data); #endif } else { diag_printf("BOOTP/DHCP failed on eth1\n"); eth1_up = false; } #elif defined(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP) eth1_up = true; build_bootp_record(ð1_bootp_data, eth1_name, string(CYGHWR_NET_DRIVER_ETH1_ADDRS_IP), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_NETMASK), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_BROADCAST), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_GATEWAY), string(CYGHWR_NET_DRIVER_ETH1_ADDRS_SERVER)); show_bootp(eth1_name, ð1_bootp_data); #endif #ifdef CYGPKG_IO_PCMCIA bail_eth1: #endif } #endif // CYGHWR_NET_DRIVER_ETH1 #ifdef CYGHWR_NET_DRIVER_ETH0 #ifndef CYGHWR_NET_DRIVER_ETH0_MANUAL if (eth0_up) { if (!init_net(eth0_name, ð0_bootp_data)) { diag_printf("Network initialization failed for eth0\n"); eth0_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX if (!init_net_IPv6(eth0_name, ð0_bootp_data, string(CYGHWR_NET_DRIVER_ETH0_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth0\n"); eth0_up = false; // ??? } #endif } #endif #endif #ifdef CYGHWR_NET_DRIVER_ETH1 #ifndef CYGHWR_NET_DRIVER_ETH1_MANUAL if (eth1_up) { if (!init_net(eth1_name, ð1_bootp_data)) { diag_printf("Network initialization failed for eth1\n"); eth1_up = false; } #ifdef CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX if (!init_net_IPv6(eth1_name, ð1_bootp_data, string(CYGHWR_NET_DRIVER_ETH1_IPV6_PREFIX))) { diag_printf("Static IPv6 network initialization failed for eth1\n"); eth1_up = false; // ??? } #endif } #endif #endif #ifdef CYGPKG_NET_NLOOP #if 0 < CYGPKG_NET_NLOOP { static int loop_init = 0; int i; if ( 0 == loop_init++ ) for ( i = 0; i < CYGPKG_NET_NLOOP; i++ ) init_loopback_interface( i ); } #endif #endif #ifdef CYGOPT_NET_DHCP_DHCP_THREAD dhcp_start_dhcp_mgt_thread(); #endif #ifdef CYGOPT_NET_IPV6_ROUTING_THREAD ipv6_start_routing_thread(); // Wait for router solicit process to happen. while (rs_wait-- && !cyg_net_get_ipv6_advrouter(NULL)) { cyg_thread_delay(10); } if (rs_wait == 0 ) { diag_printf("No router solicit received\n"); } else { // Give Duplicate Address Detection time to work cyg_thread_delay(200); } #endif #ifdef CYGDAT_NS_DNS_DEFAULT_SERVER cyg_dns_res_start(string(CYGDAT_NS_DNS_DEFAULT_SERVER)); #endif #ifdef CYGDAT_NS_DNS_DOMAINNAME_NAME #define _NAME string(CYGDAT_NS_DNS_DOMAINNAME_NAME) { const char buf[] = _NAME; int len = strlen(_NAME); setdomainname(buf,len); } #endif // Open the monitor to other threads. in_init_all_network_interfaces = 0; }
bool set_ip_address(char *pcInterface, unsigned long ulIP, unsigned long ulNetmask) { struct ifreq ifr; int fd; struct sockaddr_in *pAddr; int i; char mac[] = {0x00, 0x02, 0x13, 0x1a, 0x44, 0x78}; if (pcInterface == NULL) { fprintf(stderr, "illegal call function SetGeneralIP!\n"); return false; } if ((fd = socket(AF_INET,SOCK_DGRAM,0)) < 0) return false; strcpy(ifr.ifr_name, pcInterface); ifr.ifr_flags = IFF_UP | IFF_BROADCAST | IFF_RUNNING; if (ioctl(fd, SIOCSIFFLAGS, &ifr)) { diag_printf("SIOCSIFFLAGS error %x\n", errno); return false; } pAddr = (struct sockaddr_in *)&(ifr.ifr_addr); bzero(pAddr, sizeof(struct sockaddr_in)); pAddr->sin_addr.s_addr = ulIP; pAddr->sin_family = AF_INET; if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) { fprintf(stderr,"Set Ip Address error\n"); close(fd); return false; } pAddr = (struct sockaddr_in *)&(ifr.ifr_addr); bzero(pAddr, sizeof(struct sockaddr_in)); pAddr->sin_addr.s_addr = ulNetmask; pAddr->sin_family = AF_INET; if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) { fprintf(stderr,"Set netmask error\n"); close(fd); return false; } SetGateway(fd, pcInterface, inet_addr("10.130.1.254")); //set_lo_address(fd); for(; i<5; i++) init_loopback_interface(i); #if 0 memcpy((void*)ifr.ifr_hwaddr.sa_data, mac,6); if (ioctl(fd, SIOCSIFHWADDR, &ifr) < 0) { fprintf(stderr,"Set netmask error\n"); close(fd); return false; } #endif close(fd); return true; }