net.h revision 64185
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 * 3. All advertising materials mentioning features or use of this software 2138451Smsmith * must display the following acknowledgement: 2238451Smsmith * This product includes software developed by the University of 2338451Smsmith * California, Lawrence Berkeley Laboratory and its contributors. 2438451Smsmith * 4. Neither the name of the University nor the names of its contributors 2538451Smsmith * may be used to endorse or promote products derived from this software 2638451Smsmith * without specific prior written permission. 2738451Smsmith * 2838451Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2938451Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3038451Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3138451Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3238451Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3338451Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3438451Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3538451Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3638451Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3738451Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3838451Smsmith * SUCH DAMAGE. 3964185Sjhb * 4064185Sjhb * $FreeBSD: head/lib/libstand/net.h 64185 2000-08-03 09:08:29Z jhb $ 4138451Smsmith */ 4238451Smsmith 4338451Smsmith#define NETIF_DEBUG 1 4438451Smsmith 4538451Smsmith#ifndef _KERNEL /* XXX - see <netinet/in.h> */ 4638451Smsmith#undef __IPADDR 4738451Smsmith#define __IPADDR(x) htonl((u_int32_t)(x)) 4838451Smsmith#endif 4938451Smsmith 5038451Smsmith#include "iodesc.h" 5138451Smsmith 5238451Smsmith#define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } 5338451Smsmith 5438451Smsmith/* Returns true if n_long's on the same net */ 5538451Smsmith#define SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m)) 5638451Smsmith 5738451Smsmith#define MACPY(s, d) bcopy((char *)s, (char *)d, 6) 5838451Smsmith 5938451Smsmith#define MAXTMO 20 /* seconds */ 6038451Smsmith#define MINTMO 2 /* seconds */ 6138451Smsmith 6238451Smsmith#define FNAME_SIZE 128 6338451Smsmith#define IFNAME_SIZE 16 6438451Smsmith#define RECV_SIZE 1536 /* XXX delete this */ 6538451Smsmith 6638451Smsmith/* 6738451Smsmith * How much room to leave for headers: 6838451Smsmith * 14: struct ether_header 6938451Smsmith * 20: struct ip 7038451Smsmith * 8: struct udphdr 7138451Smsmith * That's 42 but let's pad it out to 48 bytes. 7238451Smsmith */ 7338451Smsmith#define ETHER_SIZE 14 7438451Smsmith#define HEADER_SIZE 48 7538451Smsmith 7638451Smsmithextern u_char bcea[6]; 7738451Smsmithextern char rootpath[FNAME_SIZE]; 7838451Smsmithextern char bootfile[FNAME_SIZE]; 7938451Smsmithextern char hostname[FNAME_SIZE]; 8038451Smsmithextern int hostnamelen; 8138451Smsmithextern char domainname[FNAME_SIZE]; 8238451Smsmithextern int domainnamelen; 8338451Smsmithextern char ifname[IFNAME_SIZE]; 8438451Smsmith 8538451Smsmith/* All of these are in network order. */ 8638451Smsmithextern struct in_addr myip; 8738451Smsmithextern struct in_addr rootip; 8838451Smsmithextern struct in_addr swapip; 8938451Smsmithextern struct in_addr gateip; 9038451Smsmithextern struct in_addr nameip; 9138451Smsmithextern n_long netmask; 9238451Smsmith 9338451Smsmithextern int debug; /* defined in the machdep sources */ 9438451Smsmith 9538451Smsmithextern struct iodesc sockets[SOPEN_MAX]; 9638451Smsmith 9738451Smsmith/* ARP/RevARP functions: */ 9838451Smsmithu_char *arpwhohas(struct iodesc *, struct in_addr); 9938451Smsmithvoid arp_reply(struct iodesc *, void *); 10038451Smsmithint rarp_getipaddress(int); 10138451Smsmith 10238451Smsmith/* Link functions: */ 10338451Smsmithssize_t sendether(struct iodesc *d, void *pkt, size_t len, 10438451Smsmith u_char *dea, int etype); 10538451Smsmithssize_t readether(struct iodesc *d, void *pkt, size_t len, 10638451Smsmith time_t tleft, u_int16_t *etype); 10738451Smsmith 10838451Smsmithssize_t sendudp(struct iodesc *, void *, size_t); 10938451Smsmithssize_t readudp(struct iodesc *, void *, size_t, time_t); 11038451Smsmithssize_t sendrecv(struct iodesc *, 11138451Smsmith ssize_t (*)(struct iodesc *, void *, size_t), 11238451Smsmith void *, size_t, 11338451Smsmith ssize_t (*)(struct iodesc *, void *, size_t, time_t), 11438451Smsmith void *, size_t); 11538451Smsmith 11664185Sjhb/* bootp/DHCP */ 11764185Sjhbvoid bootp(int); 11864185Sjhb 11938451Smsmith/* Utilities: */ 12038451Smsmithchar *ether_sprintf(u_char *); 12138451Smsmithint in_cksum(void *, int); 12238451Smsmithchar *inet_ntoa(struct in_addr); 12338451Smsmithchar *intoa(n_long); /* similar to inet_ntoa */ 12438451Smsmithn_long inet_addr(char *); 12538451Smsmith 12638451Smsmith/* Machine-dependent functions: */ 12738451Smsmithtime_t getsecs(void); 128