본문 바로가기
  • AI (Artificial Intelligence)
Legacy Skills/VM

Build vlan header in c

by 로샤스 2014. 7. 31.

need to build a vlan header. I have code that build eh header (struct ether_header) and it work ok.

/* Ethernet header */
memcpy(eh->ether_shost,src_mac_.data(), 6);
memcpy(eh->ether_dhost,socketAddress.sll_addr , 6);

/* Ethertype field */
eh->ether_type = htons(ETH_P_IP);

I didnt find struct for vlan_eth_header , so i create my own and populate it like this:

struct vlan_ethhdr {
  u_int8_t  ether_dhost[ETH_ALEN];  /* destination eth addr */
  u_int8_t  ether_shost[ETH_ALEN];  /* source ether addr    */
  u_int16_t          h_vlan_proto;
  u_int16_t          h_vlan_TCI;
  u_int16_t ether_type;
 };

    /* Ethernet header */
    memcpy(eh->ether_shost,src_mac_.data(), 6);
    memcpy(eh->ether_dhost,socketAddress.sll_addr , 6);
        eh->h_vlan_proto = htons(0x8100);
        eh->h_vlan_TCI = htons(VLAN_ID);
    /* Ethertype field */
    eh->ether_type = htons(ETH_P_IP);

It seems that i did it wrong. It seems that Wireshak even didnt recognize the packet (the old code sent tcp packet and send them correct). Any advice?












출처 : http://stackoverflow.com/questions/13166094/build-vlan-header-in-c









댓글