/*-----------------------------------------------------------------------------------*/ static void tunif_input(struct netif *netif) { struct tunif *tunif; struct pbuf *p; tunif = (struct tunif *)netif->state; p = low_level_input(tunif); if (p == NULL) { LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_input: low_level_input returned NULL\n")); return; } #if 0 /* CS: ip_lookup() was removed */ if (ip_lookup(p->payload, netif)) { #endif netif->input(p, netif); #if 0 } #endif }
/*-----------------------------------------------------------------------------------*/ static void timeout(void *arg) { struct netif *netif; struct pcapif *pcapif; struct pbuf *p, *q; u8_t *bufptr; struct eth_hdr *ethhdr; netif = (struct netif *)arg; pcapif = netif->state; ethhdr = (struct eth_hdr *)pcapif->pkt; if(htons(ethhdr->type) != ETHTYPE_IP || ip_lookup(pcapif->pkt + 14, netif)) { /* We allocate a pbuf chain of pbufs from the pool. */ p = pbuf_alloc(PBUF_LINK, pcapif->len, PBUF_POOL); if(p != NULL) { /* We iterate over the pbuf chain until we have read the entire packet into the pbuf. */ bufptr = (u_char *)pcapif->pkt; for(q = p; q != NULL; q = q->next) { /* Read enough bytes to fill this pbuf in the chain. The avaliable data in the pbuf is given by the q->len variable. */ /* read data into(q->payload, q->len); */ bcopy(bufptr, q->payload, q->len); bufptr += q->len; } ethhdr = p->payload; switch(htons(ethhdr->type)) { case ETHTYPE_IP: arp_ip_input(netif, p); pbuf_header(p, -14); netif->input(p, netif); break; case ETHTYPE_ARP: p = arp_arp_input(netif, pcapif->ethaddr, p); if(p != NULL) { printf("ARP outout\n"); pbuf_free(p); } break; default: pbuf_free(p); break; } } } else { printf("ip_lookup dropped\n"); } sys_sem_signal(pcapif->sem); }
/*-----------------------------------------------------------------------------------*/ static void tapif_input(struct netif *netif) { struct tapif *tapif; struct eth_hdr *ethhdr; struct pbuf *p; tapif = netif->state; p = low_level_input(tapif); if(p == NULL) { DEBUGF(TAPIF_DEBUG, ("tapif_input: low_level_input returned NULL\n")); return; } ethhdr = p->payload; switch(htons(ethhdr->type)) { case ETHTYPE_IP: DEBUGF(TAPIF_DEBUG, ("tapif_input: IP packet\n")); arp_ip_input(netif, p); pbuf_header(p, -14); if(ip_lookup(p->payload, netif)) { netif->input(p, netif); } else { printf("tapif_input: lookup failed!\n"); } break; case ETHTYPE_ARP: DEBUGF(TAPIF_DEBUG, ("tapif_input: ARP packet\n")); p = arp_arp_input(netif, tapif->ethaddr, p); if(p != NULL) { DEBUGF(TAPIF_DEBUG, ("tapif_input: Sending ARP reply\n")); low_level_output(tapif, p); pbuf_free(p); } break; default: pbuf_free(p); break; } }
udp_socket::udp_socket( uint32_t addr, uint64_t port, bool broadcast ) { // Create the socket _fd = ::socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ); if ( _fd < 0 ) error( errno, "Error creating server socket" ); // Close if we exit prematurely auto guard = make_guard( [&]() { ::close( _fd ); _fd = -1; } ); // Set the socket to be reusable immediately after closing if ( port > 0 ) { int opt = 1; if ( setsockopt( _fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt) ) != 0 ) error( errno, "Error reusing address" ); } if ( broadcast ) { int opt = 1; // Turn on broadcasting if ( setsockopt( _fd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt) ) != 0 ) error( errno, "Could not set broadcast" ); } // Bind the socket if( port != 0 ) { struct sockaddr_in servaddr; size_t servsize = sizeof(servaddr); memset( (void *)(&servaddr), 0, servsize ); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = addr; servaddr.sin_port = htons( port ); if ( ::bind( _fd, (struct sockaddr *)&servaddr, servsize ) != 0 ) error( errno, format( "Error binding socket ({0})", ip_lookup( addr ) ) ); } guard.commit(); }
/*-----------------------------------------------------------------------------------*/ static void tunif_input(struct netif *netif) { struct tunif *tunif; struct pbuf *p; tunif = netif->state; p = low_level_input(tunif); if(p == NULL) { DEBUGF(TUNIF_DEBUG, ("tunif_input: low_level_input returned NULL\n")); return; } if(ip_lookup(p->payload, netif)) { netif->input(p, netif); } }