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