Various packet structures of TCP/IP

Source: Internet
Author: User

Various packet structures of TCP/IP
The following TCP/IP data packets are the data packet structures that I have used during socket and wipcap network programming. These data packets seem inconspicuous at ordinary times, it will be very useful when actually used ......
/* Physical Frame header structure */
Typedef struct {
Byte desmac [6]; // target MAC address
Byte srcmac [6]; // source MAC address
Ushort ethertype; // Frame Type
} Dlc_header;

/* IP header structure */
Typedef struct {
Byte h_len_ver; // IP version number (4 digits in height) and length of the IP packet header in 32 bits (four digits below)
Byte TOS; // service type TOS
Ushort total_len; // total IP package Length
Ushort ident; // ID
Ushort frag_and_flags; // flag
Byte TTL; // TTL
Byte proto; // Protocol
Ushort checksum; // IP header checksum
Byte sourceip [4]; // source IP address (32-bit)
// Or uint sourceip;
Byte destip [4]; // destination IP address (32-bit)
// Or uint destip;
} Ip_header;

/* TCP Header */
Typedef struct {
Ushort srcport; // Source Port
Ushort dstport; // destination port
Uint seqnum; // sequence number
Uint acknum; // expected TCP Package number of the other party
Byte h_len; // The length of the TCP Header in 32 bits
Byte flags; // flag (URG, ack, etc)
Ushort indow; // window size
Ushort chksum; // checksum
Ushort urgptr; // emergency pointer
} Tcp_header;

// The TCP pseudo header is used for TCP checksum calculation to ensure the validity of TCP verification.
Typedef struct {
Ulong sourceip; // source IP address
Ulong destip; // destination IP address
Byte mbz; // null (0)
Byte ptcl; // protocol type (ipproto_tcp)
Ushort tcpl; // The length of the TCP Header (unit: bytes)
} Psd_header;

/* UDP header */
Typedef struct {
Ushort srcport; // Source Port
Ushort dstport; // destination port
Ushort total_len; // The length of the UDP header and UDP data (unit: bytes)
Ushort chksum; // checksum
} Udp_header;

// UDP pseudo header-used only for calculating the checksum
Typedef struct tsd_hdr
{
Byte sourceip [4]; // source IP address
Byte destip [4]; // destination IP address
Byte mbz; // null (0)
Byte ptcl; // protocol type (ipproto_udp)
Ushort udpl; // The total length of the UDP packet (excluding the length unit of the pseudo header: bytes)
} Psd_header;

/* ICMP header */
Typedef struct {
Byte I _type; // The ICMP sent by the type is 8 (icmp_echo_request), and the ICMP received is 0.
Byte I _code; // code
Ushort I _cksum; // ICMP packet checksum
Ushort I _id; // identification number (process number is generally used as the identification number)
Ushort I _seq; // message serial number (usually set to 0)
Ulong timestamp; // Timestamp
} Icmp_header;

// ARP Frame Structure
Typedef struct {
Ushort hw_type; // hardware type: 0x1
Ushort prot_type; // upper-layer protocol type IP Address: 0x0800
Byte hw_addr_len; // hardware address length: 6
Byte prot_addr_len; // Protocol address (IP address) Length: 4
Ushort flag; // 1 indicates the request and 2 indicates the response
Byte send_hw_addr [6]; // source MAC address
Byte send_prot_addr [4]; // source IP address
Byte targ_hw_addr [6]; // target MAC address
Byte targ_prot_addr [4]; // destination IP address
Byte padding [18]; // fill in data
} Arp_frame;

/* DNS data header */
Typedef struct {
Ushort ID; // ID. The client can match the DNS request with the response;
Ushort flags; // flag: (query) 0x0100 (response) 0x8180. These numbers are in the host sequence.
Ushort questions; // number of problems
Ushort answers; // number of resource records
Ushort author; // number of authorized resource records
Ushort addition; // number of additional resource records
} Dns_header;
// This is the public part of the DNS package, that is, both the query package and the response package contain this part. The query problem (domain) cannot be determined, therefore, it is difficult to write data in the struct

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.