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: stable/11/stand/libsa/net.h 332154 2018-04-06 21:37:25Z kevans $ 3738451Smsmith */ 3838451Smsmith 39307632Sbapt#ifndef _STAND_NET_H 40307632Sbapt#define _STAND_NET_H 4138451Smsmith#ifndef _KERNEL /* XXX - see <netinet/in.h> */ 4238451Smsmith#undef __IPADDR 43332154Skevans#define __IPADDR(x) htonl((uint32_t)(x)) 4438451Smsmith#endif 4538451Smsmith 4638451Smsmith#include "iodesc.h" 4738451Smsmith 4838451Smsmith#define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } 4938451Smsmith 50307632Sbaptenum net_proto { 51307632Sbapt NET_NONE, 52307632Sbapt NET_NFS, 53307632Sbapt NET_TFTP 54307632Sbapt}; 55307632Sbapt 5638451Smsmith/* Returns true if n_long's on the same net */ 5738451Smsmith#define SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m)) 5838451Smsmith 5938451Smsmith#define MACPY(s, d) bcopy((char *)s, (char *)d, 6) 6038451Smsmith 61213235Semaste#define MAXTMO 120 /* seconds */ 6238451Smsmith#define MINTMO 2 /* seconds */ 6338451Smsmith 6438451Smsmith#define FNAME_SIZE 128 6538451Smsmith#define IFNAME_SIZE 16 6638451Smsmith#define RECV_SIZE 1536 /* XXX delete this */ 6738451Smsmith 6838451Smsmith/* 6938451Smsmith * How much room to leave for headers: 7038451Smsmith * 14: struct ether_header 7138451Smsmith * 20: struct ip 7238451Smsmith * 8: struct udphdr 7338451Smsmith * That's 42 but let's pad it out to 48 bytes. 7438451Smsmith */ 7538451Smsmith#define ETHER_SIZE 14 7638451Smsmith#define HEADER_SIZE 48 7738451Smsmith 7838451Smsmithextern u_char bcea[6]; 7938451Smsmithextern char rootpath[FNAME_SIZE]; 8038451Smsmithextern char bootfile[FNAME_SIZE]; 8138451Smsmithextern char hostname[FNAME_SIZE]; 8238451Smsmithextern int hostnamelen; 8338451Smsmithextern char domainname[FNAME_SIZE]; 8438451Smsmithextern int domainnamelen; 85307632Sbaptextern int netproto; 8638451Smsmithextern char ifname[IFNAME_SIZE]; 8738451Smsmith 8838451Smsmith/* All of these are in network order. */ 8938451Smsmithextern struct in_addr myip; 9038451Smsmithextern struct in_addr rootip; 9138451Smsmithextern struct in_addr swapip; 9238451Smsmithextern struct in_addr gateip; 9338451Smsmithextern struct in_addr nameip; 9438451Smsmithextern n_long netmask; 95297150Sianextern u_int intf_mtu; 9638451Smsmith 9738451Smsmithextern int debug; /* defined in the machdep sources */ 9838451Smsmith 9938451Smsmithextern struct iodesc sockets[SOPEN_MAX]; 10038451Smsmith 10138451Smsmith/* ARP/RevARP functions: */ 10238451Smsmithu_char *arpwhohas(struct iodesc *, struct in_addr); 10338451Smsmithvoid arp_reply(struct iodesc *, void *); 10438451Smsmithint rarp_getipaddress(int); 10538451Smsmith 10638451Smsmith/* Link functions: */ 10738451Smsmithssize_t sendether(struct iodesc *d, void *pkt, size_t len, 10838451Smsmith u_char *dea, int etype); 109329100Skevansssize_t readether(struct iodesc *, void **, void **, time_t, uint16_t *); 11038451Smsmith 111329100Skevansssize_t sendip(struct iodesc *, void *, size_t, uint8_t); 112329100Skevansssize_t readip(struct iodesc *, void **, void **, time_t, uint8_t); 11338451Smsmithssize_t sendudp(struct iodesc *, void *, size_t); 114329100Skevansssize_t readudp(struct iodesc *, void **, void **, time_t); 11538451Smsmithssize_t sendrecv(struct iodesc *, 116329100Skevans ssize_t (*)(struct iodesc *, void *, size_t), 11738451Smsmith void *, size_t, 118330898Skevans ssize_t (*)(struct iodesc *, void **, void **, time_t, 119330898Skevans void *), 120330898Skevans void **, void **, void *); 12138451Smsmith 12264185Sjhb/* bootp/DHCP */ 123329100Skevansvoid bootp(int); 12464185Sjhb 12538451Smsmith/* Utilities: */ 12638451Smsmithchar *ether_sprintf(u_char *); 12738451Smsmithint in_cksum(void *, int); 12838451Smsmithchar *inet_ntoa(struct in_addr); 12938451Smsmithchar *intoa(n_long); /* similar to inet_ntoa */ 13038451Smsmithn_long inet_addr(char *); 13138451Smsmith 132307632Sbapt#endif /* ! _STAND_NET_H */ 133