IP,TCP,UDP头及定义


Source to netinet/ip.h

 

--------------------------------------------------------------------------------

 

 Enter a symbol's name here to quickly find it.

 

--------------------------------------------------------------------------------

 

/*

 *Copyright (c) 1982, 1986 Regents of the University of California.

 *All rights reserved.

 *

 *Redistribution and use in source and binary forms, with or without

 *modification, are permitted provided that the following conditions

 *are met:

 * 1.Redistributions of source code must retain the above copyright

 *   notice, this list of conditions and the following disclaimer.

 * 2.Redistributions in binary form must reproduce the above copyright

 *   notice, this list of conditions and the following disclaimer in the

 *   documentation and/or other materials provided with the distribution.

 * 3.All advertising materials mentioning features or use of this software

 *   must display the following acknowledgement:

 *     This product includes software developed bythe University of

 *     California, Berkeley and its contributors.

 * 4.Neither the name of the University nor the names of its contributors

 *    maybe used to endorse or promote products derived from this software

 *   without specific prior written permission.

 *

 *THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND

 *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

 *ARE DISCLAIMED.  IN NO EVENT SHALL THEREGENTS OR CONTRIBUTORS BE LIABLE

 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

 *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

 * ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

 *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

 *OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

 *SUCH DAMAGE.

 *

 *     @(#)ip.h  7.10(Berkeley) 6/28/90

 */

 

/*

 *Definitions for internet protocol version 4.

 *Per RFC 791, September 1981.

 */

#define     IPVERSION       4

 

/*

 *Structure of an internet header, naked of options.

 *

 * Wedeclare ip_len and ip_off to be short, rather than u_short

 *pragmatically since otherwise unsigned comparisons can result

 *against negative integers quite easily, and fail in subtle ways.

 */

struct ip {

#if BYTE_ORDER == LITTLE_ENDIAN

         u_char      ip_hl:4,              /*header length */

                   ip_v:4;                         /* version */

#endif

#if BYTE_ORDER == BIG_ENDIAN

         u_char      ip_v:4,                         /*version */

                   ip_hl:4;              /* header length */

#endif

         u_char      ip_tos;                        /*type of service */

         short         ip_len;                         /*total length */

         u_short    ip_id;                           /*identification */

         short         ip_off;                         /*fragment offset field */

#define     IP_DF0x4000                     /* dontfragment flag */

#define     IP_MF0x2000                    /* morefragments flag */

         u_char      ip_ttl;                          /*time to live */

         u_char      ip_p;                            /*protocol */

         u_short    ip_sum;                      /*checksum */

         struct       in_addr ip_src,ip_dst;      /* source and dest address */

};

 

#define     IP_MAXPACKET        65535                /*maximum packet size */

 

/*

 *Definitions for IP type of service (ip_tos)

 */

#define     IPTOS_LOWDELAY            0x10

#define     IPTOS_THROUGHPUT      0x08

#define     IPTOS_RELIABILITY 0x04

 

/*

 *Definitions for IP precedence (also in ip_tos) (hopefully unused)

 */

#define     IPTOS_PREC_NETCONTROL             0xe0

#define     IPTOS_PREC_INTERNETCONTROL  0xc0

#define     IPTOS_PREC_CRITIC_ECP                 0xa0

#define     IPTOS_PREC_FLASHOVERRIDE        0x80

#define     IPTOS_PREC_FLASH                   0x60

#define     IPTOS_PREC_IMMEDIATE                 0x40

#define     IPTOS_PREC_PRIORITY            0x20

#define     IPTOS_PREC_ROUTINE             0x10

 

/*

 *Definitions for options.

 */

#define     IPOPT_COPIED(o)             ((o)&0x80)

#define     IPOPT_CLASS(o)                 ((o)&0x60)

#define     IPOPT_NUMBER(o)          ((o)&0x1f)

 

#define     IPOPT_CONTROL              0x00

#define     IPOPT_RESERVED1           0x20

#define     IPOPT_DEBMEAS              0x40

#define     IPOPT_RESERVED2           0x60

 

#define     IPOPT_EOL                0                /* end of option list */

#define     IPOPT_NOP               1                /*no operation */

 

#define     IPOPT_RR                  7                /* record packet route */

#define     IPOPT_TS          68              /*timestamp */

#define     IPOPT_SECURITY              130            /* provide s,c,h,tcc */

#define     IPOPT_LSRR              131            /* loose source route */

#define     IPOPT_SATID             136            /*satnet id */

#define     IPOPT_SSRR              137            /* strict source route */

 

/*

 *Offsets to fields in options other than EOL and NOP.

 */

#define     IPOPT_OPTVAL                  0                /* option ID */

#define     IPOPT_OLEN             1                /*option length */

#define IPOPT_OFFSET              2                /*offset within option */

#define     IPOPT_MINOFF                  4                /* min value of above */

 

/*

 *Time stamp option structure.

 */

struct       ip_timestamp{

         u_char      ipt_code;          /*IPOPT_TS */

         u_char      ipt_len;              /*size of structure (variable) */

         u_char      ipt_ptr;              /*index of current entry */

#if BYTE_ORDER == LITTLE_ENDIAN

         u_char      ipt_flg:4,           /*flags, see below */

                   ipt_oflw:4;                 /* overflow counter */

#endif

#if BYTE_ORDER == BIG_ENDIAN

         u_char      ipt_oflw:4,                 /* overflow counter */

                   ipt_flg:4;           /* flags, see below */

#endif

         unionipt_timestamp {

                   n_long      ipt_time[1];

                   struct       ipt_ta {

                            structin_addr ipt_addr;

                            n_longipt_time;

                   }ipt_ta[1];

         }ipt_timestamp;

};

 

/* flag bits for ipt_flg */

#define     IPOPT_TS_TSONLY            0                /*timestamps only */

#define     IPOPT_TS_TSANDADDR  1                /*timestamps and addresses */

#define     IPOPT_TS_PRESPEC 3                /*specified modules only */

 

/* bits for security (not byte swapped) */

#define     IPOPT_SECUR_UNCLASS 0x0000

#define     IPOPT_SECUR_CONFID   0xf135

#define     IPOPT_SECUR_EFTO        0x789a

#define     IPOPT_SECUR_MMMM  0xbc4d

#define     IPOPT_SECUR_RESTR      0xaf13

#define     IPOPT_SECUR_SECRET    0xd788

#define     IPOPT_SECUR_TOPSECRET     0x6bc5

 

/*

 *Internet implementation parameters.

 */

#define     MAXTTL            255            /*maximum time to live (seconds) */

#define     IPFRAGTTL       60              /*time to live for frags, slowhz */

#define     IPTTLDEC 1                /*subtracted when forwarding */

 

#define     IP_MSS              576            /* default maximum segment size */

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Main Page  Alphabetical List   DataStructures   File List   Data Fields  Globals  

 

--------------------------------------------------------------------------------

 

udp.h

Go to the documentation of this file.00001/*

00002 * INET         An implementationof the TCP/IP protocol suite for the LINUX

00003 *              operating system.  INET is implemented using the  BSD Socket

00004 *              interface as themeans of communication with the user level.

00005 *

00006 *              Definitions for theUDP protocol.

00007 *

00008 * Version:     @(#)udp.h       1.0.2  04/28/93

00009 *

00010 * Author:      Fred N. van Kempen,<waltje@uWalt.NL.Mugnet.ORG>

00011 *

00012 *              This program isfree software; you can redistribute it and/or

00013 *              modify it under theterms of the GNU General Public License

00014 *              as published by theFree Software Foundation; either version

00015 *              2 of the License,or (at your option) any later version.

00016 */

00017 #ifndef _LINUX_UDP_H

00018 #define _LINUX_UDP_H

00019

00020 #include <linux/types.h>

00021

00022 struct udphdr {

00023         __u16  source;

00024         __u16  dest;

00025         __u16  len;

00026         __u16  check;

00027 };

00028

00029 /* UDP socket options */

00030 #define UDP_CORK        1      /* Never send partiallycomplete segments */

00031 #define UDP_ENCAP       100    /* Set the socket to accept encapsulated packets */

00032

00033 /* UDP encapsulation types */

00034 #defineUDP_ENCAP_ESPINUDP_NON_IKE      1 /*draft-ietf-ipsec-nat-t-ike-00/01 */

00035 #define UDP_ENCAP_ESPINUDP      2 /* draft-ietf-ipsec-udp-encaps-06 */

00036

00037 #ifdef __KERNEL__

00038

00039 #include <linux/config.h>

00040 #include <net/sock.h>

00041 #include <linux/ip.h>

00042

00043 struct udp_opt {

00044         int             pending;        /* Any pending frames ? */

00045         unsigned int    corkflag;       /* Cork is required */

00046         __u16           encap_type;     /* Is this an Encapsulation socket? */

00047         /*

00048         * Following member retains theinfomation to create a UDP header

00049          * when the socket is uncorked.

00050          */

00051         __u16           len;            /* total length of pending frames*/

00052 };

00053

00054 /* WARNING: don't change the layoutof the members in udp_sock! */

00055 struct udp_sock {

00056         struct sock       sk;

00057 #if defined(CONFIG_IPV6) ||defined(CONFIG_IPV6_MODULE)

00058         struct ipv6_pinfo *pinet6;

00059 #endif

00060         struct inet_opt   inet;

00061         struct udp_opt    udp;

00062 };

00063

00064 static inline struct udp_opt *udp_sk(const struct sock *__sk)

00065 {

00066         return &((struct udp_sock*)__sk)->udp;

00067 }

00068

00069 #endif

00070

00071 #endif  /* _LINUX_UDP_H */

 

 





--------------------------------------------------------------------------------

 

Generated at Wed Sep 22 17:57:02 2004 forLINUX_TCP_STACK by doxygen1.2.8.1 written by Dimitri van Heesch, ? 1997-2001

 

/*

 *Copyright (c) 1982, 1986, 1993

 *     The Regents of the University ofCalifornia.  All rights reserved.

 *

 *Redistribution and use in source and binary forms, with or without

 *modification, are permitted provided that the following conditions

 *are met:

 * 1.Redistributions of source code must retain the above copyright

 *   notice, this list of conditions and the following disclaimer.

 * 2.Redistributions in binary form must reproduce the above copyright

 *   notice, this list of conditions and the following disclaimer in the

 *    documentation and/or other materials providedwith the distribution.

 * 4.Neither the name of the University nor the names of its contributors

 *    maybe used to endorse or promote products derived from this software

 *   without specific prior written permission.

 *

 *THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND

 *ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE

 *IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE

 *ARE DISCLAIMED.  IN NO EVENT SHALL THEREGENTS OR CONTRIBUTORS BE LIABLE

 *FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL

 *DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS

 * ORSERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)

 *HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT

 *LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY

 *OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF

 *SUCH DAMAGE.

 *

 *     @(#)tcp.h         8.1(Berkeley) 6/10/93

 */

 

#ifndef _NETINET_TCP_H

#define _NETINET_TCP_H       1

 

#include <features.h>

 

/*

 *User-settable options (used with setsockopt).

 */

#define     TCP_NODELAY 1     /*Don't delay send to coalesce packets  */

#define     TCP_MAXSEG  2     /*Set maximum segment size  */

#define TCP_CORK  3     /* Control sending ofpartial frames  */

#define TCP_KEEPIDLE    4     /* Start keeplivesafter this period */

#define TCP_KEEPINTVL 5     /*Interval between keepalives */

#define TCP_KEEPCNT     6     /* Number ofkeepalives before death */

#define TCP_SYNCNT       7     /* Number of SYNretransmits */

#define TCP_LINGER2     8     /* Life time oforphaned FIN-WAIT-2 state */

#define TCP_DEFER_ACCEPT 9        /* Wake up listener only when dataarrive */

#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */

#define TCP_INFO   11  /* Information aboutthis connection. */

#define     TCP_QUICKACK        12  /*Bock/reenable quick ACKs.  */

#define TCP_CONGESTION      13  /*Congestion control algorithm.  */

#define TCP_MD5SIG      14  /* TCP MD5 Signature(RFC2385) */

 

#ifdef __USE_MISC

# include <sys/types.h>

# include <sys/socket.h>

 

# ifdef __FAVOR_BSD

typedef    u_int32_ttcp_seq;

/*

 *TCP header.

 *Per RFC 793, September, 1981.

 */

struct tcphdr

  {

   u_int16_t th_sport;          /*source port */

   u_int16_t th_dport;                   /*destination port */

   tcp_seq th_seq;                /*sequence number */

   tcp_seq th_ack;                 /*acknowledgement number */

#  if__BYTE_ORDER == __LITTLE_ENDIAN

   u_int8_t th_x2:4;              /*(unused) */

   u_int8_t th_off:4;             /*data offset */

# endif

#  if__BYTE_ORDER == __BIG_ENDIAN

   u_int8_t th_off:4;             /*data offset */

   u_int8_t th_x2:4;              /*(unused) */

# endif

   u_int8_t th_flags;

# define TH_FIN    0x01

# define TH_SYN   0x02

# define TH_RST   0x04

# define TH_PUSH         0x08

# define TH_ACK  0x10

# define TH_URG 0x20

   u_int16_t th_win;             /*window */

   u_int16_t th_sum;            /*checksum */

   u_int16_t th_urp;             /*urgent pointer */

};

 

# else /* !__FAVOR_BSD */

struct tcphdr

  {

   u_int16_t source;

   u_int16_t dest;

   u_int32_t seq;

   u_int32_t ack_seq;

#  if__BYTE_ORDER == __LITTLE_ENDIAN

   u_int16_t res1:4;

   u_int16_t doff:4;

   u_int16_t fin:1;

   u_int16_t syn:1;

    u_int16_trst:1;

   u_int16_t psh:1;

   u_int16_t ack:1;

   u_int16_t urg:1;

   u_int16_t res2:2;

# elif __BYTE_ORDER == __BIG_ENDIAN

   u_int16_t doff:4;

   u_int16_t res1:4;

   u_int16_t res2:2;

   u_int16_t urg:1;

   u_int16_t ack:1;

   u_int16_t psh:1;

   u_int16_t rst:1;

   u_int16_t syn:1;

   u_int16_t fin:1;

# else

#  error "Adjust your <bits/endian.h> defines"

# endif

   u_int16_t window;

   u_int16_t check;

   u_int16_t urg_ptr;

};

# endif /* __FAVOR_BSD */

 

enum

{

  TCP_ESTABLISHED= 1,

 TCP_SYN_SENT,

 TCP_SYN_RECV,

 TCP_FIN_WAIT1,

 TCP_FIN_WAIT2,

 TCP_TIME_WAIT,

 TCP_CLOSE,

 TCP_CLOSE_WAIT,

 TCP_LAST_ACK,

 TCP_LISTEN,

 TCP_CLOSING   /* now a valid state*/

};

 

# define TCPOPT_EOL               0

# define TCPOPT_NOP              1

# define TCPOPT_MAXSEG                2

# define TCPOLEN_MAXSEG             4

# define TCPOPT_WINDOW              3

# define TCPOLEN_WINDOW           3

# define TCPOPT_SACK_PERMITTED       4                /*Experimental */

# define TCPOLEN_SACK_PERMITTED    2

# define TCPOPT_SACK             5                /*Experimental */

# define TCPOPT_TIMESTAMP         8

# define TCPOLEN_TIMESTAMP      10

# define TCPOLEN_TSTAMP_APPA  (TCPOLEN_TIMESTAMP+2) /* appendix A */

 

# define TCPOPT_TSTAMP_HDR      \

   (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)

 

/*

 *Default maximum segment size for TCP.

 *With an IP MSS of 576, this is 536,

 *but 512 is probably more convenient.

 *This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).

 */

# define TCP_MSS    512

 

# define TCP_MAXWIN    65535       /* largest valuefor (unscaled) window */

 

# define TCP_MAX_WINSHIFT         14     /*maximum window shift */

 

# define SOL_TCP              6       /* TCPlevel */

 

 

# define TCPI_OPT_TIMESTAMPS   1

# define TCPI_OPT_SACK                   2

# define TCPI_OPT_WSCALE   4

# define TCPI_OPT_ECN           8

 

/* Values for tcpi_state.  */

enum tcp_ca_state

{

 TCP_CA_Open = 0,

 TCP_CA_Disorder = 1,

 TCP_CA_CWR = 2,

 TCP_CA_Recovery = 3,

 TCP_CA_Loss = 4

};

 

struct tcp_info

{

 u_int8_t       tcpi_state;

 u_int8_t       tcpi_ca_state;

 u_int8_t       tcpi_retransmits;

 u_int8_t       tcpi_probes;

 u_int8_t       tcpi_backoff;

 u_int8_t       tcpi_options;

 u_int8_t       tcpi_snd_wscale : 4,tcpi_rcv_wscale : 4;

 

 u_int32_t     tcpi_rto;

 u_int32_t     tcpi_ato;

 u_int32_t     tcpi_snd_mss;

 u_int32_t     tcpi_rcv_mss;

 

 u_int32_t     tcpi_unacked;

 u_int32_t     tcpi_sacked;

 u_int32_t     tcpi_lost;

 u_int32_t     tcpi_retrans;

 u_int32_t     tcpi_fackets;

 

  /*Times. */

 u_int32_t     tcpi_last_data_sent;

 u_int32_t     tcpi_last_ack_sent; /* Not remembered, sorry.  */

 u_int32_t     tcpi_last_data_recv;

 u_int32_t     tcpi_last_ack_recv;

 

  /*Metrics. */

 u_int32_t     tcpi_pmtu;

 u_int32_t     tcpi_rcv_ssthresh;

 u_int32_t     tcpi_rtt;

 u_int32_t     tcpi_rttvar;

 u_int32_t     tcpi_snd_ssthresh;

 u_int32_t     tcpi_snd_cwnd;

 u_int32_t     tcpi_advmss;

 u_int32_t     tcpi_reordering;

 

 u_int32_t     tcpi_rcv_rtt;

 u_int32_t     tcpi_rcv_space;

 

 u_int32_t     tcpi_total_retrans;

};

 

 

/* For TCP_MD5SIG socket option.  */

#define TCP_MD5SIG_MAXKEYLEN         80

 

struct tcp_md5sig

{

 struct sockaddr_storage tcpm_addr;          /*Address associated.  */

 u_int16_t     __tcpm_pad1;                   /* Zero.  */

 u_int16_t     tcpm_keylen;                     /* Key length.  */

 u_int32_t     __tcpm_pad2;                   /* Zero.  */

 u_int8_t       tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary).  */

};

 

#endif /* Misc.  */

 

#endif /* netinet/tcp.h */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值