xref: /minix3/sys/lib/libsa/net.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: net.h,v 1.27 2014/03/29 14:30:16 jakllsch Exp $	*/
258a2b000SEvgeniy Ivanov 
358a2b000SEvgeniy Ivanov /*
458a2b000SEvgeniy Ivanov  * Copyright (c) 1993 Adam Glass
558a2b000SEvgeniy Ivanov  * Copyright (c) 1992 Regents of the University of California.
658a2b000SEvgeniy Ivanov  * All rights reserved.
758a2b000SEvgeniy Ivanov  *
858a2b000SEvgeniy Ivanov  * This software was developed by the Computer Systems Engineering group
958a2b000SEvgeniy Ivanov  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
1058a2b000SEvgeniy Ivanov  * contributed to Berkeley.
1158a2b000SEvgeniy Ivanov  *
1258a2b000SEvgeniy Ivanov  * Redistribution and use in source and binary forms, with or without
1358a2b000SEvgeniy Ivanov  * modification, are permitted provided that the following conditions
1458a2b000SEvgeniy Ivanov  * are met:
1558a2b000SEvgeniy Ivanov  * 1. Redistributions of source code must retain the above copyright
1658a2b000SEvgeniy Ivanov  *    notice, this list of conditions and the following disclaimer.
1758a2b000SEvgeniy Ivanov  * 2. Redistributions in binary form must reproduce the above copyright
1858a2b000SEvgeniy Ivanov  *    notice, this list of conditions and the following disclaimer in the
1958a2b000SEvgeniy Ivanov  *    documentation and/or other materials provided with the distribution.
2058a2b000SEvgeniy Ivanov  * 3. All advertising materials mentioning features or use of this software
2158a2b000SEvgeniy Ivanov  *    must display the following acknowledgement:
2258a2b000SEvgeniy Ivanov  *	This product includes software developed by the University of
2358a2b000SEvgeniy Ivanov  *	California, Lawrence Berkeley Laboratory and its contributors.
2458a2b000SEvgeniy Ivanov  * 4. Neither the name of the University nor the names of its contributors
2558a2b000SEvgeniy Ivanov  *    may be used to endorse or promote products derived from this software
2658a2b000SEvgeniy Ivanov  *    without specific prior written permission.
2758a2b000SEvgeniy Ivanov  *
2858a2b000SEvgeniy Ivanov  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2958a2b000SEvgeniy Ivanov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3058a2b000SEvgeniy Ivanov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3158a2b000SEvgeniy Ivanov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3258a2b000SEvgeniy Ivanov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3358a2b000SEvgeniy Ivanov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3458a2b000SEvgeniy Ivanov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3558a2b000SEvgeniy Ivanov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3658a2b000SEvgeniy Ivanov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3758a2b000SEvgeniy Ivanov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3858a2b000SEvgeniy Ivanov  * SUCH DAMAGE.
3958a2b000SEvgeniy Ivanov  */
4058a2b000SEvgeniy Ivanov 
41*0a6a1f1dSLionel Sambuc #include <net/if_ether.h>	/* for ETHER_ADDR_LEN */
4258a2b000SEvgeniy Ivanov #include <netinet/in.h>
4358a2b000SEvgeniy Ivanov #include <netinet/in_systm.h>
4458a2b000SEvgeniy Ivanov 
4558a2b000SEvgeniy Ivanov #ifndef _KERNEL	/* XXX - see <netinet/in.h> */
4658a2b000SEvgeniy Ivanov #undef __IPADDR
4758a2b000SEvgeniy Ivanov #define __IPADDR(x)	htonl((u_int32_t)(x))
4858a2b000SEvgeniy Ivanov #endif
4958a2b000SEvgeniy Ivanov 
5058a2b000SEvgeniy Ivanov #ifdef _STANDALONE
5158a2b000SEvgeniy Ivanov #include <lib/libsa/iodesc.h>
5258a2b000SEvgeniy Ivanov #else
5358a2b000SEvgeniy Ivanov #include <iodesc.h>
5458a2b000SEvgeniy Ivanov #endif
5558a2b000SEvgeniy Ivanov 
5658a2b000SEvgeniy Ivanov #define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
5758a2b000SEvgeniy Ivanov 
5858a2b000SEvgeniy Ivanov /* Returns true if n_long's on the same net */
5958a2b000SEvgeniy Ivanov #define	SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m))
6058a2b000SEvgeniy Ivanov 
61*0a6a1f1dSLionel Sambuc #define MACPY(s, d) memcpy(d, s, ETHER_ADDR_LEN)
6258a2b000SEvgeniy Ivanov 
6358a2b000SEvgeniy Ivanov #define MAXTMO 20	/* seconds */
6458a2b000SEvgeniy Ivanov #define MINTMO 2	/* seconds */
6558a2b000SEvgeniy Ivanov 
6658a2b000SEvgeniy Ivanov #define FNAME_SIZE 128
6758a2b000SEvgeniy Ivanov #define	IFNAME_SIZE 16
6858a2b000SEvgeniy Ivanov #define RECV_SIZE 1536	/* XXX delete this */
6958a2b000SEvgeniy Ivanov 
7058a2b000SEvgeniy Ivanov /*
7158a2b000SEvgeniy Ivanov  * How much room to leave for headers in UDP packets:
7258a2b000SEvgeniy Ivanov  *  14: struct ether_header
7358a2b000SEvgeniy Ivanov  *  20: struct ip
7458a2b000SEvgeniy Ivanov  *   8: struct udphdr
7558a2b000SEvgeniy Ivanov  * That's 42 but let's pad it out to 48 bytes.
7658a2b000SEvgeniy Ivanov  */
7758a2b000SEvgeniy Ivanov #define ETHERNET_HEADER_SIZE 14
7858a2b000SEvgeniy Ivanov #define IP_HEADER_SIZE 20
7958a2b000SEvgeniy Ivanov #define UDP_HEADER_SIZE 8
8058a2b000SEvgeniy Ivanov 
8158a2b000SEvgeniy Ivanov #define	UDP_TOTAL_HEADER_SIZE (ETHERNET_HEADER_SIZE + IP_HEADER_SIZE + UDP_HEADER_SIZE)
8258a2b000SEvgeniy Ivanov 
8358a2b000SEvgeniy Ivanov /*
8458a2b000SEvgeniy Ivanov  * How much room to leave for headers in TCP packets:
8558a2b000SEvgeniy Ivanov  *  14: struct ether_header
8658a2b000SEvgeniy Ivanov  *  20: struct ip
8758a2b000SEvgeniy Ivanov  *  20: struct tcphdr
8858a2b000SEvgeniy Ivanov  */
8958a2b000SEvgeniy Ivanov #define TCP_HEADER_SIZE 20
9058a2b000SEvgeniy Ivanov 
9158a2b000SEvgeniy Ivanov #define TCP_TOTAL_HEADER_SIZE (ETHERNET_HEADER_SIZE + IP_HEADER_SIZE + TCP_HEADER_SIZE)
9258a2b000SEvgeniy Ivanov 
93*0a6a1f1dSLionel Sambuc extern	u_char bcea[ETHER_ADDR_LEN];
9458a2b000SEvgeniy Ivanov extern	char rootpath[FNAME_SIZE];
9558a2b000SEvgeniy Ivanov extern	char bootfile[FNAME_SIZE];
9658a2b000SEvgeniy Ivanov extern	char hostname[FNAME_SIZE];
9758a2b000SEvgeniy Ivanov 
9858a2b000SEvgeniy Ivanov /* All of these are in network order. */
9958a2b000SEvgeniy Ivanov extern	struct in_addr myip;
10058a2b000SEvgeniy Ivanov extern	struct in_addr rootip;
10158a2b000SEvgeniy Ivanov extern	struct in_addr gateip;
10258a2b000SEvgeniy Ivanov extern	n_long netmask;
10358a2b000SEvgeniy Ivanov 
10458a2b000SEvgeniy Ivanov extern	int debug;			/* defined in the machdep sources */
10558a2b000SEvgeniy Ivanov 
10658a2b000SEvgeniy Ivanov /* ARP/RevARP functions: */
10758a2b000SEvgeniy Ivanov u_char	*arpwhohas(struct iodesc *, struct in_addr);
10858a2b000SEvgeniy Ivanov void	arp_reply(struct iodesc *, void *);
10958a2b000SEvgeniy Ivanov int	rarp_getipaddress(int);
11058a2b000SEvgeniy Ivanov 
11158a2b000SEvgeniy Ivanov /* Link functions: */
11258a2b000SEvgeniy Ivanov ssize_t sendether(struct iodesc *, void *, size_t, u_char *, int);
11358a2b000SEvgeniy Ivanov ssize_t readether(struct iodesc *, void *, size_t, saseconds_t, u_int16_t *);
11458a2b000SEvgeniy Ivanov 
11558a2b000SEvgeniy Ivanov ssize_t	sendip __P((struct iodesc *, void *, size_t, u_int8_t));
11658a2b000SEvgeniy Ivanov ssize_t	readip __P((struct iodesc *, void *, size_t, time_t, u_int8_t));
11758a2b000SEvgeniy Ivanov 
11858a2b000SEvgeniy Ivanov ssize_t	sendudp(struct iodesc *, void *, size_t);
11958a2b000SEvgeniy Ivanov ssize_t	readudp(struct iodesc *, void *, size_t, saseconds_t);
12058a2b000SEvgeniy Ivanov 
12158a2b000SEvgeniy Ivanov int	tcp_connect __P((struct iodesc *));
12258a2b000SEvgeniy Ivanov ssize_t	sendtcp __P((struct iodesc *, void *, size_t));
12358a2b000SEvgeniy Ivanov ssize_t	readtcp __P((struct iodesc *, void *, size_t, time_t));
12458a2b000SEvgeniy Ivanov 
12558a2b000SEvgeniy Ivanov ssize_t	sendrecv(struct iodesc *, ssize_t (*)(struct iodesc *, void *, size_t),
12658a2b000SEvgeniy Ivanov     void *, size_t, ssize_t (*)(struct iodesc *, void *, size_t, saseconds_t),
12758a2b000SEvgeniy Ivanov     void *, size_t);
12858a2b000SEvgeniy Ivanov 
12958a2b000SEvgeniy Ivanov /* Utilities: */
13058a2b000SEvgeniy Ivanov char	*ether_sprintf(const u_char *);
13158a2b000SEvgeniy Ivanov int	ip_cksum(const void *, size_t);
13258a2b000SEvgeniy Ivanov 
13358a2b000SEvgeniy Ivanov /* Machine-dependent functions: */
13458a2b000SEvgeniy Ivanov #ifdef _STANDALONE	/* XXX for mount_nfs(8) SMALLPROG hack */
13558a2b000SEvgeniy Ivanov satime_t	getsecs(void);
13658a2b000SEvgeniy Ivanov #endif
137