138451Smsmith/*	$NetBSD: net.h,v 1.10 1995/10/20 00:46:30 cgd Exp $	*/
238451Smsmith
338451Smsmith/*
438451Smsmith * Copyright (c) 1993 Adam Glass
538451Smsmith * Copyright (c) 1992 Regents of the University of California.
638451Smsmith * All rights reserved.
738451Smsmith *
838451Smsmith * This software was developed by the Computer Systems Engineering group
938451Smsmith * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
1038451Smsmith * contributed to Berkeley.
1138451Smsmith *
1238451Smsmith * Redistribution and use in source and binary forms, with or without
1338451Smsmith * modification, are permitted provided that the following conditions
1438451Smsmith * are met:
1538451Smsmith * 1. Redistributions of source code must retain the above copyright
1638451Smsmith *    notice, this list of conditions and the following disclaimer.
1738451Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1838451Smsmith *    notice, this list of conditions and the following disclaimer in the
1938451Smsmith *    documentation and/or other materials provided with the distribution.
2038451Smsmith * 4. Neither the name of the University nor the names of its contributors
2138451Smsmith *    may be used to endorse or promote products derived from this software
2238451Smsmith *    without specific prior written permission.
2338451Smsmith *
2438451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2538451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2638451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2738451Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2838451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2938451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3038451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3138451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3238451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3338451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3438451Smsmith * SUCH DAMAGE.
3564185Sjhb *
3664185Sjhb * $FreeBSD$
3738451Smsmith */
3838451Smsmith
3938451Smsmith#ifndef _KERNEL	/* XXX - see <netinet/in.h> */
4038451Smsmith#undef __IPADDR
4138451Smsmith#define __IPADDR(x)	htonl((u_int32_t)(x))
4238451Smsmith#endif
4338451Smsmith
4438451Smsmith#include "iodesc.h"
4538451Smsmith
4638451Smsmith#define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
4738451Smsmith
4838451Smsmith/* Returns true if n_long's on the same net */
4938451Smsmith#define	SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m))
5038451Smsmith
5138451Smsmith#define MACPY(s, d) bcopy((char *)s, (char *)d, 6)
5238451Smsmith
53213235Semaste#define MAXTMO 120	/* seconds */
5438451Smsmith#define MINTMO 2	/* seconds */
5538451Smsmith
5638451Smsmith#define FNAME_SIZE 128
5738451Smsmith#define	IFNAME_SIZE 16
5838451Smsmith#define RECV_SIZE 1536	/* XXX delete this */
5938451Smsmith
6038451Smsmith/*
6138451Smsmith * How much room to leave for headers:
6238451Smsmith *  14: struct ether_header
6338451Smsmith *  20: struct ip
6438451Smsmith *   8: struct udphdr
6538451Smsmith * That's 42 but let's pad it out to 48 bytes.
6638451Smsmith */
6738451Smsmith#define ETHER_SIZE 14
6838451Smsmith#define	HEADER_SIZE 48
6938451Smsmith
7038451Smsmithextern	u_char bcea[6];
7138451Smsmithextern	char rootpath[FNAME_SIZE];
7238451Smsmithextern	char bootfile[FNAME_SIZE];
7338451Smsmithextern	char hostname[FNAME_SIZE];
7438451Smsmithextern	int hostnamelen;
7538451Smsmithextern	char domainname[FNAME_SIZE];
7638451Smsmithextern	int domainnamelen;
7738451Smsmithextern	char ifname[IFNAME_SIZE];
7838451Smsmith
7938451Smsmith/* All of these are in network order. */
8038451Smsmithextern	struct in_addr myip;
8138451Smsmithextern	struct in_addr rootip;
8238451Smsmithextern	struct in_addr swapip;
8338451Smsmithextern	struct in_addr gateip;
8438451Smsmithextern	struct in_addr nameip;
8538451Smsmithextern	n_long netmask;
8638451Smsmith
8738451Smsmithextern	int debug;			/* defined in the machdep sources */
8838451Smsmith
8938451Smsmithextern struct iodesc sockets[SOPEN_MAX];
9038451Smsmith
9138451Smsmith/* ARP/RevARP functions: */
9238451Smsmithu_char	*arpwhohas(struct iodesc *, struct in_addr);
9338451Smsmithvoid	arp_reply(struct iodesc *, void *);
9438451Smsmithint	rarp_getipaddress(int);
9538451Smsmith
9638451Smsmith/* Link functions: */
9738451Smsmithssize_t sendether(struct iodesc *d, void *pkt, size_t len,
9838451Smsmith			u_char *dea, int etype);
9938451Smsmithssize_t readether(struct iodesc *d, void *pkt, size_t len,
10038451Smsmith			time_t tleft, u_int16_t *etype);
10138451Smsmith
10238451Smsmithssize_t	sendudp(struct iodesc *, void *, size_t);
10338451Smsmithssize_t	readudp(struct iodesc *, void *, size_t, time_t);
10438451Smsmithssize_t	sendrecv(struct iodesc *,
10538451Smsmith		      ssize_t (*)(struct iodesc *, void *, size_t),
10638451Smsmith			void *, size_t,
10738451Smsmith		        ssize_t (*)(struct iodesc *, void *, size_t, time_t),
10838451Smsmith			void *, size_t);
10938451Smsmith
11064185Sjhb/* bootp/DHCP */
11164527Spsvoid	bootp(int, int);
11264185Sjhb
11338451Smsmith/* Utilities: */
11438451Smsmithchar	*ether_sprintf(u_char *);
11538451Smsmithint	in_cksum(void *, int);
11638451Smsmithchar	*inet_ntoa(struct in_addr);
11738451Smsmithchar	*intoa(n_long);		/* similar to inet_ntoa */
11838451Smsmithn_long	inet_addr(char *);
11938451Smsmith
12038451Smsmith/* Machine-dependent functions: */
12138451Smsmithtime_t	getsecs(void);
122