TCP/IP Header Structure

Source: Internet
Author: User
// MAC header, total length 14 bytes Typedef struct _ eth_hdr {unsigned char dstmac [6]; // target MAC address unsigned char srcmac [6]; // source MAC address unsigned short eth_type; // Ethernet Type} eth_hdr; // IP header, total length: 20 bytes Typedef struct _ ip_hdr {# If little_endianunsigned char IHL: 4; // header length unsigned char version: 4, // version # else www.2cto.com unsigned char version: 4, // version unsigned char IHL: 4; // header length # endifunsigned char TOS; // service type unsigned short tot_len; // total length unsigned short ID; // flag unsigned short frag_off; // shard offset unsigned char TTL; // survival time unsigned char protocol; // protocol unsigned short chk_sum; // check and struct in_addr srcaddr; // source IP address struct in_addr dstaddr; // destination IP address} ip_hdr; // TCP Header, with a total length of 20 bytes Typedef struct _ tcp_hdr {unsigned short src_port; // source port number unsigned short dst_port; // destination port number unsigned int seq_no; // serial number unsigned int ack_no; // confirmation # If little_endianunsigned char reserved_1: 4; // retain the four-digit header length of the six-digit unsigned char Thl: 4; // TCP Header Length: unsigned char flag: 6; // The six-digit flag unsigned char reseverd_2: 2; // retain the two digits in the six digits # elseunsigned char Thl: 4; // The TCP Header Length unsigned char reserved_1: 4; // retain the four-digit header length of the six-digit unsigned char reseverd_2: 2; // retain the two-digit unsigned char flag: 6; // the six-digit sign # endifunsigned short wnd_size; // 16-bit window size unsigned short chk_sum; // 16-bit TCP test and unsigned short urgt_p; // 16 is an emergency pointer} tcp_hdr; www.2cto.com // UDP header, total length 8 bytes Typedef struct _ udp_hdr {unsigned short src_port; // remote slogan unsigned short dst_port; // destination port number unsigned short Uhl; // UDP header length unsigned short chk_sum; // 16-bit UDP check and} udp_hdr; // ICMP header, with a total length of 4 bytes Typedef struct _ icmp_hdr {unsigned char icmp_type; // type unsigned char code ;// Code Unsigned short chk_sum; // 16-bit check and} icmp_hdr;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.