xref: /titanic_52/usr/src/boot/lib/libstand/net.h (revision 7b2a1233f92b2b3cb858f2fdb69378a9ab0a42f1)
14a5d661aSToomas Soome /*	$NetBSD: net.h,v 1.10 1995/10/20 00:46:30 cgd Exp $	*/
24a5d661aSToomas Soome 
34a5d661aSToomas Soome /*
44a5d661aSToomas Soome  * Copyright (c) 1993 Adam Glass
54a5d661aSToomas Soome  * Copyright (c) 1992 Regents of the University of California.
64a5d661aSToomas Soome  * All rights reserved.
74a5d661aSToomas Soome  *
84a5d661aSToomas Soome  * This software was developed by the Computer Systems Engineering group
94a5d661aSToomas Soome  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
104a5d661aSToomas Soome  * contributed to Berkeley.
114a5d661aSToomas Soome  *
124a5d661aSToomas Soome  * Redistribution and use in source and binary forms, with or without
134a5d661aSToomas Soome  * modification, are permitted provided that the following conditions
144a5d661aSToomas Soome  * are met:
154a5d661aSToomas Soome  * 1. Redistributions of source code must retain the above copyright
164a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer.
174a5d661aSToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
184a5d661aSToomas Soome  *    notice, this list of conditions and the following disclaimer in the
194a5d661aSToomas Soome  *    documentation and/or other materials provided with the distribution.
204a5d661aSToomas Soome  * 4. Neither the name of the University nor the names of its contributors
214a5d661aSToomas Soome  *    may be used to endorse or promote products derived from this software
224a5d661aSToomas Soome  *    without specific prior written permission.
234a5d661aSToomas Soome  *
244a5d661aSToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
254a5d661aSToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
264a5d661aSToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
274a5d661aSToomas Soome  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
284a5d661aSToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
294a5d661aSToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
304a5d661aSToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
314a5d661aSToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
324a5d661aSToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
334a5d661aSToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
344a5d661aSToomas Soome  * SUCH DAMAGE.
354a5d661aSToomas Soome  *
364a5d661aSToomas Soome  * $FreeBSD$
374a5d661aSToomas Soome  */
384a5d661aSToomas Soome 
3918609d04SToomas Soome #ifndef _STAND_NET_H
4018609d04SToomas Soome #define	_STAND_NET_H
414a5d661aSToomas Soome #ifndef _KERNEL	/* XXX - see <netinet/in.h> */
424a5d661aSToomas Soome #undef __IPADDR
434a5d661aSToomas Soome #define __IPADDR(x)	htonl((u_int32_t)(x))
444a5d661aSToomas Soome #endif
454a5d661aSToomas Soome 
464a5d661aSToomas Soome #include "iodesc.h"
474a5d661aSToomas Soome 
484a5d661aSToomas Soome #define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
494a5d661aSToomas Soome 
5018609d04SToomas Soome enum net_proto {
5118609d04SToomas Soome 	NET_NONE,
5218609d04SToomas Soome 	NET_NFS,
5318609d04SToomas Soome 	NET_TFTP
5418609d04SToomas Soome };
5518609d04SToomas Soome 
564a5d661aSToomas Soome /* Returns true if n_long's on the same net */
574a5d661aSToomas Soome #define	SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m))
584a5d661aSToomas Soome 
594a5d661aSToomas Soome #define MACPY(s, d) bcopy((char *)s, (char *)d, 6)
604a5d661aSToomas Soome 
614a5d661aSToomas Soome #define MAXTMO 120	/* seconds */
624a5d661aSToomas Soome #define MINTMO 2	/* seconds */
634a5d661aSToomas Soome 
644a5d661aSToomas Soome #define FNAME_SIZE 128
654a5d661aSToomas Soome #define	IFNAME_SIZE 16
664a5d661aSToomas Soome #define RECV_SIZE 1536	/* XXX delete this */
674a5d661aSToomas Soome 
684a5d661aSToomas Soome /*
694a5d661aSToomas Soome  * How much room to leave for headers:
704a5d661aSToomas Soome  *  14: struct ether_header
714a5d661aSToomas Soome  *  20: struct ip
724a5d661aSToomas Soome  *   8: struct udphdr
734a5d661aSToomas Soome  * That's 42 but let's pad it out to 48 bytes.
744a5d661aSToomas Soome  */
754a5d661aSToomas Soome #define ETHER_SIZE 14
764a5d661aSToomas Soome #define	HEADER_SIZE 48
774a5d661aSToomas Soome 
784a5d661aSToomas Soome extern	u_char bcea[6];
794a5d661aSToomas Soome extern	char rootpath[FNAME_SIZE];
804a5d661aSToomas Soome extern	char bootfile[FNAME_SIZE];
814a5d661aSToomas Soome extern	char hostname[FNAME_SIZE];
824a5d661aSToomas Soome extern	int hostnamelen;
834a5d661aSToomas Soome extern	char domainname[FNAME_SIZE];
844a5d661aSToomas Soome extern	int domainnamelen;
8518609d04SToomas Soome extern	int netproto;
864a5d661aSToomas Soome extern	char ifname[IFNAME_SIZE];
874a5d661aSToomas Soome 
884a5d661aSToomas Soome /* All of these are in network order. */
894a5d661aSToomas Soome extern	struct in_addr myip;
904a5d661aSToomas Soome extern	struct in_addr rootip;
914a5d661aSToomas Soome extern	struct in_addr swapip;
924a5d661aSToomas Soome extern	struct in_addr gateip;
934a5d661aSToomas Soome extern	struct in_addr nameip;
9418609d04SToomas Soome extern	struct in_addr tftpip;
954a5d661aSToomas Soome extern	n_long netmask;
96e1bd2803SToomas Soome extern	u_int intf_mtu;
974a5d661aSToomas Soome 
984a5d661aSToomas Soome extern	int debug;			/* defined in the machdep sources */
994a5d661aSToomas Soome 
1004a5d661aSToomas Soome extern struct iodesc sockets[SOPEN_MAX];
1014a5d661aSToomas Soome 
1024a5d661aSToomas Soome /* ARP/RevARP functions: */
1034a5d661aSToomas Soome u_char	*arpwhohas(struct iodesc *, struct in_addr);
1044a5d661aSToomas Soome void	arp_reply(struct iodesc *, void *);
1054a5d661aSToomas Soome int	rarp_getipaddress(int);
1064a5d661aSToomas Soome 
1074a5d661aSToomas Soome /* Link functions: */
1084a5d661aSToomas Soome ssize_t sendether(struct iodesc *d, void *pkt, size_t len,
1094a5d661aSToomas Soome 			u_char *dea, int etype);
110*7b2a1233SToomas Soome ssize_t readether(struct iodesc *, void **, void **, time_t, u_int16_t *);
1114a5d661aSToomas Soome 
1124a5d661aSToomas Soome ssize_t	sendudp(struct iodesc *, void *, size_t);
113*7b2a1233SToomas Soome ssize_t	readudp(struct iodesc *, void **, void **, time_t);
1144a5d661aSToomas Soome ssize_t	sendrecv(struct iodesc *,
1154a5d661aSToomas Soome 		      ssize_t (*)(struct iodesc *, void *, size_t),
1164a5d661aSToomas Soome 			void *, size_t,
117*7b2a1233SToomas Soome 		        ssize_t (*)(struct iodesc *, void **, void **, time_t),
118*7b2a1233SToomas Soome 			void **, void **);
1194a5d661aSToomas Soome 
1204a5d661aSToomas Soome /* bootp/DHCP */
1214a5d661aSToomas Soome void	bootp(int, int);
1224a5d661aSToomas Soome 
1234a5d661aSToomas Soome /* Utilities: */
1244a5d661aSToomas Soome char	*ether_sprintf(u_char *);
1254a5d661aSToomas Soome int	in_cksum(void *, int);
1264a5d661aSToomas Soome char	*inet_ntoa(struct in_addr);
1274a5d661aSToomas Soome char	*intoa(n_long);		/* similar to inet_ntoa */
1284a5d661aSToomas Soome n_long	inet_addr(char *);
1294a5d661aSToomas Soome 
1304a5d661aSToomas Soome /* Machine-dependent functions: */
1314a5d661aSToomas Soome time_t	getsecs(void);
13218609d04SToomas Soome #endif	/* ! _STAND_NET_H */
133