LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   802.1q tag, raw socket (https://www.linuxquestions.org/questions/programming-9/802-1q-tag-raw-socket-943244/)

petar 05-04-2012 06:19 AM

802.1q tag, raw socket
 
Hello,

I am writing program that need to accept double TAG traffic. I am using raw socket for that.
And in general my program run OK, except that for some reason received packet do not have 2 VLAN tags, but only one. I see in wireshark that packet indeed have 2 VLAN tags in it.
Can you please help? Funny part is that sending of double tagged package is working fine.

if ((rx_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0)
{
perror("Error creating socket");
exit(0);
}
struct ifreq if_mac_rec1;
memset(&if_mac_rec1, 0, sizeof(struct ifreq));
strncpy(if_mac_rec1.ifr_name, "eth0", IFNAMSIZ);
if (ioctl(rx_socket, SIOCGIFINDEX, &if_mac_rec1) < 0)
{
perror("SIOCGIFINDEX");
exit(1);
}

struct packet_mreq mr_rx;
memset (&mr_rx, 0, sizeof (mr_rx));
mr_rx.mr_ifindex = if_mac_rec1.ifr_ifindex;
mr_rx.mr_type = PACKET_MR_PROMISC;
setsockopt (rx_socket, SOL_PACKET,PACKET_ADD_MEMBERSHIP, &mr_rx, sizeof (mr_rx));

if (recvfrom(rx_socket, (unsigned char *)&recv_msg, 800, 0,0,0) <= 0)
perror("packet receive error:Rx-> Receive all messages");

smallpond 05-07-2012 03:31 PM

Most likely this means you are capturing on the VLAN interface (like eth1.101) instead of on the raw interface (like eth1). See here.


All times are GMT -5. The time now is 04:56 PM.