| /* |
| * Copyright (c) 2015 PLUMgrid, Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| struct ethernet_t { |
| unsigned long long dst:48; |
| unsigned long long src:48; |
| unsigned int type:16; |
| } __attribute__((packed)); |
| |
| struct dot1q_t { |
| unsigned short pri:3; |
| unsigned short cfi:1; |
| unsigned short vlanid:12; |
| unsigned short type; |
| } __attribute__((packed)); |
| |
| struct arp_t { |
| unsigned short htype; |
| unsigned short ptype; |
| unsigned char hlen; |
| unsigned char plen; |
| unsigned short oper; |
| unsigned long long sha:48; |
| unsigned long long spa:32; |
| unsigned long long tha:48; |
| unsigned int tpa; |
| } __attribute__((packed)); |
| |
| struct ip_t { |
| unsigned char ver:4; // byte 0 |
| unsigned char hlen:4; |
| unsigned char tos; |
| unsigned short tlen; |
| unsigned short identification; // byte 4 |
| unsigned short ffo_unused:1; |
| unsigned short df:1; |
| unsigned short mf:1; |
| unsigned short foffset:13; |
| unsigned char ttl; // byte 8 |
| unsigned char nextp; |
| unsigned short hchecksum; |
| unsigned int src; // byte 12 |
| unsigned int dst; // byte 16 |
| } __attribute__((packed)); |
| |
| struct udp_t { |
| unsigned short sport; |
| unsigned short dport; |
| unsigned short length; |
| unsigned short crc; |
| } __attribute__((packed)); |
| |
| struct tcp_t { |
| unsigned short src_port; // byte 0 |
| unsigned short dst_port; |
| unsigned int seq_num; // byte 4 |
| unsigned int ack_num; // byte 8 |
| unsigned char offset:4; // byte 12 |
| unsigned char reserved:4; |
| unsigned char flag_cwr:1; |
| unsigned char flag_ece:1; |
| unsigned char flag_urg:1; |
| unsigned char flag_ack:1; |
| unsigned char flag_psh:1; |
| unsigned char flag_rst:1; |
| unsigned char flag_syn:1; |
| unsigned char flag_fin:1; |
| unsigned short rcv_wnd; |
| unsigned short cksum; // byte 16 |
| unsigned short urg_ptr; |
| } __attribute__((packed)); |