static uint8_t network_send(void) { #if TCPDUMP printf_P(PSTR("OUT: ")); tcpdump(uip_buf, uip_len); #endif #if CONFIG_DRIVERS_ENC28J60 if (uip_len <= UIP_LLH_LEN + 40) { enc28j60PacketSend( uip_len, (uint8_t *)uip_buf, 0, 0); } else { enc28j60PacketSend( 54, (uint8_t *)uip_buf, uip_len - UIP_LLH_LEN - 40, (uint8_t*)uip_appdata); } #endif #if CONFIG_DRIVERS_ENC424J600 enc424j600PacketSend(uip_len, (uint8_t *)uip_buf); #endif uip_len = 0; return 0; }
static err_t loopif_output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) { struct pbuf *q, *r; char *ptr; void **arg; #if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) tcpdump(p); #endif /* LWIP_DEBUG && LWIP_TCPDUMP */ r = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); if (r != NULL) { ptr = r->payload; for(q = p; q != NULL; q = q->next) { memcpy(ptr, q->payload, q->len); ptr += q->len; } arg = mem_malloc( sizeof( void *[2])); if( NULL == arg ) { return ERR_MEM; } arg[0] = netif; arg[1] = r; /** * workaround (patch #1779) to try to prevent bug #2595: * When connecting to "localhost" with the loopif interface, * tcp_output doesn't get the opportunity to finnish sending the * segment before tcp_process gets it, resulting in tcp_process * referencing pcb->unacked-> which still is NULL. * * TODO: Is there still a race condition here? Leon */ sys_timeout( 1, loopif_input, arg ); return ERR_OK; } return ERR_MEM; }
static uint16_t network_read(void) { uint16_t len; #if CONFIG_DRIVERS_ENC28J60 len = enc28j60PacketReceive(UIP_BUFSIZE, (uint8_t *)uip_buf); #endif #if CONFIG_DRIVERS_ENC424J600 len = enc424j600PacketReceive(UIP_BUFSIZE, (uint8_t *)uip_buf); #endif #if TCPDUMP if (len > 0) { printf_P(PSTR("IN: ")); tcpdump(uip_buf, len); } #endif return len; }
int main(int argc, char **argv) { int ret = EXIT_FAILURE; char *mesh_iface = mesh_dfl_iface; if ((argc > 1) && (strcmp(argv[1], "-m") == 0)) { if (argc < 3) { printf("Error - the option '-m' needs a parameter\n"); goto err; } mesh_iface = argv[2]; argv += 2; argc -= 2; } if (argc < 2) { printf("Error - no command specified\n"); goto err; } if (strcmp(argv[1], "-h") == 0) goto err; if (strcmp(argv[1], "-v") == 0) { printf("batctl %s [batman-adv: ", SOURCE_VERSION); ret = read_file("", module_ver_path, USE_READ_BUFF | SILENCE_ERRORS, 0, 0); if ((line_ptr) && (line_ptr[strlen(line_ptr) - 1] == '\n')) line_ptr[strlen(line_ptr) - 1] = '\0'; if (ret == EXIT_SUCCESS) printf("%s]\n", line_ptr); else printf("module not loaded]\n"); free(line_ptr); exit(EXIT_SUCCESS); } /* TODO: remove this generic check here and move it into the individual functions */ /* check if user is root */ if ((strcmp(argv[1], "bisect") != 0) && ((getuid()) || (getgid()))) { fprintf(stderr, "Error - you must be root to run '%s' !\n", argv[0]); exit(EXIT_FAILURE); } if ((strcmp(argv[1], "ping") == 0) || (strcmp(argv[1], "p") == 0)) { ret = ping(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "traceroute") == 0) || (strcmp(argv[1], "tr") == 0)) { ret = traceroute(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "tcpdump") == 0) || (strcmp(argv[1], "td") == 0)) { ret = tcpdump(argc - 1, argv + 1); } else if ((strcmp(argv[1], "interface") == 0) || (strcmp(argv[1], "if") == 0)) { ret = interface(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "originators") == 0) || (strcmp(argv[1], "o") == 0)) { ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, DEBUG_ORIGINATORS, originators_usage); } else if ((strcmp(argv[1], "translocal") == 0) || (strcmp(argv[1], "tl") == 0)) { ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, DEBUG_TRANSTABLE_LOCAL, trans_local_usage); } else if ((strcmp(argv[1], "transglobal") == 0) || (strcmp(argv[1], "tg") == 0)) { ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, DEBUG_TRANSTABLE_GLOBAL, trans_global_usage); } else if ((strcmp(argv[1], "softif_neigh") == 0) || (strcmp(argv[1], "sn") == 0)) { ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, DEBUG_SOFTIF_NEIGH, softif_neigh_usage); } else if ((strcmp(argv[1], "loglevel") == 0) || (strcmp(argv[1], "ll") == 0)) { ret = handle_loglevel(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "log") == 0) || (strcmp(argv[1], "l") == 0)) { ret = log_print(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "interval") == 0) || (strcmp(argv[1], "it") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_ORIG_INTERVAL, orig_interval_usage, NULL); } else if ((strcmp(argv[1], "vis_mode") == 0) || (strcmp(argv[1], "vm") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_VIS_MODE, vis_mode_usage, sysfs_param_server); } else if ((strcmp(argv[1], "vis_data") == 0) || (strcmp(argv[1], "vd") == 0)) { ret = vis_data(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "gw_mode") == 0) || (strcmp(argv[1], "gw") == 0)) { ret = handle_gw_setting(mesh_iface, argc - 1, argv + 1); } else if ((strcmp(argv[1], "gateways") == 0) || (strcmp(argv[1], "gwl") == 0)) { ret = handle_debug_table(mesh_iface, argc - 1, argv + 1, DEBUG_GATEWAYS, gateways_usage); } else if ((strcmp(argv[1], "aggregation") == 0) || (strcmp(argv[1], "ag") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_AGGR, aggregation_usage, sysfs_param_enable); } else if ((strcmp(argv[1], "bonding") == 0) || (strcmp(argv[1], "b") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_BONDING, bonding_usage, sysfs_param_enable); } else if ((strcmp(argv[1], "fragmentation") == 0) || (strcmp(argv[1], "f") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_FRAG, fragmentation_usage, sysfs_param_enable); } else if ((strcmp(argv[1], "ap_isolation") == 0) || (strcmp(argv[1], "ap") == 0)) { ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1, SYS_AP_ISOLA, ap_isolation_usage, sysfs_param_enable); } else if ((strcmp(argv[1], "bisect") == 0)) { ret = bisect(argc - 1, argv + 1); } else { printf("Error - no command specified\n"); print_usage(); } return ret; err: print_usage(); exit(EXIT_FAILURE); }
/*-----------------------------------------------------------------------------------*/ static void unixif_input_handler(void *data) { struct netif *netif; struct unixif *unixif; char buf[1532], *bufptr; int len, plen, rlen; struct pbuf *p, *q; netif = (struct netif *)data; unixif = (struct unixif *)netif->state; len = read(unixif->fd, &plen, sizeof(int)); if (len == -1) { perror("unixif_irq_handler: read"); abort(); } // printf("unixif_input_handler: len == %d plen == %d bytes | %x \n", len, plen, plen); // LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: len == %d plen == %d bytes\n", len, plen)); if (len == sizeof(int)) { if (plen < 20 || plen > 1500) { LWIP_DEBUGF(UNIXIF_DEBUG, ("plen %d!\n", plen)); return; } printf("[+] Reading IP-packet from lower socket\n"); len = read(unixif->fd, buf, plen); if (len == -1) { perror("unixif_irq_handler: read"); abort(); } // printf("unixif_irq_handler: read %d bytes\n", len); // LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: read %d bytes\n", len)); p = pbuf_alloc(PBUF_LINK, len, PBUF_POOL); if (p != NULL) { rlen = len; bufptr = buf; q = p; while (rlen > 0) { memcpy(q->payload, bufptr, rlen > q->len? q->len: rlen); rlen -= q->len; bufptr += q->len; q = q->next; } pbuf_realloc(p, len); LINK_STATS_INC(link.recv); tcpdump(p); // formated printout of packet payload int i=0; for(i=0; i < p->len; i++) { printf("%02x ", (*((char *)p->payload + i) & 0xff)); if (((i + 1) % 8) == 0) { printf("\n"); } } printf("\n"); // call input-handler of lwip netif->input(p, netif); } else { LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: could not allocate pbuf\n")); } } }