samedi 18 avril 2015

UDP services such as netcat using raw sockets and tun/tap interface

I have a program that uses raw sockets and sends an UDP packet from 1 "eth" interface to a tun/tap interface with IP addr "IP1". The reason why is that I am receiving UDP packets through a tunnel, which are originally sent from IP "IP2", so both IP and UDP headers are already there once I remove the overhead. I create a tun/tap interface with the destination IP of such UDP packets and I open "netcat -u IP2 portx" (on the other side it's "netcat -u IP1 portx") and nothing is being received or sent.



  • IP forwarding is enabled (although I am not sure if it matters).

  • The packets can be seen in wireshark: Both UDP and IP checksums are OK, also source and destination IPs are OK.

  • Destination and source MACs and IPs are also right both in IP and ethernet headers, and the "type" in ethernet header is 0x0800 (IP).

  • "nc -l -u -p 12345" doesn't receive anything.

  • My program creates the tun/tap interface. I run wireshark only after the interface is created, and only listen to the tap interface


What is left for me to make UDP services like netcat work?


I send with the following function:



/* Destination address */
struct sockaddr_ll socket_address;
memset (&socket_address, 0, sizeof(struct sockaddr_ll));
/* Index of the network device */
socket_address.sll_ifindex = ifindex;
/* Address length*/
socket_address.sll_family = AF_PACKET;
socket_address.sll_protocol = htons(ETH_P_IP);
socket_address.sll_halen = ETHER_ADDR_LEN;//ETH_ALEN;
/* Destination MAC */
socket_address.sll_addr[0] = (uint8_t) (*(dest_mac));
socket_address.sll_addr[1] = (uint8_t) (*(++dest_mac));
socket_address.sll_addr[2] = (uint8_t) (*(++dest_mac));
socket_address.sll_addr[3] = (uint8_t) (*(++dest_mac));
socket_address.sll_addr[4] = (uint8_t) (*(++dest_mac));
socket_address.sll_addr[5] = (uint8_t) (*(++dest_mac));

/* Send packet */
if (sendto(sock, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) < 0)
perror("Send failed\n");

Aucun commentaire:

Enregistrer un commentaire