title: Sending Packet with VLAN tag using C Socket
body: <p>I am having a problem to understand VLAN tagging. 
  I have already done changes in the /etc/network/interface file using  <a href="http://myhomelab.blogspot.de/2014/01/8021q-vlan-trunk-in-linux.html" rel="nofollow">this link</a>
  I am using socket programming on Raspbian (Raspberry pi) using C language.</p>
  
  <p>I tried 2 methods:</p>
  
  <ol>
  <li><p>The socket in C is </p>
  
  <p>s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);</p></li>
  </ol>
  
  <p>When i send a ethernet packet from the raspberry pi using the above socket i  only see the outgoing "arp" messages on the bus.</p>
  
  <ol start="2">
  <li><code>s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))</code></li>
  </ol>
  
  <p>But this creates an error "sendto failed: Invalid argument" during sending the packet, the code to send packet is: </p>
  
  <pre><code>struct sockaddr_in sin; 
  sin.sin_family = AF_PACKET;
  sin.sin_port = htons(30490);
  sin.sin_addr.s_addr = inet_addr(destination ip address);
  
  
  if(sendto(socket, data, iph-&gt;tot_len, 0, (struct sockaddr *)&amp;sin, sizeof(sin)) &lt; 0)
  { perror("Sendto failed"); }
  else { printf("Packet send"); }
  </code></pre>
  
  <p>Could anyone help me with the information on how to attach a VLAN tag with every packet that is being send ? Or what i am doing wrong in above code ?</p>
  
  <p>Is there a code which is already implemented for sending packets with VLAN?</p>
  
  <p>(In my setup i am not using any router or switch)</p>