sockets - Reading 802.1Q frames with specific VLAN tag under Linux -
Is there a way to get data for a specific VLAN tag frame? The frame being tagged by inputting htons (0x22f0) as input to all the VLAN sockets () I currently receive:
m_iSocketDesc = socket (AF_PACKET, SOCK_RAW, htons (0x22f0)); Numbytes = recvfrom (m_iSocketDesc, message_data, 1522, 0, null, 0)
I A similar requirement was to get a packet with a specific VLAN, I created a VLAN interface and forced it to my raw socket. Now I can send 802.3 frames, the kernel insert / removes the VLAN tag.
-
Create the VLAN interface, you must have root access
add ip link link & lt; PhyInterface & gt; Name & lt; PhyInterface.VLANID & gt; Type VLAN ID VLANID Example: IP Link Link Link eth0 Name eth0.100 Type vlan 100 -
Use the normal bind function in your application to connect to the VLAN interface Please. Eth0.100 in the above example.
You can specify the following two links for the sample code (I am the owner of the not code) < P> Getting: Receiving:
The only change is needed to bind the virtual VLAN interface instead of binding to the physical interface. Note that the received ethernet frames are un-tagged frames. Any frames sent to this interface will be automatically tagged with VLANID.
Comments
Post a Comment