int real_time_listen( serial_port_t const port, struct activity *activity, struct model const *const model ) { double elapsed; struct packet packet; struct timespec tic; char message[MSG_LEN]; struct calibr calibr[CONF_BAN_NUM_NODES]; if (calibration_table_read(FILE_CONF_CALIBRATION, calibr)) return EXIT_FAILURE; file_write_header(activity->files[FILE_RAW]); file_write_header(activity->files[FILE_HISTORY]); clock_gettime(CLOCK_MONOTONIC, &tic); while (time_stopwatch(tic, CONF_TIME_LISTENING, &elapsed)) { if (serial_port_read(port, message, sizeof(message))) return EXIT_FAILURE; file_write_raw(activity->files[FILE_RAW], message); if (packet_validate(message, &packet)) continue; packet.elapsed = elapsed; if (calibrate_packet(&packet, calibr, sizeof(calibr))) return EXIT_FAILURE; file_write_history(activity->files[FILE_HISTORY], packet); process_region(&packet, model); activity->window[packet.node_id - 1][packet.region - 1]++; } return EXIT_SUCCESS; }
static void paulosif_input (struct netif *netif) { struct genericif *genericif; struct eth_hdr *ethhdr; struct pbuf *p, *q = NULL, *r = NULL; int len; u16_t ether_type; genericif = netif->state; ioctl (genericif->fd, FIONREAD, &len); if (len <= 0) return; p = low_level_input (genericif); if (!p) { DEBUGF (TAPIF_DEBUG, ("paulosif_input: low_level_input returned NULL\n")); return; } ethhdr = p->payload; ether_type = ntohs (ethhdr->type); if (pppoe_input_callback && (ether_type == 0x8863 || ether_type == 0x8864)) { //printf ("paulosif_input: got PPPoE packet, %d bytes\n", (int) p->len); (*pppoe_input_callback) (pppoe_user_data, p, ether_type); pbuf_free (p); return; } if (packet_validate (p, netif, genericif)) { pbuf_free (p); return; } if (packet_filter_callback) { if ((*packet_filter_callback) (packet_filter_data, (unsigned char *) p->payload, (int) p->len)) { pbuf_free (p); return; } } switch (ether_type) { case ETHTYPE_IP: DEBUGF (TAPIF_DEBUG, ("paulosif_input: IP packet\n")); q = etharp_ip_input (netif, p); pbuf_header (p, -14); netif->input (p, netif); /* segfault */ break; case ETHTYPE_ARP: DEBUGF (TAPIF_DEBUG, ("paulosif_input: ARP packet\n")); q = etharp_arp_input (netif, genericif->ethaddr, p, &r); pbuf_free (p); break; default: pbuf_free (p); break; } if (q != NULL) { magic (q, PBUF_MAGIC); low_level_output (genericif, q); pbuf_free (q); /* free'd */ } if (r != NULL) { magic (r, PBUF_MAGIC); low_level_output (genericif, r); pbuf_free (r); /* free'd */ } }