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); } }
static void parse_data(char* buf, int len) { int i; for (i=0; i<len; i++) { int8_t c = buf[i ]; switch (status) { case STA_UNINIT: if (c==SYNC_1) status = STA_GOT_SYNC_1; break; case STA_GOT_SYNC_1: if (c==SYNC_2) { status = STA_GOT_SYNC_2; idx = 0; } else status = STA_UNINIT; break; case STA_GOT_SYNC_2: frame_buf[idx] = c; idx++; if (idx == FRAME_LEN) { status = STA_UNINIT; handle_frame(); } break; } } }
/* * This is a callback which gets a packet from Tox core. * It checks for basic inconsistiencies and allocates the * protocol_frame structure. */ void parse_lossless_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data, size_t len, void *tmp) { protocol_frame *frame = NULL; if(len < PROTOCOL_BUFFER_OFFSET) { log_printf(L_WARNING, "Received too short data frame - only %d bytes, at least %d expected\n", len, PROTOCOL_BUFFER_OFFSET); return; } if(!data) { log_printf(L_ERROR, "Got NULL pointer from toxcore - WTF?\n"); return; } if(data[0] != PROTOCOL_MAGIC_HIGH || data[1] != PROTOCOL_MAGIC_LOW) { log_printf(L_WARNING, "Received data frame with invalid protocol magic number 0x%x%x\n", data[0], data[1]); return; } frame = calloc(1, sizeof(protocol_frame)); if(!frame) { log_printf(L_ERROR, "Could not allocate memory for protocol_frame_t\n"); return; } /* TODO check if friendnumber is the same in sender and connid tunnel*/ frame->magic = INT16_AT(data, 0); frame->packet_type = INT16_AT(data, 2); frame->connid = INT16_AT(data, 4); frame->data_length = INT16_AT(data, 6); frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET); frame->friendnumber = friendnumber; log_printf(L_DEBUG, "Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET) { log_printf(L_WARNING, "Received frame too small (attempted buffer overflow?): %d bytes, excepted at least %d bytes\n", len, frame->data_length + PROTOCOL_BUFFER_OFFSET); free(frame); return; } if(frame->data_length > (TOX_MAX_CUSTOM_PACKET_SIZE - PROTOCOL_BUFFER_OFFSET)) { log_printf(L_WARNING, "Declared data length too big (attempted buffer overflow?): %d bytes, excepted at most %d bytes\n", frame->data_length, (TOX_MAX_CUSTOM_PACKET_SIZE - PROTOCOL_BUFFER_OFFSET)); free(frame); return; } handle_frame(frame); free(frame); }
pipeline_processing_block::pipeline_processing_block(const std::vector<int>& streams_to_aggregate) : _queue(new single_consumer_queue<frame_holder>(1)), _streams_ids(streams_to_aggregate) { auto processing_callback = [&](frame_holder frame, synthetic_source_interface* source) { handle_frame(std::move(frame), source); }; set_processing_callback(std::shared_ptr<rs2_frame_processor_callback>( new internal_frame_processor_callback<decltype(processing_callback)>(processing_callback))); }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { struct hostap_driver_data *drv = eloop_ctx; int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { wpa_printf(MSG_ERROR, "recv: %s", strerror(errno)); return; } handle_frame(drv, buf, len); }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { struct hostap_driver_data *drv = eloop_ctx; int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); return; } handle_frame(drv, buf, len); }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { hostapd *hapd = (hostapd *) eloop_ctx; int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); return; } handle_frame(hapd, buf, len); }
void *netdev_rx_loop() { while (running) { if (tun_read(netdev.buf, netdev.buflen) < 0) { print_error("ERR: Read from tun_fd: %s\n", strerror(errno)); return NULL; } struct eth_hdr *hdr = init_eth_hdr(netdev.buf); handle_frame(&netdev, hdr); } return NULL; }
uint64 pcnet_poll(struct eth_dev *e, struct net_dev *nd) { struct pcnet_private *p = (struct pcnet_private *)e->phys; int i; //print_pcnet(p); for(i = 0 ; i < DRE_COUNT ; i++ ) { if(!p->rx[i].RBADR) continue; if(p->rx[i].OWN) continue; handle_frame(e, nd, &p->rx[i]); p->rx[i].OWN = 1; } return 0; }
static void handle_read(int sock, void *eloop_ctx, void *sock_ctx) { hostapd *hapd = (hostapd *) eloop_ctx; int len; unsigned char buf[3000]; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); return; } HOSTAPD_DEBUG(HOSTAPD_DEBUG_VERBOSE, "Received %d bytes management frame\n", len); if (HOSTAPD_DEBUG_COND(HOSTAPD_DEBUG_MSGDUMPS)) { int i; printf(" dump:"); for (i = 0; i < len; i++) printf(" %02x", buf[i]); printf("\n"); } handle_frame(hapd, buf, len); }
static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx) { struct wpa_driver_nl80211_data *drv = eloop_ctx; int len; unsigned char buf[3000]; struct ieee80211_radiotap_iterator iter; int ret; int datarate = 0, ssi_signal = 0; int injected = 0, failed = 0, rxflags = 0; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { wpa_printf(MSG_ERROR, "nl80211: Monitor socket recv failed: %s", strerror(errno)); return; } if (ieee80211_radiotap_iterator_init(&iter, (void *) buf, len, NULL)) { wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame"); return; } while (1) { ret = ieee80211_radiotap_iterator_next(&iter); if (ret == -ENOENT) break; if (ret) { wpa_printf(MSG_INFO, "nl80211: received invalid radiotap frame (%d)", ret); return; } switch (iter.this_arg_index) { case IEEE80211_RADIOTAP_FLAGS: if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS) len -= 4; break; case IEEE80211_RADIOTAP_RX_FLAGS: rxflags = 1; break; case IEEE80211_RADIOTAP_TX_FLAGS: injected = 1; failed = le_to_host16((*(uint16_t *) iter.this_arg)) & IEEE80211_RADIOTAP_F_TX_FAIL; break; case IEEE80211_RADIOTAP_DATA_RETRIES: break; case IEEE80211_RADIOTAP_CHANNEL: /* TODO: convert from freq/flags to channel number */ break; case IEEE80211_RADIOTAP_RATE: datarate = *iter.this_arg * 5; break; case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: ssi_signal = (s8) *iter.this_arg; break; } } if (rxflags && injected) return; if (!injected) handle_frame(drv, buf + iter._max_length, len - iter._max_length, datarate, ssi_signal); else handle_tx_callback(drv->ctx, buf + iter._max_length, len - iter._max_length, !failed); }