I 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
'Legacy Skills > VM' 카테고리의 다른 글
프록시를 통해 Docker 컨테이너 로그를 CloudWatch Logs에 푸시하려면 어떻게 해야 합니까? (0) | 2019.12.18 |
---|---|
A CentOS 6 Image for OpenStack (0) | 2014.08.04 |
VLAN Tagging (0) | 2014.07.30 |
Linux KVM: disable/enable virbr0 NAT Interface (0) | 2014.07.24 |
How to install Open vSwitch and test connection of VMs over GRE (0) | 2014.07.14 |
댓글