xref: /freebsd/stand/libsa/net.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1ca987d46SWarner Losh /*	$NetBSD: net.h,v 1.10 1995/10/20 00:46:30 cgd Exp $	*/
2ca987d46SWarner Losh 
3ca987d46SWarner Losh /*
4ca987d46SWarner Losh  * Copyright (c) 1993 Adam Glass
5ca987d46SWarner Losh  * Copyright (c) 1992 Regents of the University of California.
6ca987d46SWarner Losh  * All rights reserved.
7ca987d46SWarner Losh  *
8ca987d46SWarner Losh  * This software was developed by the Computer Systems Engineering group
9ca987d46SWarner Losh  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10ca987d46SWarner Losh  * contributed to Berkeley.
11ca987d46SWarner Losh  *
12ca987d46SWarner Losh  * Redistribution and use in source and binary forms, with or without
13ca987d46SWarner Losh  * modification, are permitted provided that the following conditions
14ca987d46SWarner Losh  * are met:
15ca987d46SWarner Losh  * 1. Redistributions of source code must retain the above copyright
16ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer.
17ca987d46SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
18ca987d46SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
19ca987d46SWarner Losh  *    documentation and/or other materials provided with the distribution.
20ca987d46SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
21ca987d46SWarner Losh  *    may be used to endorse or promote products derived from this software
22ca987d46SWarner Losh  *    without specific prior written permission.
23ca987d46SWarner Losh  *
24ca987d46SWarner Losh  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25ca987d46SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26ca987d46SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27ca987d46SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28ca987d46SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29ca987d46SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30ca987d46SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31ca987d46SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32ca987d46SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33ca987d46SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34ca987d46SWarner Losh  * SUCH DAMAGE.
35ca987d46SWarner Losh  */
36ca987d46SWarner Losh 
37ca987d46SWarner Losh #ifndef _STAND_NET_H
38ca987d46SWarner Losh #define _STAND_NET_H
39ca987d46SWarner Losh #ifndef _KERNEL	/* XXX - see <netinet/in.h> */
40ca987d46SWarner Losh #undef __IPADDR
4156e53cb8SWarner Losh #define __IPADDR(x)	htonl((uint32_t)(x))
42ca987d46SWarner Losh #endif
43ca987d46SWarner Losh 
44ca987d46SWarner Losh #include "iodesc.h"
45ca987d46SWarner Losh 
46ca987d46SWarner Losh #define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
47ca987d46SWarner Losh 
48ca987d46SWarner Losh enum net_proto {
49ca987d46SWarner Losh 	NET_NONE,
50ca987d46SWarner Losh 	NET_NFS,
51ca987d46SWarner Losh 	NET_TFTP
52ca987d46SWarner Losh };
53ca987d46SWarner Losh 
54ca987d46SWarner Losh /* Returns true if n_long's on the same net */
55ca987d46SWarner Losh #define	SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m))
56ca987d46SWarner Losh 
57ca987d46SWarner Losh #define MACPY(s, d) bcopy((char *)s, (char *)d, 6)
58ca987d46SWarner Losh 
59ca987d46SWarner Losh #define MAXTMO 120	/* seconds */
60ca987d46SWarner Losh #define MINTMO 2	/* seconds */
61ca987d46SWarner Losh 
62ca987d46SWarner Losh #define FNAME_SIZE 128
63ca987d46SWarner Losh #define	IFNAME_SIZE 16
64ca987d46SWarner Losh #define RECV_SIZE 1536	/* XXX delete this */
65ca987d46SWarner Losh 
66ca987d46SWarner Losh /*
67ca987d46SWarner Losh  * How much room to leave for headers:
68ca987d46SWarner Losh  *  14: struct ether_header
69ca987d46SWarner Losh  *  20: struct ip
70ca987d46SWarner Losh  *   8: struct udphdr
71ca987d46SWarner Losh  * That's 42 but let's pad it out to 48 bytes.
72ca987d46SWarner Losh  */
73ca987d46SWarner Losh #define ETHER_SIZE 14
74ca987d46SWarner Losh #define	HEADER_SIZE 48
75ca987d46SWarner Losh 
76ca987d46SWarner Losh extern	u_char bcea[6];
77ca987d46SWarner Losh extern	char rootpath[FNAME_SIZE];
78ca987d46SWarner Losh extern	char bootfile[FNAME_SIZE];
79ca987d46SWarner Losh extern	char hostname[FNAME_SIZE];
80ca987d46SWarner Losh extern	int hostnamelen;
81ca987d46SWarner Losh extern	char domainname[FNAME_SIZE];
82ca987d46SWarner Losh extern	int domainnamelen;
83ca987d46SWarner Losh extern	int netproto;
84ca987d46SWarner Losh extern	char ifname[IFNAME_SIZE];
85ca987d46SWarner Losh 
86ca987d46SWarner Losh /* All of these are in network order. */
87ca987d46SWarner Losh extern	struct in_addr myip;
88ca987d46SWarner Losh extern	struct in_addr rootip;
89ca987d46SWarner Losh extern	struct in_addr swapip;
90ca987d46SWarner Losh extern	struct in_addr gateip;
91ca987d46SWarner Losh extern	struct in_addr nameip;
92*1ea71757SJustin Hibbits extern	struct in_addr servip;
93ca987d46SWarner Losh extern	n_long netmask;
94ca987d46SWarner Losh extern	u_int intf_mtu;
95ca987d46SWarner Losh 
96ca987d46SWarner Losh extern	int debug;			/* defined in the machdep sources */
97ca987d46SWarner Losh 
98ca987d46SWarner Losh /* ARP/RevARP functions: */
99ca987d46SWarner Losh u_char	*arpwhohas(struct iodesc *, struct in_addr);
100ca987d46SWarner Losh void	arp_reply(struct iodesc *, void *);
101ca987d46SWarner Losh int	rarp_getipaddress(int);
102ca987d46SWarner Losh 
103ca987d46SWarner Losh /* Link functions: */
104ca987d46SWarner Losh ssize_t sendether(struct iodesc *d, void *pkt, size_t len,
105ca987d46SWarner Losh 			u_char *dea, int etype);
106ca987d46SWarner Losh ssize_t readether(struct iodesc *, void **, void **, time_t, uint16_t *);
107ca987d46SWarner Losh 
108ca987d46SWarner Losh ssize_t	sendip(struct iodesc *, void *, size_t, uint8_t);
109ca987d46SWarner Losh ssize_t	readip(struct iodesc *, void **, void **, time_t, uint8_t);
110ca987d46SWarner Losh ssize_t	sendudp(struct iodesc *, void *, size_t);
111ca987d46SWarner Losh ssize_t	readudp(struct iodesc *, void **, void **, time_t);
112ca987d46SWarner Losh ssize_t	sendrecv(struct iodesc *,
113ca987d46SWarner Losh 			ssize_t (*)(struct iodesc *, void *, size_t),
114ca987d46SWarner Losh 			void *, size_t,
115c5b86c3bSKyle Evans 			ssize_t (*)(struct iodesc *, void **, void **, time_t,
116c5b86c3bSKyle Evans 			    void *),
117c5b86c3bSKyle Evans 			void **, void **, void *);
118ca987d46SWarner Losh 
119ca987d46SWarner Losh /* bootp/DHCP */
120ca987d46SWarner Losh void	bootp(int);
121ca987d46SWarner Losh 
122ca987d46SWarner Losh /* Utilities: */
123ca987d46SWarner Losh char	*ether_sprintf(u_char *);
124ca987d46SWarner Losh int	in_cksum(void *, int);
125ca987d46SWarner Losh char	*inet_ntoa(struct in_addr);
126ca987d46SWarner Losh char	*intoa(n_long);		/* similar to inet_ntoa */
127ca987d46SWarner Losh n_long	inet_addr(char *);
128ca987d46SWarner Losh 
129ca987d46SWarner Losh #endif /* ! _STAND_NET_H */
130