Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-04-2012, 06:19 AM   #1
LQ Newbie
Registered: Jun 2008
Posts: 3

Rep: Reputation: 0
802.1q tag, raw socket


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");
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)

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");
Old 05-07-2012, 03:31 PM   #2
Senior Member
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,761

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket RAW ethernet scarabee Programming 1 02-23-2012 06:00 PM
Raw socket - max frame length supported by sendto call for tag frames muruga86 Linux - Networking 0 06-17-2010 06:45 AM
raw sockets in wireless network (802.11) pratyushvb Programming 2 05-27-2010 08:15 AM
Socket Raw linuxanswer Programming 1 04-01-2004 09:43 PM
ping without raw socket linuxnw Linux - Networking 3 12-09-2003 11:57 PM

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration