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