Another round of clean up, including fixes presented by Matthias Drochner

(PR#1404). Things to be noted:
	- all IP addresses are now `struct in_addr's.
	- the function rarp_getipaddress() no longer return `myip'; in stead
	  it returns -1 on failure (errno set), 0 on success. `myip' is set
	  as a size-effect.
This commit is contained in:
pk 1995-09-18 21:19:18 +00:00
parent 05f929580f
commit d9124da47f
17 changed files with 212 additions and 206 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: arp.c,v 1.9 1995/09/14 23:45:21 pk Exp $ */
/* $NetBSD: arp.c,v 1.10 1995/09/18 21:19:18 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -56,7 +56,7 @@
#define ARP_NUM 8 /* need at most 3 arp entries */
static struct arp_list {
n_long addr;
struct in_addr addr;
u_char ea[6];
} arp_list[ARP_NUM] = {
{ INADDR_BROADCAST, BA }
@ -71,7 +71,7 @@ static ssize_t arprecv __P((struct iodesc *, void *, size_t, time_t));
u_char *
arpwhohas(d, addr)
register struct iodesc *d;
n_long addr;
struct in_addr addr;
{
register int i;
register struct ether_arp *ah;
@ -93,11 +93,11 @@ arpwhohas(d, addr)
#ifdef ARP_DEBUG
if (debug)
printf("arpwhohas: called for %s\n", intoa(addr));
printf("arpwhohas: called for %s\n", inet_ntoa(addr));
#endif
/* Try for cached answer first */
for (i = 0, al = arp_list; i < arp_num; ++i, ++al)
if (addr == al->addr)
if (addr.s_addr == al->addr.s_addr)
return (al->ea);
/* Don't overflow cache */

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootp.c,v 1.6 1995/09/14 23:45:22 pk Exp $ */
/* $NetBSD: bootp.c,v 1.7 1995/09/18 21:19:20 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -101,15 +101,15 @@ bootp(sock)
bp->bp_op = BOOTREQUEST;
bp->bp_htype = 1; /* 10Mb Ethernet (48 bits) */
bp->bp_hlen = 6;
bp->bp_xid = d->xid;
bp->bp_xid = htonl(d->xid);
MACPY(d->myea, bp->bp_chaddr);
bzero(bp->bp_file, sizeof(bp->bp_file));
bcopy(vm_rfc1048, bp->bp_vend, sizeof(vm_rfc1048));
d->myip = myip;
d->myport = IPPORT_BOOTPC;
d->destip = INADDR_BROADCAST;
d->destport = IPPORT_BOOTPS;
d->myport = htons(IPPORT_BOOTPC);
d->destip.s_addr = INADDR_BROADCAST;
d->destport = htons(IPPORT_BOOTPS);
(void)sendrecv(d,
bootpsend, bp, sizeof(*bp),
@ -134,7 +134,7 @@ bootpsend(d, pkt, len)
#endif
bp = pkt;
bp->bp_secs = (u_long)(getsecs() - bot);
bp->bp_secs = htons((u_short)(getsecs() - bot));
#ifdef BOOTP_DEBUG
if (debug)
@ -165,18 +165,17 @@ bootprecv(d, pkt, len, tleft)
goto bad;
bp = (struct bootp *)pkt;
NTOHL(bp->bp_xid);
#ifdef BOOTP_DEBUG
if (debug)
printf("bootprecv: checked. bp = 0x%x, n = %d\n",
(unsigned)bp, n);
#endif
if (bp->bp_xid != d->xid) {
if (bp->bp_xid != htonl(d->xid)) {
#ifdef BOOTP_DEBUG
if (debug) {
printf("bootprecv: expected xid 0x%x, got 0x%x\n",
d->xid, bp->bp_xid);
d->xid, ntohl(bp->bp_xid));
}
#endif
goto bad;
@ -188,14 +187,14 @@ bootprecv(d, pkt, len, tleft)
#endif
/* Pick up our ip address (and natural netmask) */
myip = d->myip = ntohl(bp->bp_yiaddr.s_addr);
myip = d->myip = bp->bp_yiaddr;
#ifdef BOOTP_DEBUG
if (debug)
printf("our ip address is %s\n", intoa(d->myip));
printf("our ip address is %s\n", inet_ntoa(d->myip));
#endif
if (IN_CLASSA(d->myip))
if (IN_CLASSA(d->myip.s_addr))
nmask = IN_CLASSA_NET;
else if (IN_CLASSB(d->myip))
else if (IN_CLASSB(d->myip.s_addr))
nmask = IN_CLASSB_NET;
else
nmask = IN_CLASSC_NET;
@ -206,7 +205,7 @@ bootprecv(d, pkt, len, tleft)
/* Pick up root or swap server address and file spec. */
if (bp->bp_siaddr.s_addr != 0)
rootip = ntohl(bp->bp_siaddr.s_addr);
rootip = bp->bp_siaddr;
if (bp->bp_file[0] != '\0') {
strncpy(bootfile, (char *)bp->bp_file, sizeof(bootfile));
bootfile[sizeof(bootfile) - 1] = '\0';
@ -230,23 +229,23 @@ bootprecv(d, pkt, len, tleft)
}
/* Get subnet (or natural net) mask */
mask = nmask;
netmask = nmask;
if (smask)
mask = smask;
netmask = smask;
#ifdef BOOTP_DEBUG
if (debug)
printf("mask: %s\n", intoa(mask));
printf("mask: %s\n", intoa(netmask));
#endif
/* We need a gateway if root or swap is on a different net */
if (!SAMENET(d->myip, rootip, mask)) {
if (!SAMENET(d->myip, rootip, netmask)) {
#ifdef BOOTP_DEBUG
if (debug)
printf("need gateway for root ip\n");
#endif
}
if (!SAMENET(d->myip, swapip, mask)) {
if (!SAMENET(d->myip, swapip, netmask)) {
#ifdef BOOTP_DEBUG
if (debug)
printf("need gateway for swap ip\n");
@ -254,12 +253,12 @@ bootprecv(d, pkt, len, tleft)
}
/* Toss gateway if on a different net */
if (!SAMENET(d->myip, gateip, mask)) {
if (!SAMENET(d->myip, gateip, netmask)) {
#ifdef BOOTP_DEBUG
if (debug)
printf("gateway ip (%s) bad\n", intoa(gateip));
printf("gateway ip (%s) bad\n", inet_ntoa(gateip));
#endif
gateip = 0;
gateip.s_addr = 0;
}
return (n);
@ -282,10 +281,10 @@ vend_cmu(cp)
vp = (struct cmu_vend *)cp;
if (vp->v_smask.s_addr != 0) {
smask = ntohl(vp->v_smask.s_addr);
smask = vp->v_smask.s_addr;
}
if (vp->v_dgate.s_addr != 0) {
gateip = ntohl(vp->v_dgate.s_addr);
gateip = vp->v_dgate;
}
}
@ -315,30 +314,26 @@ vend_rfc1048(cp, len)
if (tag == TAG_SUBNET_MASK) {
bcopy(cp, &smask, sizeof(smask));
smask = ntohl(smask);
}
if (tag == TAG_GATEWAY) {
bcopy(cp, &gateip, sizeof(gateip));
gateip = ntohl(gateip);
bcopy(cp, &gateip.s_addr, sizeof(gateip.s_addr));
}
if (tag == TAG_SWAPSERVER) {
bcopy(cp, &swapip, sizeof(swapip));
swapip = ntohl(swapip);
bcopy(cp, &swapip.s_addr, sizeof(swapip.s_addr));
}
if (tag == TAG_DOMAIN_SERVER) {
bcopy(cp, &nameip, sizeof(nameip));
nameip = ntohl(nameip);
bcopy(cp, &nameip.s_addr, sizeof(nameip.s_addr));
}
if (tag == TAG_ROOTPATH) {
strncpy(rootpath, cp, sizeof(rootpath));
strncpy(rootpath, (char *)cp, sizeof(rootpath));
rootpath[size] = '\0';
}
if (tag == TAG_HOSTNAME) {
strncpy(hostname, cp, sizeof(hostname));
strncpy(hostname, (char *)cp, sizeof(hostname));
hostname[size] = '\0';
}
if (tag == TAG_DOMAINNAME) {
strncpy(domainname, cp, sizeof(domainname));
strncpy(domainname, (char *)cp, sizeof(domainname));
domainname[size] = '\0';
}
cp += size;

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootparam.c,v 1.3 1995/09/17 00:49:38 pk Exp $ */
/* $NetBSD: bootparam.c,v 1.4 1995/09/18 21:19:22 pk Exp $ */
/*
* Copyright (c) 1995 Gordon W. Ross
@ -52,15 +52,9 @@
#include "rpc.h"
#include "bootparam.h"
n_long bp_server_addr; /* net order */
struct in_addr bp_server_addr; /* net order */
n_short bp_server_port; /* net order */
int hostnamelen;
char hostname[FNAME_SIZE];
int domainnamelen;
char domainname[FNAME_SIZE];
/*
* RPC definitions for bootparamd
*/
@ -78,8 +72,8 @@ struct xdr_inaddr {
int32_t addr[4];
};
int xdr_inaddr_encode __P((void **p, n_long ia));
int xdr_inaddr_decode __P((void **p, n_long *ia));
int xdr_inaddr_encode __P((void **p, struct in_addr ia));
int xdr_inaddr_decode __P((void **p, struct in_addr *ia));
int xdr_string_encode __P((void **p, char *str, int len));
int xdr_string_decode __P((void **p, char *str, int *len_p));
@ -131,12 +125,12 @@ bp_whoami(sockfd)
int len, x;
#ifdef RPC_DEBUG
printf("bp_whoami: myip=0x%x\n", myip);
printf("bp_whoami: myip=%s\n", inet_ntoa(myip));
#endif
if (!(d = socktodesc(sockfd))) {
printf("bp_whoami: bad socket. %d\n", sockfd);
return (EBADF);
return (-1);
}
args = &sdata.d;
repl = &rdata.d;
@ -158,7 +152,7 @@ bp_whoami(sockfd)
/* RPC: portmap/callit */
d->myport = htons(--rpc_port);
d->destip = htonl(INADDR_BROADCAST); /* XXX: subnet bcast? */
d->destip.s_addr = INADDR_BROADCAST; /* XXX: subnet bcast? */
/* rpc_call will set d->destport */
len = rpc_call(d, PMAPPROG, PMAPVERS, PMAPPROC_CALLIT,
@ -166,7 +160,7 @@ bp_whoami(sockfd)
repl, sizeof(*repl));
if (len < 8) {
printf("bootparamd: 'whoami' call failed\n");
return(-1);
return (-1);
}
/* Save bootparam server address (from IP header). */
@ -181,7 +175,7 @@ bp_whoami(sockfd)
#ifdef RPC_DEBUG
printf("bp_whoami: server at %s:%d\n",
intoa(bp_server_addr), ntohs(bp_server_port));
inet_ntoa(bp_server_addr), ntohs(bp_server_port));
#endif
/* We have just done a portmap call, so cache the portnum. */
@ -196,7 +190,7 @@ bp_whoami(sockfd)
x = ntohl(repl->encap_len);
if (len < x) {
printf("bp_whoami: short reply, %d < %d\n", len, x);
return(-1);
return (-1);
}
recv_head = repl->capsule;
@ -206,7 +200,7 @@ bp_whoami(sockfd)
#ifdef RPC_DEBUG
printf("bp_whoami: bad hostname\n");
#endif
return(-1);
return (-1);
}
/* domain name */
@ -215,7 +209,7 @@ bp_whoami(sockfd)
#ifdef RPC_DEBUG
printf("bp_whoami: bad domainname\n");
#endif
return(-1);
return (-1);
}
/* gateway address */
@ -223,7 +217,7 @@ bp_whoami(sockfd)
#ifdef RPC_DEBUG
printf("bp_whoami: bad gateway\n");
#endif
return(-1);
return (-1);
}
/* success */
@ -243,7 +237,7 @@ bp_getfile(sockfd, key, serv_addr, pathname)
int sockfd;
char *key;
char *pathname;
n_long *serv_addr;
struct in_addr *serv_addr;
{
struct {
n_long h[RPC_HEADER_WORDS];
@ -261,7 +255,7 @@ bp_getfile(sockfd, key, serv_addr, pathname)
if (!(d = socktodesc(sockfd))) {
printf("bp_getfile: bad socket. %d\n", sockfd);
return (EBADF);
return (-1);
}
send_tail = sdata.d;
@ -300,7 +294,8 @@ bp_getfile(sockfd, key, serv_addr, pathname)
#ifdef RPC_DEBUG
printf("bp_getfile: short reply\n");
#endif
return(-1);
errno = EBADRPC;
return (-1);
}
recv_head = rdata.d;
@ -314,7 +309,7 @@ bp_getfile(sockfd, key, serv_addr, pathname)
#ifdef RPC_DEBUG
printf("bp_getfile: bad server name\n");
#endif
return(-1);
return (-1);
}
/* server IP address (mountd/NFS) */
@ -322,7 +317,7 @@ bp_getfile(sockfd, key, serv_addr, pathname)
#ifdef RPC_DEBUG
printf("bp_getfile: bad server addr\n");
#endif
return(-1);
return (-1);
}
/* server pathname */
@ -331,7 +326,7 @@ bp_getfile(sockfd, key, serv_addr, pathname)
#ifdef RPC_DEBUG
printf("bp_getfile: bad server path\n");
#endif
return(-1);
return (-1);
}
/* success */
@ -398,7 +393,7 @@ xdr_string_decode(pkt, str, len_p)
int
xdr_inaddr_encode(pkt, ia)
void **pkt;
n_long ia; /* host order */
struct in_addr ia;
{
struct xdr_inaddr *xi;
u_char *cp;
@ -411,13 +406,13 @@ xdr_inaddr_encode(pkt, ia)
xi = *pkt;
*(char**)pkt += sizeof(*xi);
xi->atype = htonl(1);
uia.l = htonl(ia);
uia.l = ia.s_addr;
cp = uia.c;
ip = xi->addr;
*ip++ = *cp++;
*ip++ = *cp++;
*ip++ = *cp++;
*ip++ = *cp++;
*ip++ = htonl((unsigned int)*cp++);
*ip++ = htonl((unsigned int)*cp++);
*ip++ = htonl((unsigned int)*cp++);
*ip++ = htonl((unsigned int)*cp++);
return (0);
}
@ -425,7 +420,7 @@ xdr_inaddr_encode(pkt, ia)
int
xdr_inaddr_decode(pkt, ia)
void **pkt;
n_long *ia; /* host order */
struct in_addr *ia; /* host order */
{
struct xdr_inaddr *xi;
u_char *cp;
@ -445,14 +440,13 @@ xdr_inaddr_decode(pkt, ia)
return(-1);
}
cp = uia.c;
ip = xi->addr;
*cp++ = *ip++;
*cp++ = *ip++;
*cp++ = *ip++;
*cp++ = *ip++;
*ia = ntohl(uia.l);
*cp++ = ntohl(*ip++);
*cp++ = ntohl(*ip++);
*cp++ = ntohl(*ip++);
*cp++ = ntohl(*ip++);
ia->s_addr = uia.l;
return (0);
}

View File

@ -1,4 +1,4 @@
int bp_whoami(int sock);
int bp_getfile(int sock, char *key, n_long *addrp, char *path);
int bp_getfile(int sock, char *key, struct in_addr *addrp, char *path);

View File

@ -1,4 +1,4 @@
/* $NetBSD: exit.c,v 1.6 1995/09/17 00:49:40 pk Exp $ */
/* $NetBSD: exit.c,v 1.7 1995/09/18 21:19:25 pk Exp $ */
/*-
* Copyright (c) 1993 John Brezak
@ -44,7 +44,6 @@ panic(fmt /*, va_alist */)
#endif
{
extern void closeall __P((void));
extern __dead void _rtt __P((void)) __attribute__((noreturn));
va_list ap;
static int paniced;

View File

@ -1,4 +1,4 @@
/* $NetBSD: globals.c,v 1.2 1994/10/26 05:44:47 cgd Exp $ */
/* $NetBSD: globals.c,v 1.3 1995/09/18 21:19:27 pk Exp $ */
/*
* globals.c:
@ -19,10 +19,13 @@ u_char bcea[6] = BA; /* broadcast ethernet address */
char rootpath[FNAME_SIZE] = "/"; /* root mount path */
char bootfile[FNAME_SIZE]; /* bootp says to boot this */
char hostname[FNAME_SIZE]; /* our hostname */
int hostnamelen;
char domainname[FNAME_SIZE]; /* our DNS domain */
int domainnamelen;
char ifname[IFNAME_SIZE]; /* name of interface (e.g. "le0") */
n_long nameip; /* DNS server ip address */
n_long rootip; /* root ip address */
n_long swapip; /* swap ip address */
n_long gateip; /* swap ip address */
n_long mask = 0xffffff00; /* subnet or net mask */
struct in_addr myip; /* my ip address */
struct in_addr nameip; /* DNS server ip address */
struct in_addr rootip; /* root ip address */
struct in_addr swapip; /* swap ip address */
struct in_addr gateip; /* swap ip address */
n_long netmask = 0xffffff00; /* subnet or net mask */

View File

@ -1,4 +1,4 @@
/* $NetBSD: iodesc.h,v 1.2 1994/10/26 05:44:50 cgd Exp $ */
/* $NetBSD: iodesc.h,v 1.3 1995/09/18 21:19:28 pk Exp $ */
/*
* Copyright (c) 1993 Adam Glass
@ -42,8 +42,8 @@
#define __SYS_LIBNETBOOT_IODESC_H
struct iodesc {
n_long destip; /* destination ip address */
n_long myip; /* my ip address */
struct in_addr destip; /* destination ip address */
struct in_addr myip; /* my ip address */
u_short destport; /* destination port */
u_short myport; /* destination port */
u_long xid; /* transaction identification */

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.c,v 1.7 1995/09/17 00:49:41 pk Exp $ */
/* $NetBSD: net.c,v 1.8 1995/09/18 21:19:30 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -56,9 +56,6 @@
#include "stand.h"
#include "net.h"
#include "netif.h"
n_long myip;
/* Caller must leave room for ethernet, ip and udp headers in front!! */
ssize_t
@ -79,9 +76,9 @@ sendudp(d, pkt, len)
printf("sendudp: d=%x called.\n", (u_int)d);
if (d) {
printf("saddr: %s:%d",
intoa(d->myip), d->myport);
inet_ntoa(d->myip), ntohs(d->myport));
printf(" daddr: %s:%d\n",
intoa(d->destip), d->destport);
inet_ntoa(d->destip), ntohs(d->destport));
}
}
#endif
@ -97,12 +94,12 @@ sendudp(d, pkt, len)
ip->ip_len = htons(len);
ip->ip_p = IPPROTO_UDP; /* char */
ip->ip_ttl = IP_TTL; /* char */
ip->ip_src.s_addr = htonl(d->myip);
ip->ip_dst.s_addr = htonl(d->destip);
ip->ip_src = d->myip;
ip->ip_dst = d->destip;
ip->ip_sum = in_cksum(ip, sizeof(*ip)); /* short, but special */
uh->uh_sport = htons(d->myport);
uh->uh_dport = htons(d->destport);
uh->uh_sport = d->myport;
uh->uh_dport = d->destport;
uh->uh_ulen = htons(len - sizeof(*ip));
/* Calculate checksum (must save and restore ip header) */
@ -116,10 +113,10 @@ sendudp(d, pkt, len)
*ip = tip;
if (ip->ip_dst.s_addr == INADDR_BROADCAST || ip->ip_src.s_addr == 0 ||
mask == 0 || SAMENET(ip->ip_src.s_addr, ip->ip_dst.s_addr, mask))
ea = arpwhohas(d, ip->ip_dst.s_addr);
netmask == 0 || SAMENET(ip->ip_src, ip->ip_dst, netmask))
ea = arpwhohas(d, ip->ip_dst);
else
ea = arpwhohas(d, htonl(gateip));
ea = arpwhohas(d, gateip);
cc = sendether(d, ip, len, ea, ETHERTYPE_IP);
if (cc == -1)
@ -207,11 +204,11 @@ readudp(d, pkt, len, tleft)
#endif
return -1;
}
if (d->myip && ntohl(ip->ip_dst.s_addr) != d->myip) {
if (d->myip.s_addr && ip->ip_dst.s_addr != d->myip.s_addr) {
#ifdef NET_DEBUG
if (debug) {
printf("readudp: bad saddr %s != ", intoa(d->myip));
printf("%s\n", intoa(ntohl(ip->ip_dst.s_addr)));
printf("readudp: bad saddr %s != ", inet_ntoa(d->myip));
printf("%s\n", inet_ntoa(ip->ip_dst));
}
#endif
return -1;
@ -223,7 +220,7 @@ readudp(d, pkt, len, tleft)
ip->ip_len = sizeof(*ip);
n -= hlen - sizeof(*ip);
}
if (ntohs(uh->uh_dport) != d->myport) {
if (uh->uh_dport != d->myport) {
#ifdef NET_DEBUG
if (debug)
printf("readudp: bad dport %d != %d\n",
@ -305,6 +302,10 @@ sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize)
t = getsecs();
for (;;) {
if (tleft <= 0) {
if (tmo == MAXTMO) {
errno = ETIMEDOUT;
return -1;
}
cc = (*sproc)(d, sbuf, ssize);
if (cc == -1 || cc < ssize)
panic("sendrecv: short write! (%d < %d)",
@ -330,16 +331,24 @@ sendrecv(d, sproc, sbuf, ssize, rproc, rbuf, rsize)
}
}
char *
inet_ntoa(ia)
struct in_addr ia;
{
return (intoa(ia.s_addr));
}
/* Similar to inet_ntoa() */
char *
intoa(addr)
n_long addr;
register n_long addr;
{
register char *cp;
register u_int byte;
register int n;
static char buf[17]; /* strlen(".255.255.255.255") + 1 */
NTOHL(addr);
cp = &buf[sizeof buf];
*--cp = '\0';
@ -397,5 +406,5 @@ ip_convertaddr(p)
if (*p != '\0')
return IP_ANYADDR;
return ntohl(addr);
return htonl(addr);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: net.h,v 1.6 1995/09/14 23:45:27 pk Exp $ */
/* $NetBSD: net.h,v 1.7 1995/09/18 21:19:32 pk Exp $ */
/*
* Copyright (c) 1993 Adam Glass
@ -38,12 +38,17 @@
* SUCH DAMAGE.
*/
#ifndef _KERNEL /* XXX - see <netinet/in.h> */
#undef __IPADDR
#define __IPADDR(x) htonl((u_int32_t)(x))
#endif
#include "iodesc.h"
#define BA { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
/* Returns true if n_long's on the same net */
#define SAMENET(a1, a2, m) ((a1 & m) == (a2 & m))
#define SAMENET(a1, a2, m) ((a1.s_addr & m) == (a2.s_addr & m))
#define MACPY(s, d) bcopy((char *)s, (char *)d, 6)
@ -68,25 +73,28 @@ extern u_char bcea[6];
extern char rootpath[FNAME_SIZE];
extern char bootfile[FNAME_SIZE];
extern char hostname[FNAME_SIZE];
extern int hostnamelen;
extern char domainname[FNAME_SIZE];
extern int domainnamelen;
extern char ifname[IFNAME_SIZE];
extern n_long myip;
extern n_long rootip;
extern n_long swapip;
extern n_long gateip;
extern n_long nameip;
extern n_long mask;
extern struct in_addr myip;
extern struct in_addr rootip;
extern struct in_addr swapip;
extern struct in_addr gateip;
extern struct in_addr nameip;
extern n_long netmask;
extern int debug; /* defined in the machdep sources */
extern struct iodesc sockets[SOPEN_MAX];
/* ARP functions: */
u_char *arpwhohas __P((struct iodesc *, n_long));
/* ARP/RevARP functions: */
u_char *arpwhohas __P((struct iodesc *, struct in_addr));
void arp_reply __P((struct iodesc *, void *));
int rarp_getipaddress __P((int));
/* Link functions: */
ssize_t sendether __P((struct iodesc *d, void *pkt, size_t len,
u_char *dea, int etype));
ssize_t readether __P((struct iodesc *d, void *pkt, size_t len,
@ -100,12 +108,11 @@ ssize_t sendrecv __P((struct iodesc *,
ssize_t (*)(struct iodesc *, void *, size_t, time_t),
void *, size_t));
/* utilities: */
/* Utilities: */
char *ether_sprintf __P((u_char *));
int in_cksum __P((void *, int));
char *inet_ntoa __P((struct in_addr));
char *intoa __P((n_long)); /* similar to inet_ntoa */
/* Machine-dependent functions: */
time_t getsecs __P((void));

View File

@ -1,4 +1,4 @@
/* $NetBSD: netif.c,v 1.4 1995/09/14 23:45:28 pk Exp $ */
/* $NetBSD: netif.c,v 1.5 1995/09/18 21:19:34 pk Exp $ */
/*
* Copyright (c) 1993 Adam Glass
@ -281,7 +281,8 @@ socktodesc(sock)
int sock;
{
if (sock >= SOPEN_MAX) {
return(NULL);
errno = EBADF;
return (NULL);
}
return (&sockets[sock]);
}
@ -298,6 +299,7 @@ netif_open(machdep_hint)
for (fd = 0, s = sockets; fd < SOPEN_MAX; fd++, s++)
if (s->io_netif == (struct netif *)0)
goto fnd;
errno = EMFILE;
return (-1);
fnd:

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs.c,v 1.10 1995/09/17 00:49:42 pk Exp $ */
/* $NetBSD: nfs.c,v 1.11 1995/09/18 21:19:36 pk Exp $ */
/*-
* Copyright (c) 1993 John Brezak
@ -271,7 +271,7 @@ nfs_readdata(d, off, addr, len)
int
nfs_mount(sock, ip, path)
int sock;
n_long ip;
struct in_addr ip;
char *path;
{
struct iodesc *desc;

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs.h,v 1.3 1995/09/14 23:45:32 pk Exp $ */
/* $NetBSD: nfs.h,v 1.4 1995/09/18 21:19:39 pk Exp $ */
/*-
* Copyright (c) 1993
@ -41,3 +41,5 @@ ssize_t nfs_write __P((struct open_file *f, void *buf,
size_t size, size_t *resid));
off_t nfs_seek __P((struct open_file *f, off_t offset, int where));
int nfs_stat __P((struct open_file *f, struct stat *sb));
int nfs_mount __P((int, struct in_addr, char *));

View File

@ -1,4 +1,4 @@
/* $NetBSD: rarp.c,v 1.8 1995/09/14 23:45:34 pk Exp $ */
/* $NetBSD: rarp.c,v 1.9 1995/09/18 21:19:40 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -58,7 +58,7 @@ static ssize_t rarprecv __P((struct iodesc *, void *, size_t, time_t));
/*
* Ethernet (Reverse) Address Resolution Protocol (see RFC 903, and 826).
*/
n_long
int
rarp_getipaddress(sock)
int sock;
{
@ -85,7 +85,7 @@ rarp_getipaddress(sock)
#endif
if (!(d = socktodesc(sock))) {
printf("rarp: bad socket. %d\n", sock);
return(INADDR_ANY);
return (-1);
}
#ifdef RARP_DEBUG
if (debug)
@ -106,10 +106,10 @@ rarp_getipaddress(sock)
rarpsend, &wbuf.data, sizeof(wbuf.data),
rarprecv, &rbuf.data, sizeof(rbuf.data)) < 0) {
printf("No response for RARP request\n");
return(INADDR_ANY);
return (-1);
}
return (myip);
return (0);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc.c,v 1.8 1995/09/17 00:49:44 pk Exp $ */
/* $NetBSD: rpc.c,v 1.9 1995/09/18 21:19:42 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -101,6 +101,7 @@ struct rpc_reply {
/* Local forwards */
static ssize_t recvrpc __P((struct iodesc *, void *, size_t, time_t));
static int rpc_getport __P((struct iodesc *, n_long, n_long));
int rpc_xid;
int rpc_port = 0x400; /* predecrement */
@ -125,6 +126,7 @@ rpc_call(d, prog, vers, proc, sdata, slen, rdata, rlen)
char *send_head, *send_tail;
char *recv_head, *recv_tail;
n_long x;
int p;
#ifdef RPC_DEBUG
if (debug)
@ -132,7 +134,11 @@ rpc_call(d, prog, vers, proc, sdata, slen, rdata, rlen)
prog, vers, proc);
#endif
d->destport = rpc_getport(d, prog, vers);
p = rpc_getport(d, prog, vers);
if (p == htonl(-1))
return (-1);
d->destport = htons((short)ntohl(p));
/*
* Prepend authorization stuff and headers.
@ -182,6 +188,7 @@ rpc_call(d, prog, vers, proc, sdata, slen, rdata, rlen)
cc = sendrecv(d,
sendudp, send_head, ((int)send_tail - (int)send_head),
recvrpc, recv_head, ((int)recv_tail - (int)recv_head));
#ifdef RPC_DEBUG
if (debug)
printf("callrpc: cc=%d rlen=%d\n", cc, rlen);
@ -284,7 +291,10 @@ recvrpc(d, pkt, len, tleft)
* dig out the IP address/port from the headers.
*/
void
rpc_fromaddr(void *pkt, n_long *addr, u_short *port)
rpc_fromaddr(pkt, addr, port)
void *pkt;
struct in_addr *addr;
u_short *port;
{
struct hackhdr {
/* Tail of IP header: just IP addresses */
@ -300,46 +310,46 @@ rpc_fromaddr(void *pkt, n_long *addr, u_short *port)
} *hhdr;
hhdr = ((struct hackhdr *)pkt) - 1;
*addr = hhdr->ip_src;
addr->s_addr = hhdr->ip_src;
*port = hhdr->uh_sport;
}
/*
* RPC Portmapper cache
*/
#define PMAP_NUM 8 /* need at most 5 pmap entries */
int rpc_pmap_num;
struct pmap_list {
u_long addr; /* server, net order */
struct in_addr addr; /* server, net order */
u_long prog; /* host order */
u_long vers; /* host order */
u_short port; /* net order */
n_short port; /* net order */
u_short _pad;
} rpc_pmap_list[PMAP_NUM];
/* return port number in net order */
int
rpc_pmap_getcache(addr, prog, vers)
u_long addr; /* server, net order */
struct in_addr addr; /* server, net order */
u_long prog; /* host order */
u_long vers; /* host order */
{
struct pmap_list *pl;
for (pl = rpc_pmap_list; pl < &rpc_pmap_list[rpc_pmap_num]; pl++)
if (pl->addr == addr && pl->prog == prog && pl->vers == vers)
if (pl->addr.s_addr == addr.s_addr && pl->prog == prog &&
pl->vers == vers)
return ((int) pl->port);
return (-1);
return (htonl(-1));
}
void
rpc_pmap_putcache(addr, prog, vers, port)
n_long addr; /* net order */
n_long prog; /* host order */
n_long vers; /* host order */
int port; /* net order */
struct in_addr addr; /* server, net order */
u_long prog; /* host order */
u_long vers; /* host order */
n_long port; /* net order */
{
struct pmap_list *pl;
@ -374,13 +384,13 @@ rpc_getport(d, prog, vers)
n_long vers; /* host order */
{
struct args {
u_long prog; /* call program */
u_long vers; /* call version */
u_long proto; /* call protocol */
u_long port; /* call port (unused) */
n_long prog; /* call program */
n_long vers; /* call version */
n_long proto; /* call protocol */
n_long port; /* call port (unused) */
} *args;
struct res {
u_long port;
n_long port;
} *res;
struct {
n_long h[RPC_HEADER_WORDS];
@ -391,7 +401,8 @@ rpc_getport(d, prog, vers)
struct res d;
n_long pad;
} rdata;
int cc, port;
ssize_t cc;
n_long port;
#ifdef RPC_DEBUG
if (debug)
@ -400,11 +411,11 @@ rpc_getport(d, prog, vers)
/* This one is fixed forever. */
if (prog == PMAPPROG)
return PMAPPORT;
return (htons(PMAPPORT));
/* Try for cached answer first */
port = rpc_pmap_getcache(d->destip, prog, vers);
if (port >= 0)
if (port != htonl(-1))
return (port);
args = &sdata.d;
@ -418,9 +429,10 @@ rpc_getport(d, prog, vers)
args, sizeof(*args), res, sizeof(*res));
if (cc < sizeof(*res)) {
printf("getport: %s", strerror(errno));
return(-1);
errno = EBADRPC;
return (htonl(-1));
}
port = (u_short)res->port;
port = res->port;
rpc_pmap_putcache(d->destip, prog, vers, port);

View File

@ -1,4 +1,4 @@
/* $NetBSD: rpc.h,v 1.5 1995/09/14 23:45:38 pk Exp $ */
/* $NetBSD: rpc.h,v 1.6 1995/09/18 21:19:44 pk Exp $ */
/*
* Copyright (c) 1992 Regents of the University of California.
@ -49,13 +49,12 @@
#define PMAPPROC_CALLIT 5
/* RPC functions: */
ssize_t rpc_call __P((struct iodesc *d, n_long prog, n_long ver, n_long func,
void *sdata, size_t slen, void *rdata, size_t rlen));
int rpc_getport __P((struct iodesc *d, n_long prog, n_long vers));
void rpc_fromaddr(void *pkt, n_long *addr, u_short *port);
void rpc_pmap_putcache __P((n_long addr, n_long pr, n_long v, int port));
ssize_t rpc_call __P((struct iodesc *, n_long, n_long, n_long,
void *, size_t, void *, size_t));
void rpc_fromaddr __P((void *, struct in_addr *, u_short *));
int rpc_pmap_getcache __P((struct in_addr, u_long, u_long));
void rpc_pmap_putcache __P((struct in_addr, u_long, u_long, n_long));
extern int rpc_xid; /* increment before call */
extern int rpc_port; /* decrement before bind */
/*
@ -67,4 +66,3 @@ extern int rpc_port; /* decrement before bind */
* 2: Auth NULL
*/
#define RPC_HEADER_WORDS 28

View File

@ -1,4 +1,4 @@
/* $NetBSD: saerrno.h,v 1.5 1995/09/14 23:45:39 pk Exp $ */
/* $NetBSD: saerrno.h,v 1.6 1995/09/18 21:19:45 pk Exp $ */
/*
* Copyright (c) 1988, 1993
@ -35,35 +35,19 @@
* @(#)saerrno.h 8.1 (Berkeley) 6/11/93
*/
extern int errno; /* just like unix */
#include <sys/errno.h>
/* error codes */
#define EADAPT 1 /* bad adaptor */
#define ECTLR 2 /* bad controller */
#define EUNIT 3 /* bad drive */
#define EPART 4 /* bad partition */
#define ERDLAB 5 /* can't read disk label */
#define EUNLAB 6 /* unlabeled disk */
#define ENXIO 7 /* Device not configured */
#define EBADF 8 /* bad file descriptor */
#define EOFFSET 9 /* relative seek not supported */
#define ESRCH 10 /* directory search for file failed */
#define EIO 11 /* generic error */
#define ECMD 12 /* undefined driver command */
#define EBSE 13 /* bad sector error */
#define EWCK 14 /* write check error */
#define EECC 15 /* uncorrectable ecc error */
#define EHER 16 /* hard error */
#define ENOEXEC 17 /* Exec format error */
#define EPERM 18 /* Operation not permitted */
#define ENOENT 19 /* No such file or directory */
#define ESTALE 20 /* Stale NFS file handle */
#define EINVAL 21 /* Invalid argument */
#define EMFILE 22 /* Too many open files */
#define EOPNOTSUPP 23 /* Operation not supported */
#define EFBIG 24 /* File too large */
#define ENOTDIR 25 /* Not a directory */
#define EROFS 26 /* Read-only file system */
#define ENODEV 27 /* Operation not supported by device */
#define EFTYPE 28 /* Inappropriate file type or format */
#define EBADRPC 29 /* RPC struct is bad */
/* special stand error codes */
#define EADAPT (ELAST+1) /* bad adaptor */
#define ECTLR (ELAST+2) /* bad controller */
#define EUNIT (ELAST+3) /* bad drive */
#define EPART (ELAST+4) /* bad partition */
#define ERDLAB (ELAST+5) /* can't read disk label */
#define EUNLAB (ELAST+6) /* unlabeled disk */
#define EOFFSET (ELAST+7) /* relative seek not supported */
#define ECMD (ELAST+8) /* undefined driver command */
#define EBSE (ELAST+9) /* bad sector error */
#define EWCK (ELAST+10) /* write check error */
#define EECC (ELAST+11) /* uncorrectable ecc error */
#define EHER (ELAST+12) /* hard error */
#define ESALAST (ELAST+12) /* */

View File

@ -1,4 +1,4 @@
/* $NetBSD: stand.h,v 1.11 1995/09/17 00:49:45 pk Exp $ */
/* $NetBSD: stand.h,v 1.12 1995/09/18 21:19:47 pk Exp $ */
/*-
* Copyright (c) 1993
@ -116,8 +116,9 @@ void printf __P((const char *, ...));
void sprintf __P((char *, const char *, ...));
void twiddle __P((void));
void gets __P((char *));
__dead void panic __P((const char *, ...))
__attribute__((noreturn));
__dead void panic __P((const char *, ...)) __attribute__((noreturn));
__dead void _rtt __P((void)) __attribute__((noreturn));
void bcopy __P((const void *, void *, size_t));
int getchar __P((void));
void exec __P((char *, char *, int));
int open __P((const char *, int));