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