int16_t parse_cmd_netmask(char *cmd, char *output, uint16_t len) { uip_ipaddr_t netmask; while (*cmd == ' ') cmd++; #ifndef DISABLE_IPCONF_SUPPORT #if !UIP_CONF_IPV6 && !defined(BOOTP_SUPPORT) if (*cmd != '\0') { /* try to parse ip */ if (parse_ip (cmd, &netmask)) return ECMD_ERR_PARSE_ERROR; eeprom_save(netmask, &netmask, IPADDR_LEN); eeprom_update_chksum(); return ECMD_FINAL_OK; } else #endif /* !UIP_CONF_IPV6 and !BOOTP_SUPPORT */ #endif /* DISABLE_IPCONF_SUPPORT */ { uip_getnetmask(&netmask); return ECMD_FINAL(print_ipaddr(&netmask, output, len)); } }
int vmm_netstack_get_ipmask(u8 *addr) { uip_ipaddr_t ipaddr; uip_getnetmask(ipaddr); memcpy(addr, ipaddr, 4); return VMM_OK; }
///////////////////////////////////////////////////////////////////////////// // Prints current IP settings ///////////////////////////////////////////////////////////////////////////// static s32 UIP_TASK_SendDebugMessage_IP(void) { uip_ipaddr_t ipaddr; uip_gethostaddr(&ipaddr); #if DEBUG_VERBOSE_LEVEL >= 1 UIP_TASK_MUTEX_MIDIOUT_TAKE; DEBUG_MSG("[UIP_TASK] IP address: %d.%d.%d.%d\n", uip_ipaddr1(ipaddr), uip_ipaddr2(ipaddr), uip_ipaddr3(ipaddr), uip_ipaddr4(ipaddr)); uip_ipaddr_t netmask; uip_getnetmask(&netmask); DEBUG_MSG("[UIP_TASK] Netmask: %d.%d.%d.%d\n", uip_ipaddr1(netmask), uip_ipaddr2(netmask), uip_ipaddr3(netmask), uip_ipaddr4(netmask)); uip_ipaddr_t draddr; uip_getdraddr(&draddr); DEBUG_MSG("[UIP_TASK] Default Router (Gateway): %d.%d.%d.%d\n", uip_ipaddr1(draddr), uip_ipaddr2(draddr), uip_ipaddr3(draddr), uip_ipaddr4(draddr)); UIP_TASK_MUTEX_MIDIOUT_GIVE; #endif return 0; // no error }
s32 SEQ_TERMINAL_PrintNetworkInfo(void *_output_function) { void (*out)(char *format, ...) = _output_function; MUTEX_MIDIOUT_TAKE; #if defined(MIOS32_FAMILY_EMULATION) out("No network informations available in emulation!"); #else out("MBHP_ETH module connected: %s", UIP_TASK_NetworkDeviceAvailable() ? "yes" : "no"); if( !UIP_TASK_NetworkDeviceAvailable() ) { out("Please reboot your MIDIbox SEQ to restart module detection! (or just type \"reset\")"); } else { out("Ethernet services running: %s", UIP_TASK_ServicesRunning() ? "yes" : "no"); out("DHCP: %s", UIP_TASK_DHCP_EnableGet() ? "enabled" : "disabled"); if( UIP_TASK_DHCP_EnableGet() && !UIP_TASK_ServicesRunning() ) { out("IP address: not available yet"); out("Netmask: not available yet"); out("Default Router (Gateway): not available yet"); } else { uip_ipaddr_t ipaddr; uip_gethostaddr(&ipaddr); out("IP address: %d.%d.%d.%d", uip_ipaddr1(ipaddr), uip_ipaddr2(ipaddr), uip_ipaddr3(ipaddr), uip_ipaddr4(ipaddr)); uip_ipaddr_t netmask; uip_getnetmask(&netmask); out("Netmask: %d.%d.%d.%d", uip_ipaddr1(netmask), uip_ipaddr2(netmask), uip_ipaddr3(netmask), uip_ipaddr4(netmask)); uip_ipaddr_t draddr; uip_getdraddr(&draddr); out("Default Router (Gateway): %d.%d.%d.%d", uip_ipaddr1(draddr), uip_ipaddr2(draddr), uip_ipaddr3(draddr), uip_ipaddr4(draddr)); } int con; for(con=0; con<OSC_SERVER_NUM_CONNECTIONS; ++con) { u32 osc_remote_ip = OSC_SERVER_RemoteIP_Get(con); out("OSC%d Remote address: %d.%d.%d.%d", con+1, (osc_remote_ip>>24)&0xff, (osc_remote_ip>>16)&0xff, (osc_remote_ip>>8)&0xff, (osc_remote_ip>>0)&0xff); out("OSC%d Remote port: %d", con+1, OSC_SERVER_RemotePortGet(con)); out("OSC%d Local port: %d", con+1, OSC_SERVER_LocalPortGet(con)); } } #endif MUTEX_MIDIOUT_GIVE; return 0; // no error }
s32 UIP_TASK_EffectiveNetmaskGet(void) { uip_ipaddr_t ipaddr; uip_getnetmask(&ipaddr); return (uip_ipaddr1(ipaddr) << 24) | (uip_ipaddr2(ipaddr) << 16) | (uip_ipaddr3(ipaddr) << 8) | (uip_ipaddr4(ipaddr) << 0); }
boolean Server::clientIsLocal() { // Check if there is a current connection if (uip_conn != NULL) { // Check if the remote host is local to the server uip_ipaddr_t hostaddr, mask; // Get the server's address uip_gethostaddr(&hostaddr); // Get the subnet mask uip_getnetmask(&mask); // Compare with the client's address return uip_ipaddr_maskcmp(&hostaddr, uip_conn->ripaddr, &mask); } return false; }
// wype³nij podan¹ pamiêæ danymi konfiguracyjnymi unsigned int udp_config_fill(unsigned char* data) { // struktury danych konfiguracyjnych udp_config_info *info = (udp_config_info*) data; udp_config_info_extra *extra = (udp_config_info_extra*) (info->extra); // konfiguracja struct rs_current_setup_t *rs_setup = rs_get_setup(); config_t* conf = config_get(); // informacje o sprzêcie info->type = UDP_CONFIG_DEVICE_TYPE; // id i flagi informacyjne info->flags = server_state; // nazwa memcpy(info->name, conf->name, 16); // IP info->eth_hardware = UDP_CONFIG_ETH_HARDWARE; uip_gethostaddr( ((u16_t*) &(info->ip)) ); uip_getdraddr( ((u16_t*) &(info->gate)) ); uip_getnetmask( ((u16_t*) &(info->mask)) ); // wersja oprogramowania (0.9) info->rev_major = 0; info->rev_minor = 9; // // extra // // tryb pracy extra->mode = conf->mode; memcpy(extra->server_ip, conf->server_ip, 4); // ustawienia COM extra->rs_baud = rs_setup->baud; extra->rs_data_bits = rs_setup->data_bits; extra->rs_parity_bits = rs_setup->parity_bits; extra->rs_stop_bits = rs_setup->stop_bits; // zwróæ rozmiar danych konfiguracyjnych return UDP_CONFIG_INFO_SIZE + UDP_CONFIG_INFO_EXTRA_SIZE; }
void tapInit() { struct sigaction sig; int flags; #if !NETSTACK_CONF_WITH_IPV6 uip_ipaddr_t ip; #endif char ifconfig[80]; tap = open("/dev/tap0", O_RDWR); P_ASSERT("tap0", tap != -1); #if NETSTACK_CONF_WITH_IPV6 sprintf (ifconfig, "ifconfig tap0 inet6 -ifdisabled up"); #else uip_getdraddr(&ip); sprintf (ifconfig, "ifconfig tap0 %d.%d.%d.%d ", ip.u8[0], ip.u8[1], ip.u8[2], ip.u8[3]); uip_getnetmask(&ip); sprintf (ifconfig + strlen(ifconfig), "netmask %d.%d.%d.%d up", ip.u8[0], ip.u8[1], ip.u8[2], ip.u8[3]); #endif system(ifconfig); memset(&sig, '\0', sizeof(sig)); sig.sa_sigaction = ioReady; sig.sa_flags = SA_RESTART | SA_SIGINFO; sigaction(SIGIO, &sig, NULL); fcntl(tap, F_SETOWN, getpid()); flags = fcntl(tap, F_GETFL, 0); fcntl(tap, F_SETFL, flags | O_ASYNC | O_NONBLOCK); }
/*-----------------------------------------------------------------------------------*/ static void makestrings(void) { uip_ipaddr_t addr, *addrptr; uip_gethostaddr(&addr); makeaddr(&addr, ipaddr); uip_getnetmask(&addr); makeaddr(&addr, netmask); uip_getdraddr(&addr); makeaddr(&addr, gateway); #if WITH_DNS addrptr = resolv_getserver(); if(addrptr != NULL) { makeaddr(addrptr, dnsserver); } #endif /* WITH_DNS */ }
///////////////////////////////////////////////////////////////////////////// // Prints current IP settings ///////////////////////////////////////////////////////////////////////////// static s32 UIP_TASK_SendDebugMessage_IP(void) { uip_ipaddr_t ipaddr; uip_gethostaddr(&ipaddr); MIOS32_MIDI_SendDebugMessage("[UIP_TASK] IP address: %d.%d.%d.%d\n", uip_ipaddr1(ipaddr), uip_ipaddr2(ipaddr), uip_ipaddr3(ipaddr), uip_ipaddr4(ipaddr)); uip_ipaddr_t netmask; uip_getnetmask(&netmask); MIOS32_MIDI_SendDebugMessage("[UIP_TASK] Netmask: %d.%d.%d.%d\n", uip_ipaddr1(netmask), uip_ipaddr2(netmask), uip_ipaddr3(netmask), uip_ipaddr4(netmask)); uip_ipaddr_t draddr; uip_getdraddr(&draddr); MIOS32_MIDI_SendDebugMessage("[UIP_TASK] Default Router (Gateway): %d.%d.%d.%d\n", uip_ipaddr1(draddr), uip_ipaddr2(draddr), uip_ipaddr3(draddr), uip_ipaddr4(draddr)); return 0; // no error }
/** uIP stack application callback for the DHCP server. This function must be called each time the TCP/IP stack * needs a UDP packet to be processed. */ void DHCPServerApp_Callback(void) { DHCP_Header_t* const AppData = (DHCP_Header_t*)uip_appdata; uint16_t AppDataSize = 0; /* Only process when new data arrives - don't retransmit lost packets */ if (uip_newdata()) { /* Get the DHCP message type (if present), otherwise early-abort */ uint8_t DHCPMessageType; if (!(DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_MSG_TYPE, &DHCPMessageType))) return; uip_ipaddr_t Netmask, GatewayIPAddress, PreferredClientIP; struct uip_eth_addr RemoteMACAddress; uint32_t TransactionID; /* Get configured network mask, gateway IP and extract out DHCP transaction ID and remote IP */ uip_getnetmask(&Netmask); uip_getdraddr(&GatewayIPAddress); memcpy(&RemoteMACAddress, &AppData->ClientHardwareAddress, sizeof(struct uip_eth_addr)); TransactionID = AppData->TransactionID; /* Try to extract out the client's preferred IP address if it is indicated in the packet */ if (!(DHCPCommon_GetOption(AppData->Options, DHCP_OPTION_REQ_IPADDR, &PreferredClientIP))) memcpy(&PreferredClientIP, &uip_all_zeroes_addr, sizeof(uip_ipaddr_t)); switch (DHCPMessageType) { case DHCP_DISCOVER: /* If no preference was made or the preferred IP is already taken, find a new address */ if (DHCPServerApp_CheckIfIPLeased(&PreferredClientIP)) DHCPServerApp_GetUnleasedIP(&PreferredClientIP); /* Create a new DHCP OFFER packet with the offered IP address */ AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_OFFER, &RemoteMACAddress, &PreferredClientIP, TransactionID); /* Add network mask and router information to the list of DHCP OFFER packet options */ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_SUBNET_MASK, sizeof(uip_ipaddr_t), &Netmask); AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_ROUTER, sizeof(uip_ipaddr_t), &GatewayIPAddress); /* Send the DHCP OFFER packet */ uip_poll_conn(BroadcastConnection); memcpy(&uip_udp_conn->ripaddr, &uip_broadcast_addr, sizeof(uip_ipaddr_t)); uip_udp_send(AppDataSize); break; case DHCP_REQUEST: /* Check to see if the requested IP address has already been leased to a client */ if (!(DHCPServerApp_CheckIfIPLeased(&PreferredClientIP))) { /* Create a new DHCP ACK packet to accept the IP address lease */ AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_ACK, &RemoteMACAddress, &PreferredClientIP, TransactionID); /* Add network mask and router information to the list of DHCP ACK packet options */ AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_SUBNET_MASK, sizeof(uip_ipaddr_t), &Netmask); AppDataSize += DHCPCommon_SetOption(AppData->Options, DHCP_OPTION_ROUTER, sizeof(uip_ipaddr_t), &GatewayIPAddress); /* Mark the requested IP as leased to a client */ DHCPServerApp_LeaseIP(&PreferredClientIP); } else { /* Create a new DHCP NAK packet to reject the requested allocation */ AppDataSize += DHCPServerApp_FillDHCPHeader(AppData, DHCP_NAK, &RemoteMACAddress, &uip_all_zeroes_addr, TransactionID); } /* Send the DHCP ACK or NAK packet */ uip_poll_conn(BroadcastConnection); memcpy(&uip_udp_conn->ripaddr, &uip_broadcast_addr, sizeof(uip_ipaddr_t)); uip_udp_send(AppDataSize); break; case DHCP_RELEASE: /* Mark the IP address as released in the allocation table */ DHCPServerApp_UnleaseIP(&uip_udp_conn->ripaddr); break; } } }
/*---------------------------------------------------------------------------*/ int main(void) { #if UIP_CONF_IPV6 /* A hard coded address overrides the stack default MAC address to allow multiple instances. * uip6.c defines it as {0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of [fe80::206:98ff:fe00:232] * We make it simpler, {0x02,0x00,0x00 + the last three bytes of the hard coded address (if any are nonzero). * HARD_CODED_ADDRESS can be defined in the contiki-conf.h file, or here to allow quick builds using different addresses. * If HARD_CODED_ADDRESS has a prefix it also applied, unless built as a RPL end node. * E.g. bbbb::12:3456 becomes fe80::ff:fe12:3456 and prefix bbbb::/64 if non-RPL * ::10 becomes fe80::ff:fe00:10 and prefix awaits RA or RPL formation * bbbb:: gives an address of bbbb::206:98ff:fe00:232 if non-RPL */ //#define HARD_CODED_ADDRESS "bbbb::20" #ifdef HARD_CODED_ADDRESS { uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if ((ipaddr.u8[13]!=0) || (ipaddr.u8[14]!=0) || (ipaddr.u8[15]!=0)) { if (sizeof(uip_lladdr)==6) { //Minimal-net uses ethernet MAC uip_lladdr.addr[0]=0x02;uip_lladdr.addr[1]=0;uip_lladdr.addr[2]=0; uip_lladdr.addr[3]=ipaddr.u8[13];; uip_lladdr.addr[4]=ipaddr.u8[14]; uip_lladdr.addr[5]=ipaddr.u8[15]; } } } #endif #endif process_init(); /* procinit_init initializes RPL which sets a ctimer for the first DIS */ /* We must start etimers and ctimers,before calling it */ process_start(&etimer_process, NULL); ctimer_init(); procinit_init(); autostart_start(autostart_processes); #if RPL_BORDER_ROUTER process_start(&border_router_process, NULL); printf("Border Router Process started\n"); #elif UIP_CONF_IPV6_RPL printf("RPL enabled\n"); #endif /* Set default IP addresses if not specified */ #if !UIP_CONF_IPV6 uip_ipaddr_t addr; uip_gethostaddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,1); } printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_getnetmask(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 255,0,0,0); uip_setnetmask(&addr); } printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_getdraddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,100); uip_setdraddr(&addr); } printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); #else /* UIP_CONF_IPV6 */ #if !UIP_CONF_IPV6_RPL #ifdef HARD_CODED_ADDRESS uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if ((ipaddr.u16[0]!=0) || (ipaddr.u16[1]!=0) || (ipaddr.u16[2]!=0) || (ipaddr.u16[3]!=0)) { #if UIP_CONF_ROUTER uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0); #else /* UIP_CONF_ROUTER */ uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0); #endif /* UIP_CONF_ROUTER */ #if !UIP_CONF_IPV6_RPL uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); #endif } #endif /* HARD_CODED_ADDRESS */ #endif #if !RPL_BORDER_ROUTER //Border router process prints addresses later { uint8_t i; for (i=0;i<UIP_DS6_ADDR_NB;i++) { if (uip_ds6_if.addr_list[i].isused) { printf("IPV6 Addresss: ");sprint_ip6(uip_ds6_if.addr_list[i].ipaddr);printf("\n"); } } } #endif #endif /* !UIP_CONF_IPV6 */ /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); while(1) { fd_set fds; int n; struct timeval tv; n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); select(1, &fds, NULL, NULL, &tv); if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } etimer_request_poll(); } return 0; }
/*---------------------------------------------------------------------------*/ int main(void) { process_init(); procinit_init(); ctimer_init(); autostart_start(autostart_processes); /* Set default IP addresses if not specified */ #if !UIP_CONF_IPV6 uip_ipaddr_t addr; uip_gethostaddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,1); } printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_getnetmask(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 255,0,0,0); uip_setnetmask(&addr); } printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_getdraddr(&addr); if (addr.u8[0]==0) { uip_ipaddr(&addr, 10,1,1,100); uip_setdraddr(&addr); } printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); #else /* !UIP_CONF_IPV6 */ uip_ipaddr_t ipaddr; uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); uip_netif_addr_autoconf_set(&ipaddr, &uip_lladdr); uip_netif_addr_add(&ipaddr, 16, 0, TENTATIVE); printf("IP6 Address: ");sprint_ip6(ipaddr);printf("\n"); #endif /* !UIP_CONF_IPV6 */ /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); while(1) { fd_set fds; int n; struct timeval tv; n = process_run(); /* if(n > 0) { printf("%d processes in queue\n"); }*/ tv.tv_sec = 0; tv.tv_usec = 1; FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); select(1, &fds, NULL, NULL, &tv); if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } etimer_request_poll(); } return 0; }
// get the configured netmask static unsigned short function_get_configured_mask(char* buffer, int bufsize) { u8_t adr[4]; uip_getnetmask(adr); return snprintf_P(buffer, bufsize, tcp_address_formatter,config.netmask[0],config.netmask[1],config.netmask[2],config.netmask[3]); }
// get the current netmask static unsigned short function_get_current_mask(char* buffer, int bufsize) { u8_t adr[4]; uip_getnetmask(adr); return snprintf_P(buffer, bufsize, tcp_address_formatter,adr[0],adr[1],adr[2],adr[3]); }
/*---------------------------------------------------------------------------*/ int main(void) { clock_init(); #if UIP_CONF_IPV6 /* A hard coded address overrides the stack default MAC address to allow multiple instances. uip6.c defines it as {0x00,0x06,0x98,0x00,0x02,0x32} giving an ipv6 address of [fe80::206:98ff:fe00:232] We make it simpler, {0x02,0x00,0x00 + the last three bytes of the hard coded address (if any are nonzero). HARD_CODED_ADDRESS can be defined in the contiki-conf.h file, or here to allow quick builds using different addresses. If HARD_CODED_ADDRESS has a prefix it also applied, unless built as a RPL end node. E.g. bbbb::12:3456 becomes fe80::ff:fe12:3456 and prefix bbbb::/64 if non-RPL ::10 becomes fe80::ff:fe00:10 and prefix awaits RA or RPL formation bbbb:: gives an address of bbbb::206:98ff:fe00:232 if non-RPL */ #ifdef HARD_CODED_ADDRESS { uip_ipaddr_t ipaddr; uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); if((ipaddr.u8[13] != 0) || (ipaddr.u8[14] != 0) || (ipaddr.u8[15] != 0)) { if(sizeof(uip_lladdr) == 6) { /* Minimal-net uses ethernet MAC */ uip_lladdr.addr[0] = 0x02; uip_lladdr.addr[1] = 0; uip_lladdr.addr[2] = 0; uip_lladdr.addr[3] = ipaddr.u8[13]; uip_lladdr.addr[4] = ipaddr.u8[14]; uip_lladdr.addr[5] = ipaddr.u8[15]; } } } #endif /* HARD_CODED_ADDRESS */ #endif /* UIP_CONF_IPV6 */ process_init(); /* procinit_init initializes RPL which sets a ctimer for the first DIS */ /* We must start etimers and ctimers,before calling it */ process_start(&etimer_process, NULL); ctimer_init(); #if RPL_BORDER_ROUTER process_start(&border_router_process, NULL); printf("Border Router Process started\n"); #elif UIP_CONF_IPV6_RPL printf("RPL enabled\n"); #endif procinit_init(); autostart_start(autostart_processes); /* Set default IP addresses if not specified */ #if !UIP_CONF_IPV6 { uip_ipaddr_t addr; uip_gethostaddr(&addr); if(addr.u8[0] == 0) { uip_ipaddr(&addr, 172,18,0,2); } printf("IP Address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_sethostaddr(&addr); uip_getnetmask(&addr); if(addr.u8[0] == 0) { uip_ipaddr(&addr, 255,255,0,0); uip_setnetmask(&addr); } printf("Subnet Mask: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); uip_getdraddr(&addr); if(addr.u8[0] == 0) { uip_ipaddr(&addr, 172,18,0,1); uip_setdraddr(&addr); } printf("Def. Router: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&addr)); } #else /* UIP_CONF_IPV6 */ #if !UIP_CONF_IPV6_RPL { uip_ipaddr_t ipaddr; #ifdef HARD_CODED_ADDRESS uiplib_ipaddrconv(HARD_CODED_ADDRESS, &ipaddr); #else uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0); #endif if((ipaddr.u16[0] != 0) || (ipaddr.u16[1] != 0) || (ipaddr.u16[2] != 0) || (ipaddr.u16[3] != 0)) { #if UIP_CONF_ROUTER if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0, 0, 0, 0)) { fprintf(stderr,"uip_ds6_prefix_add() failed.\n"); exit(EXIT_FAILURE); } #else /* UIP_CONF_ROUTER */ if(!uip_ds6_prefix_add(&ipaddr, UIP_DEFAULT_PREFIX_LEN, 0)) { fprintf(stderr,"uip_ds6_prefix_add() failed.\n"); exit(EXIT_FAILURE); } #endif /* UIP_CONF_ROUTER */ uip_ds6_set_addr_iid(&ipaddr, &uip_lladdr); uip_ds6_addr_add(&ipaddr, 0, ADDR_AUTOCONF); } } #endif /* !UIP_CONF_IPV6_RPL */ #endif /* !UIP_CONF_IPV6 */ // procinit_init(); // autostart_start(autostart_processes); /* Make standard output unbuffered. */ setvbuf(stdout, (char *)NULL, _IONBF, 0); printf("\n*******%s online*******\n",CONTIKI_VERSION_STRING); #if UIP_CONF_IPV6 && !RPL_BORDER_ROUTER /* Border router process prints addresses later */ { int i = 0; int interface_count = 0; for(i = 0; i < UIP_DS6_ADDR_NB; i++) { if(uip_ds6_if.addr_list[i].isused) { printf("IPV6 Addresss: "); sprint_ip6(uip_ds6_if.addr_list[i].ipaddr); printf("\n"); interface_count++; } } assert(0 < interface_count); } #endif while(1) { fd_set fds; int n; struct timeval tv; clock_time_t next_event; n = process_run(); next_event = etimer_next_expiration_time() - clock_time(); #if DEBUG_SLEEP if(n > 0) printf("sleep: %d events pending\n",n); else printf("sleep: next event @ T-%.03f\n",(double)next_event / (double)CLOCK_SECOND); #endif #ifdef __CYGWIN__ /* wpcap doesn't appear to support select, so * we can't idle the process on windows. */ next_event = 0; #endif if(next_event > (CLOCK_SECOND * 2)) next_event = CLOCK_SECOND * 2; tv.tv_sec = n ? 0 : (next_event / CLOCK_SECOND); tv.tv_usec = n ? 0 : ((next_event % 1000) * 1000); FD_ZERO(&fds); FD_SET(STDIN_FILENO, &fds); #ifdef __CYGWIN__ select(1, &fds, NULL, NULL, &tv); #else FD_SET(tapdev_fd(), &fds); if(0 > select(tapdev_fd() + 1, &fds, NULL, NULL, &tv)) { perror("Call to select() failed."); exit(EXIT_FAILURE); } #endif if(FD_ISSET(STDIN_FILENO, &fds)) { char c; if(read(STDIN_FILENO, &c, 1) > 0) { serial_line_input_byte(c); } } #ifdef __CYGWIN__ process_poll(&wpcap_process); #else process_poll(&tapdev_process); #endif etimer_request_poll(); } return 0; }