#ident "$Id: in.h,v 1.1 1995/03/16 17:05:07 garyp Exp $"
/*****************************************************************************
 * Copyright (c) 1988-95 Digi International Inc., All Rights Reserved
 * 
 * This  software  contains  proprietary  and  confidential   information   of
 * Digi International  Inc.   By  accepting  transfer  of this copy, Recipient
 * agrees to retain this software in  confidence,  to  prevent  disclosure  to
 * others,  and  to make no  use of this software other than that for which it
 * was delivered.  This is an unpublished copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/


/******************************************************************
 *
 *  SpiderTCP Application Include Files
 *
 *  Copyright (c) 1991 Spider Systems Limited
 *
 *  IN.H
 *
 *    A version of the BSD 4.2 file <netinet/in.h>
 *    for SpiderTCP
 *
 *
 ******************************************************************/

/*
 *	 /projects/common/PBRAIN/SCCS/pbrainF/dev/src/include/netinet/0/s.in.h
 *	@(#)in.h	1.30
 *
 *	Last delta created	16:21:22 1/14/91
 *	This file extracted	11:38:41 10/26/92
 *
 *	Modifications:
 *
 */

#ifndef __IN_HEADER__

#define __IN_HEADER__




#define TLI_TCP		"/dev/tcp"	/* or else */
#define TLI_UDP		"/dev/udp"	/* or else */

/*
 * Protocols
 */
#define IPPROTO_IP	      256		/* IP (for socket options etc) */
#define	IPPROTO_ICMP		1		/* control message protocol */
#define	IPPROTO_GGP		2		/* gateway^2 (deprecated) */
#define	IPPROTO_TCP		6		/* tcp */
#define	IPPROTO_EGP		8		/* exterior gateway protocol */
#define	IPPROTO_PUP		12		/* pup */
#define	IPPROTO_UDP		17		/* user datagram protocol */

#define	IPPROTO_RAW		255		/* raw IP packet */
#define	IPPROTO_MAX		256


#define ICMP_PROT       IPPROTO_ICMP 
#define GWAY_PROT       3
#define TCP_PROT        IPPROTO_TCP 
#define UDP_PROT        IPPROTO_UDP 


/*
 * define structure for DARPA internet address
 * usually use "longs" to access but sometimes need to split into
 * components
 */

typedef union {
		char  typea[4]; /* 4 x 8 bit version */
		short typeb[2];  /* 2 x 16 bit */
		long  typec;     /* 1 x 32 bit */
} IN_ADDRESS;


/*
 * Port/socket numbers: network standard functions
 */
#define	IPPORT_ECHO		7
#define	IPPORT_DISCARD		9
#define	IPPORT_SYSTAT		11
#define	IPPORT_DAYTIME		13
#define	IPPORT_NETSTAT		15
#define	IPPORT_FTP		21
#define	IPPORT_TELNET		23
#define	IPPORT_SMTP		25
#define	IPPORT_TIMESERVER	37
#define	IPPORT_NAMESERVER	42
#define	IPPORT_WHOIS		43
#define	IPPORT_MTP		57

/*
 * Port/socket numbers: host specific functions
 */
#define	IPPORT_TFTP		69
#define	IPPORT_RJE		77
#define	IPPORT_FINGER		79
#define	IPPORT_TTYLINK		87
#define	IPPORT_SUPDUP		95

#define	IPPORT_BIFFUDP		512
#define	IPPORT_EXECSERVER	512
#define	IPPORT_LOGINSERVER	513
#define	IPPORT_WHOSERVER	513
#define	IPPORT_CMDSERVER	514

/*
 * Ports < IPPORT_RESERVED are reserved for
 * privileged processes (e.g. root).
 */
#define	IPPORT_RESERVED		1024

/*
 * Link numbers
 */
#define	IMPLINK_IP		155
#define	IMPLINK_LOWEXPER	156
#define	IMPLINK_HIGHEXPER	158


/*
 * Internet address
 */
struct in_addr {
	union {
		struct { unsigned char s_b1,s_b2,s_b3,s_b4; } S_un_b;
		struct { unsigned short s_w1,s_w2; } S_un_w;
		unsigned long S_addr;
	} S_un;
#define	s_addr	S_un.S_addr	/* can be used for most tcp & ip code */
#define	s_host	S_un.S_un_b.s_b2	/* host on imp */
#define	s_net	S_un.S_un_b.s_b1	/* network */
#define	s_imp	S_un.S_un_w.s_w2	/* imp */
#define	s_impno	S_un.S_un_b.s_b4	/* imp # */
#define	s_lh	S_un.S_un_b.s_b3	/* logical host */
};

/*
 * Definitions of bits in internet address integers.
 */
#define	IN_CLASSA(i)		((((long)(i))&0x80000000)==0)
#define	IN_CLASSA_NET		0xff000000
#define	IN_CLASSA_NSHIFT	24
#define	IN_CLASSA_HOST		0x00ffffff
#define	IN_CLASSA_MAX		128

#define	IN_CLASSB(i)		((((long)(i))&0xc0000000)==0x80000000)
#define	IN_CLASSB_NET		0xffff0000
#define	IN_CLASSB_NSHIFT	16
#define	IN_CLASSB_HOST		0x0000ffff
#define	IN_CLASSB_MAX		65536

#define	IN_CLASSC(i)		((((long)(i))&0xc0000000)==0xc0000000)
#define	IN_CLASSC_NET		0xffffff00
#define	IN_CLASSC_NSHIFT	8
#define	IN_CLASSC_HOST		0x000000ff

#define	INADDR_ANY		0x00000000
#define	INADDR_BROADCAST	0xffffffff

/*
 * Socket address, internet style.
 */
struct sockaddr_in {
	short	sin_family;
	ushort	sin_port;
	struct	in_addr sin_addr;
	char	sin_zero[8];
};

/* Length of a SOCKADDR or SOCKADDR_IN structure */
#define SOCAD_LEN 16


#define	htons(x)	((((x) >> 8) & 0x00FF) | (((x) << 8) & 0xFF00))

#ifdef FUTURE
/*
 * this macro should be used if its faster than the function
 * - measure it on the target machine
 */
#define	htonl(x)	((((x) >> 24) & 0x000000FFL) | \
			(((x) >>  8) & 0x0000FF00L) | \
			(((x) <<  8) & 0x00FF0000L) | \
			(((x) << 24) & 0xFF000000L))
#else
extern long htonl();
#endif

#define	ntohs(x)	htons(x)
#define	ntohl(x)	htonl(x)

#define MASKA	0x000000FFL
#define MASKB	0x0000FFFFL
#define MASKC	0x00FFFFFFL
#define CLSHFT  5               /* Make C generate hyper-optimized case */


#define CLA0    0               /* It takes the same arg; you mask it off, */
#define CLA1    1               /* shift, and then do a case statment with */
#define CLA2    2               /* some code having more than one label. */
#define CLA3    3               /* Values for class A */
#define CLB0    4
#define CLB1    5               /* B */
#define CLC     6               /* C */
#define CLI     7               /* Illegal */

#define BROADCAST 0x00000000L

#define CASTA   0x00FFFFFFL
#define CASTB   0x0000FFFFL
#define CASTC   0x000000FFL


/****************************************************************** 
 *
 * Type Codes for Ethernet packets
 *
 ******************************************************************/

#define TY_ETHER 1
#ifndef TYPE_HACK
#define TY_PUP		0x0200
#define TY_IDP		0x0600
#define TY_IP		0x0800
#define TY_X25		0x0805
#define TY_ARP		0x0806
#ifndef NOTRAILER
#define TY_TRAIL	0x1000
#define TY_TRAIL_LO	0x1001
#define TY_TRAIL_HI	0x1002
#endif
#define TY_ECHO		0x9000
#else /*TYPE_HACK*/
#define TY_PUP		0x0200
#define TY_IDP		0x0600
#define TY_IP		0x0807		/* modified */
#define TY_X25		0x0805
#define TY_ARP		0x0808		/* modified */
#ifndef NOTRAILER
#define TY_TRAIL	0x2000		/* modified */
#define TY_TRAIL_LO	0x2001		/* modified */
#define TY_TRAIL_HI	0x2002		/* modified */
#endif
#define TY_ECHO		0x9000
#endif /*TYPE_HACK*/

/*
 * LOOPBACK Address - in host and network byte order
 */
#define LOOPBACK 0x7F000001L
#define NLOOPBACK 0x0100007FL

/*
 * interface flags
 */
#define IFF_UP			0x01
#define IFF_BROADCAST		0x02
#define IFF_LOOPBACK		0x04
#define IFF_POINTOPOINT		0x08
#define IFF_FORWARDBROADCAST	0x10
#define IFF_NOKEEPALIVE		0x20
#define IFF_SLOWLINK		0x40


/*
 * IP Options
 */

#define IPO_TTL		103
#define IPO_TOS		104
#define	IPO_OPTS	105
#define IPO_RDOPTION	106
#define	IPO_RDROUTE	IPO_RDOPTION	
#define IPO_OPTCOUNT	107	
#define IPO_RRCOUNT	IPO_OPTCOUNT	


/*
 * IP Option values
 */

#define OPT_SECURITY	130
#define OPT_LSRR	131
#define OPT_SSRR	137
#define OPT_RR		  7
#define OPT_STRID	136
#define OPT_TIMESTAMP	 68

/*
 * Default Time to Live
 */

#define IHTTL	60

/*
 * Maximum number of hops stored in a recorded route packet
 */

#define TCP_RR_MAX	16

#define MAXOPTLEN 256


#endif	/* __IN_HEADER__ */
