tcp.h revision 1541
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
331541Srgrimes *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
341541Srgrimes */
351541Srgrimes
361541Srgrimestypedef	u_long	tcp_seq;
371541Srgrimes/*
381541Srgrimes * TCP header.
391541Srgrimes * Per RFC 793, September, 1981.
401541Srgrimes */
411541Srgrimesstruct tcphdr {
421541Srgrimes	u_short	th_sport;		/* source port */
431541Srgrimes	u_short	th_dport;		/* destination port */
441541Srgrimes	tcp_seq	th_seq;			/* sequence number */
451541Srgrimes	tcp_seq	th_ack;			/* acknowledgement number */
461541Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
471541Srgrimes	u_char	th_x2:4,		/* (unused) */
481541Srgrimes		th_off:4;		/* data offset */
491541Srgrimes#endif
501541Srgrimes#if BYTE_ORDER == BIG_ENDIAN
511541Srgrimes	u_char	th_off:4,		/* data offset */
521541Srgrimes		th_x2:4;		/* (unused) */
531541Srgrimes#endif
541541Srgrimes	u_char	th_flags;
551541Srgrimes#define	TH_FIN	0x01
561541Srgrimes#define	TH_SYN	0x02
571541Srgrimes#define	TH_RST	0x04
581541Srgrimes#define	TH_PUSH	0x08
591541Srgrimes#define	TH_ACK	0x10
601541Srgrimes#define	TH_URG	0x20
611541Srgrimes	u_short	th_win;			/* window */
621541Srgrimes	u_short	th_sum;			/* checksum */
631541Srgrimes	u_short	th_urp;			/* urgent pointer */
641541Srgrimes};
651541Srgrimes
661541Srgrimes#define	TCPOPT_EOL		0
671541Srgrimes#define	TCPOPT_NOP		1
681541Srgrimes#define	TCPOPT_MAXSEG		2
691541Srgrimes#define    TCPOLEN_MAXSEG		4
701541Srgrimes#define TCPOPT_WINDOW		3
711541Srgrimes#define    TCPOLEN_WINDOW		3
721541Srgrimes#define TCPOPT_SACK_PERMITTED	4		/* Experimental */
731541Srgrimes#define    TCPOLEN_SACK_PERMITTED	2
741541Srgrimes#define TCPOPT_SACK		5		/* Experimental */
751541Srgrimes#define TCPOPT_TIMESTAMP	8
761541Srgrimes#define    TCPOLEN_TIMESTAMP		10
771541Srgrimes#define    TCPOLEN_TSTAMP_APPA		(TCPOLEN_TIMESTAMP+2) /* appendix A */
781541Srgrimes
791541Srgrimes#define TCPOPT_TSTAMP_HDR	\
801541Srgrimes    (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
811541Srgrimes
821541Srgrimes/*
831541Srgrimes * Default maximum segment size for TCP.
841541Srgrimes * With an IP MSS of 576, this is 536,
851541Srgrimes * but 512 is probably more convenient.
861541Srgrimes * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
871541Srgrimes */
881541Srgrimes#define	TCP_MSS	512
891541Srgrimes
901541Srgrimes#define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
911541Srgrimes
921541Srgrimes#define TCP_MAX_WINSHIFT	14	/* maximum window shift */
931541Srgrimes
941541Srgrimes/*
951541Srgrimes * User-settable options (used with setsockopt).
961541Srgrimes */
971541Srgrimes#define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
981541Srgrimes#define	TCP_MAXSEG	0x02	/* set maximum segment size */
99