int main(int argc, char** argv){ char buf[BUFLEN]; char *dev = calloc(10, 1); struct netdev netdev; CLEAR(buf); tun_init(dev); netdev_init(&netdev, "10.0.0.4", "00:0c:29:6d:50:25"); arp_init(); while(1) { if (tun_read(buf, BUFLEN) < 0) { print_error("ERR: Read from tun_fd: %s\n", strerror(errno)); } print_hexdump(buf, BUFLEN); struct eth_hdr *hdr = init_eth_hdr(buf); handle_frame(&netdev, hdr); } }
/*---------------------------------------------------------------------------*/ PROCESS_THREAD(border_router_process, ev, data) { static struct etimer et; rpl_dag_t *dag; PROCESS_BEGIN(); prefix_set = 0; PROCESS_PAUSE(); PRINTF("RPL-Border router started\n"); slip_config_handle_arguments(contiki_argc, contiki_argv); /* tun init is also responsible for setting up the SLIP connection */ tun_init(); while(!mac_set) { etimer_set(&et, CLOCK_SECOND); request_mac(); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); } if(slip_config_ipaddr != NULL) { uip_ipaddr_t prefix; if(uiplib_ipaddrconv((const char *)slip_config_ipaddr, &prefix)) { PRINTF("Setting prefix "); PRINT6ADDR(&prefix); PRINTF("\n"); set_prefix_64(&prefix); } else { PRINTF("Parse error: %s\n", slip_config_ipaddr); exit(0); } } dag = rpl_set_root(RPL_DEFAULT_INSTANCE,(uip_ip6addr_t *)dag_id); if(dag != NULL) { rpl_set_prefix(dag, &prefix, 64); PRINTF("created a new RPL dag\n"); } #if DEBUG print_local_addresses(); #endif /* The border router runs with a 100% duty cycle in order to ensure high packet reception rates. */ NETSTACK_MAC.off(1); while(1) { etimer_set(&et, CLOCK_SECOND * 2); PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)); /* do anything here??? */ } PROCESS_END(); }
int main(int argc, char ** argv) { char device[256]; strcpy(device, "xbee_pro868"); int ret = tun_init(device); printf("Created device %d %s\n", ret, device); sleep(120); }
int main(int argc, char const *argv[]){ struct phys_dev* physd; struct tun_dev* tund; // Init gums before devices (for gum adding and map initializing) init_gums(); tund = tun_init(); physd = phys_init(); init_bridge(physd, tund); pause(); return 0; }
void netdev_init(char *addr, char *hwaddr) { struct netdev *dev = &netdev; CLEAR(*dev); dev->buflen = 512; if (inet_pton(AF_INET, addr, &dev->addr) != 1) { perror("ERR: Parsing inet address failed\n"); exit(1); } sscanf(hwaddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &dev->hwaddr[0], &dev->hwaddr[1], &dev->hwaddr[2], &dev->hwaddr[3], &dev->hwaddr[4], &dev->hwaddr[5]); dev->tundev = calloc(10, 1); tun_init(dev->tundev); }
int init_module(void) { return tun_init(); }