void cpu_switch_context_exit(void) { #ifdef NATIVE_AUTO_EXIT if (sched_num_threads <= 1) { DEBUG("cpu_switch_context_exit: last task has ended. exiting.\n"); real_exit(EXIT_SUCCESS); } #endif if (_native_in_isr == 0) { disableIRQ(); _native_in_isr = 1; native_isr_context.uc_stack.ss_sp = __isr_stack; native_isr_context.uc_stack.ss_size = SIGSTKSZ; native_isr_context.uc_stack.ss_flags = 0; makecontext(&native_isr_context, isr_cpu_switch_context_exit, 0); if (setcontext(&native_isr_context) == -1) { err(EXIT_FAILURE, "cpu_switch_context_exit: swapcontext"); } errx(EXIT_FAILURE, "1 this should have never been reached!!"); } else { isr_cpu_switch_context_exit(); } errx(EXIT_FAILURE, "3 this should have never been reached!!"); }
void exit(int status) { printf("We are in exit\n"); // char * value = getenv("PIPE_READ"); print_maps(); void __attribute__ ((noreturn)) (*real_exit)(int) = dlsym(RTLD_NEXT, "exit"); real_exit(status); }
/** * LPM_IDLE uses sleep() to wait for interrupts * LPM_OFF exits process * other modes not supported at the moment */ enum lpm_mode lpm_set(enum lpm_mode target) { enum lpm_mode last_lpm; //DEBUG("lpm_set(%i)\n", target); last_lpm = native_lpm; native_lpm = target; switch(native_lpm) { /* @contiki :-p */ case LPM_ON: break; case LPM_IDLE: //DEBUG("lpm_set(): pause()\n"); //pause(); _native_lpm_sleep(); break; /* XXX: unfinished modes: */ case LPM_SLEEP: /*TODO: implement*/ printf("XXX: lpm_set(): LPM_SLEEP not implemented\n"); //sigsuspend(); case LPM_POWERDOWN: /*TODO: implement*/ printf("XXX: lpm_set(): LPM_POWERDOWN not implemented\n"); //sigsuspend(); case LPM_OFF: printf("lpm_set(): exit()\n"); real_exit(EXIT_SUCCESS); default: DEBUG("XXX: unsupported power mode: %i\n", native_lpm); real_exit(EXIT_FAILURE); } return last_lpm; }
void vwarnx(const char *fmt, va_list args) { char *m; if ((m = make_message(fmt, args)) == NULL) { _native_write(STDERR_FILENO, "malloc\n", 7); real_exit(EXIT_FAILURE); } _native_write(STDERR_FILENO, _progname, strlen(_progname)); _native_write(STDERR_FILENO, ": ", 2); _native_write(STDERR_FILENO, m, strlen(m)); _native_write(STDERR_FILENO, "\n", 1); free(m); }
void exit(int status) throw() { print_trace ("%*sexit(%d)...\n", indent, "", status); indent+=2; /* call the real exit function */ real_exit (status); indent-=2; print_trace ("%*sexit(%d)\n", indent, "", status); }
static int _init(dev_eth_t *ethdev) { dev_eth_tap_t *dev = (dev_eth_tap_t*)ethdev; /* check device parametrs */ if (dev == NULL) { return -ENODEV; } char *name = dev->tap_name; #ifdef __MACH__ /* OSX */ char clonedev[255] = "/dev/"; /* XXX bad size */ strncpy(clonedev + 5, name, 250); #elif defined(__FreeBSD__) char clonedev[255] = "/dev/"; /* XXX bad size */ strncpy(clonedev + 5, name, 250); #else /* Linux */ struct ifreq ifr; const char *clonedev = "/dev/net/tun"; #endif /* initialize device descriptor */ dev->promiscous = 0; /* implicitly create the tap interface */ if ((dev->tap_fd = real_open(clonedev , O_RDWR)) == -1) { err(EXIT_FAILURE, "open(%s)", clonedev); } #if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */ struct ifaddrs *iflist; if (real_getifaddrs(&iflist) == 0) { for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) { if ((cur->ifa_addr->sa_family == AF_LINK) && (strcmp(cur->ifa_name, name) == 0) && cur->ifa_addr) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)cur->ifa_addr; memcpy(dev->addr, LLADDR(sdl), sdl->sdl_alen); break; } } real_freeifaddrs(iflist); } #else /* Linux */ memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, name, IFNAMSIZ); if (real_ioctl(dev->tap_fd, TUNSETIFF, (void *)&ifr) == -1) { _native_in_syscall++; warn("ioctl TUNSETIFF"); warnx("probably the tap interface (%s) does not exist or is already in use", name); real_exit(EXIT_FAILURE); } /* get MAC address */ memset(&ifr, 0, sizeof(ifr)); snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); if (real_ioctl(dev->tap_fd, SIOCGIFHWADDR, &ifr) == -1) { _native_in_syscall++; warn("ioctl SIOCGIFHWADDR"); if (real_close(dev->tap_fd) == -1) { warn("close"); } real_exit(EXIT_FAILURE); } memcpy(dev->addr, ifr.ifr_hwaddr.sa_data, NG_ETHERNET_ADDR_LEN); /* change mac addr so it differs from what the host is using */ dev->addr[5]++; #endif DEBUG("ng_tapnet_init(): dev->addr = %02x:%02x:%02x:%02x:%02x:%02x\n", dev->addr[0], dev->addr[1], dev->addr[2], dev->addr[3], dev->addr[4], dev->addr[5]); /* configure signal handler for fds */ register_interrupt(SIGIO, _tap_isr); #ifdef __MACH__ /* tuntap signalled IO is not working in OSX, * * check http://sourceforge.net/p/tuntaposx/bugs/17/ */ _sigio_child(dev); #else /* configure fds to send signals on io */ if (fcntl(dev->tap_fd, F_SETOWN, _native_pid) == -1) { err(EXIT_FAILURE, "ng_tapnet_init(): fcntl(F_SETOWN)"); } /* set file access mode to non-blocking */ if (fcntl(dev->tap_fd, F_SETFL, O_NONBLOCK | O_ASYNC) == -1) { err(EXIT_FAILURE, "ng_tabnet_init(): fcntl(F_SETFL)"); } #endif /* not OSX */ DEBUG("ng_tapnet: initialized.\n"); return 0; }
static int _init(netdev2_t *netdev) { DEBUG("%s:%s:%u\n", RIOT_FILE_RELATIVE, __func__, __LINE__); netdev2_tap_t *dev = (netdev2_tap_t*)netdev; /* check device parametrs */ if (dev == NULL) { return -ENODEV; } char *name = dev->tap_name; #ifdef __MACH__ /* OSX */ char clonedev[255] = "/dev/"; /* XXX bad size */ strncpy(clonedev + 5, name, 250); #elif defined(__FreeBSD__) char clonedev[255] = "/dev/"; /* XXX bad size */ strncpy(clonedev + 5, name, 250); #else /* Linux */ struct ifreq ifr; const char *clonedev = "/dev/net/tun"; #endif /* initialize device descriptor */ dev->promiscous = 0; /* implicitly create the tap interface */ if ((dev->tap_fd = real_open(clonedev, O_RDWR | O_NONBLOCK)) == -1) { err(EXIT_FAILURE, "open(%s)", clonedev); } #if (defined(__MACH__) || defined(__FreeBSD__)) /* OSX/FreeBSD */ struct ifaddrs *iflist; if (real_getifaddrs(&iflist) == 0) { for (struct ifaddrs *cur = iflist; cur; cur = cur->ifa_next) { if ((cur->ifa_addr->sa_family == AF_LINK) && (strcmp(cur->ifa_name, name) == 0) && cur->ifa_addr) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)cur->ifa_addr; memcpy(dev->addr, LLADDR(sdl), sdl->sdl_alen); break; } } real_freeifaddrs(iflist); } #else /* Linux */ memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, name, IFNAMSIZ); if (real_ioctl(dev->tap_fd, TUNSETIFF, (void *)&ifr) == -1) { _native_in_syscall++; warn("ioctl TUNSETIFF"); warnx("probably the tap interface (%s) does not exist or is already in use", name); real_exit(EXIT_FAILURE); } /* get MAC address */ memset(&ifr, 0, sizeof(ifr)); snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name); if (real_ioctl(dev->tap_fd, SIOCGIFHWADDR, &ifr) == -1) { _native_in_syscall++; warn("ioctl SIOCGIFHWADDR"); if (real_close(dev->tap_fd) == -1) { warn("close"); } real_exit(EXIT_FAILURE); } memcpy(dev->addr, ifr.ifr_hwaddr.sa_data, ETHERNET_ADDR_LEN); /* change mac addr so it differs from what the host is using */ dev->addr[5]++; #endif DEBUG("gnrc_tapnet_init(): dev->addr = %02x:%02x:%02x:%02x:%02x:%02x\n", dev->addr[0], dev->addr[1], dev->addr[2], dev->addr[3], dev->addr[4], dev->addr[5]); /* configure signal handler for fds */ native_async_read_setup(); native_async_read_add_handler(dev->tap_fd, NULL, _tap_isr); #ifdef MODULE_NETSTATS_L2 memset(&netdev->stats, 0, sizeof(netstats_t)); #endif DEBUG("gnrc_tapnet: initialized.\n"); return 0; }
void verrx(int eval, const char *fmt, va_list args) { vwarnx(fmt, args); real_exit(eval); }
int main(int argc, char **argv) { (void)argc; (void)argv; puts("Starting the RIOT\n"); int fd,tap_fd; const char *clonedev = "/dev/net/tun"; char *name = "tap0"; struct sockaddr_in6 servaddr, cliaddr; struct ifreq ifr; uint8_t buf[4096]; uint8_t scratch_raw[4096]; coap_rw_buffer_t scratch_buf = {scratch_raw, sizeof(scratch_raw)}; fd = socket(AF_INET6,SOCK_DGRAM,0);//Socket file descriptor init bzero(&servaddr,sizeof(servaddr)); servaddr.sin6_family = AF_INET6;//inet family servaddr.sin6_flowinfo = 0;//?? servaddr.sin6_addr.s6_addr[0] = (uint8_t)0x30;//IPv6 Address 1 servaddr.sin6_addr.s6_addr[1] = (uint8_t)0x00; servaddr.sin6_addr.s6_addr[2] = (uint8_t)0x00;//IPv6 Address 2 servaddr.sin6_addr.s6_addr[3] = (uint8_t)0x00; servaddr.sin6_addr.s6_addr[4] = (uint8_t)0x00;//IPv6 Address 3 servaddr.sin6_addr.s6_addr[5] = (uint8_t)0x00; servaddr.sin6_addr.s6_addr[6] = (uint8_t)0x00;//IPv6 Address 4 servaddr.sin6_addr.s6_addr[7] = (uint8_t)0x00; servaddr.sin6_addr.s6_addr[8] = (uint8_t)0x11;//IPv6 Address 5 servaddr.sin6_addr.s6_addr[9] = (uint8_t)0x11; servaddr.sin6_addr.s6_addr[10] = (uint8_t)0x22;//IPv6 Address 6 servaddr.sin6_addr.s6_addr[11] = (uint8_t)0x22; servaddr.sin6_addr.s6_addr[12] = (uint8_t)0x33;//IPv6 Address 7 servaddr.sin6_addr.s6_addr[13] = (uint8_t)0x33; servaddr.sin6_addr.s6_addr[14] = (uint8_t)0x00;//IPv6 Address 8 servaddr.sin6_addr.s6_addr[15] = (uint8_t)0x01; servaddr.sin6_port = htons(PORT); //PORT (5683) bind(fd,(struct sockaddr *)&servaddr, sizeof(servaddr)); //Set TAP device up, give it local ipv6 address /* implicitly create the tap interface */ if ((tap_fd = real_open(clonedev , O_RDWR)) == -1) { err(EXIT_FAILURE, "open(%s)", clonedev); } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, name, IFNAMSIZ); if (real_ioctl(tap_fd, TUNSETIFF, (void *)&ifr) == -1) { _native_in_syscall++; warn("ioctl TUNSETIFF"); warnx("probably the tap interface (%s) does not exist or is already in use", name); real_exit(EXIT_FAILURE); } //TODO Add Global IP endpoint_setup(); while(1) { int n, rc; socklen_t len = sizeof(cliaddr); coap_packet_t pkt; n = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&cliaddr, &len); //#ifdef DEBUG printf("Received: "); coap_dump(buf, n, true); printf("\n"); //#endif if (0 != (rc = coap_parse(&pkt, buf, n))) printf("Bad packet rc=%d\n", rc); else { size_t rsplen = sizeof(buf); coap_packet_t rsppkt; #ifdef DEBUG coap_dumpPacket(&pkt); #endif coap_handle_req(&scratch_buf, &pkt, &rsppkt); if (0 != (rc = coap_build(buf, &rsplen, &rsppkt))) printf("coap_build failed rc=%d\n", rc); else { #ifdef DEBUG printf("Sending: "); coap_dump(buf, rsplen, true); printf("\n"); #endif #ifdef DEBUG coap_dumpPacket(&rsppkt); #endif sendto(fd, buf, rsplen, 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr)); } } } }