diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-05 16:36:07 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-01-05 16:36:07 +0000 |
commit | b079187d0a366ac9b3793ebc694d774d691bb640 (patch) | |
tree | 6ee3e069839b429f4512f91ce9eb07dee7556055 /lib/libc/rpc | |
parent | 965838951ec63319efe3d6acd3340bd8e44de631 (diff) |
from netbsd; make get_myaddress() return failure if it is unable to
determine address, make other code understand this failure.
Diffstat (limited to 'lib/libc/rpc')
-rw-r--r-- | lib/libc/rpc/get_myaddress.c | 19 | ||||
-rw-r--r-- | lib/libc/rpc/pmap_clnt.c | 10 | ||||
-rw-r--r-- | lib/libc/rpc/rpc.3 | 5 |
3 files changed, 19 insertions, 15 deletions
diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c index d1a28d8d10a..b0ac7da5ac6 100644 --- a/lib/libc/rpc/get_myaddress.c +++ b/lib/libc/rpc/get_myaddress.c @@ -1,4 +1,4 @@ -/* $NetBSD: get_myaddress.c,v 1.2 1995/02/25 03:01:43 cgd Exp $ */ +/* $NetBSD: get_myaddress.c,v 1.3 1996/01/04 20:05:04 pk Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -32,7 +32,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";*/ /*static char *sccsid = "from: @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC";*/ -static char *rcsid = "$NetBSD: get_myaddress.c,v 1.2 1995/02/25 03:01:43 cgd Exp $"; +static char *rcsid = "$NetBSD: get_myaddress.c,v 1.3 1996/01/04 20:05:04 pk Exp $"; #endif /* @@ -55,6 +55,7 @@ static char *rcsid = "$NetBSD: get_myaddress.c,v 1.2 1995/02/25 03:01:43 cgd Exp /* * don't use gethostbyname, which would invoke yellow pages */ +int get_myaddress(addr) struct sockaddr_in *addr; { @@ -65,21 +66,20 @@ get_myaddress(addr) int len, slop; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - perror("get_myaddress: socket"); - exit(1); + return (-1); } ifc.ifc_len = sizeof (buf); ifc.ifc_buf = buf; if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) { - perror("get_myaddress: ioctl (get interface configuration)"); - exit(1); + (void) close(s); + return (-1); } ifr = ifc.ifc_req; for (len = ifc.ifc_len; len; len -= sizeof ifreq) { ifreq = *ifr; if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) { - perror("get_myaddress: ioctl"); - exit(1); + (void) close(s); + return (-1); } if ((ifreq.ifr_flags & IFF_UP) && ifr->ifr_addr.sa_family == AF_INET) { @@ -91,11 +91,12 @@ get_myaddress(addr) * Deal with variable length addresses */ slop = ifr->ifr_addr.sa_len - sizeof (struct sockaddr); - if (slop) { + if (slop > 0) { ifr = (struct ifreq *) ((caddr_t)ifr + slop); len -= slop; } ifr++; } (void) close(s); + return (0); } diff --git a/lib/libc/rpc/pmap_clnt.c b/lib/libc/rpc/pmap_clnt.c index 31ff204f96d..db7d4e2c30b 100644 --- a/lib/libc/rpc/pmap_clnt.c +++ b/lib/libc/rpc/pmap_clnt.c @@ -1,4 +1,4 @@ -/* $NetBSD: pmap_clnt.c,v 1.2 1995/02/25 03:01:47 cgd Exp $ */ +/* $NetBSD: pmap_clnt.c,v 1.3 1996/01/04 20:06:22 pk Exp $ */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for @@ -32,7 +32,7 @@ #if defined(LIBC_SCCS) && !defined(lint) /*static char *sccsid = "from: @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";*/ /*static char *sccsid = "from: @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC";*/ -static char *rcsid = "$NetBSD: pmap_clnt.c,v 1.2 1995/02/25 03:01:47 cgd Exp $"; +static char *rcsid = "$NetBSD: pmap_clnt.c,v 1.3 1996/01/04 20:06:22 pk Exp $"; #endif /* @@ -69,7 +69,8 @@ pmap_set(program, version, protocol, port) struct pmap parms; bool_t rslt; - get_myaddress(&myaddress); + if (get_myaddress(&myaddress) != 0) + return (FALSE); client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE); if (client == (CLIENT *)NULL) @@ -103,7 +104,8 @@ pmap_unset(program, version) struct pmap parms; bool_t rslt; - get_myaddress(&myaddress); + if (get_myaddress(&myaddress) != 0) + return (FALSE); client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS, timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE); if (client == (CLIENT *)NULL) diff --git a/lib/libc/rpc/rpc.3 b/lib/libc/rpc/rpc.3 index 447ec1cb21c..090efdf2fa0 100644 --- a/lib/libc/rpc/rpc.3 +++ b/lib/libc/rpc/rpc.3 @@ -1,5 +1,5 @@ .\" @(#)rpc.3n 2.4 88/08/08 4.0 RPCSRC; from 1.19 88/06/24 SMI -.\" $NetBSD: rpc.3,v 1.2 1995/02/25 03:01:53 cgd Exp $ +.\" $NetBSD: rpc.3,v 1.3 1996/01/04 20:09:53 pk Exp $ .\" .TH RPC 3N "16 February 1988" .SH NAME @@ -737,7 +737,7 @@ messages. .ft B .nf .sp .5 -void +int get_myaddress(addr) struct sockaddr_in *addr; .fi @@ -751,6 +751,7 @@ without consulting the library routines that deal with .BR /etc/hosts . The port number is always set to .BR htons(\s-1PMAPPORT\s0) . +Returns zero on success, non-zero on failure. .br .if t .ne 10 .LP |