2
#if defined(HAVE_CONFIG_H)
16
stpcpy (char *s1, const char *s2)
18
/* This is a naive implementation for platforms missing the
19
function. It should be rewritten. */
21
return s1 + strlen (s2);
23
#endif /* not HAVE_STPCPY */
27
strndup (const char *s, int size)
29
int len = strlen (s) + 1;
32
len = len > size ? size : len;
33
retval = malloc (len);
35
retval[len - 1] = '\0';
39
#endif /* not HAVE_STRNDUP */
41
#ifndef HAVE_GETOPT_LONG
43
getopt_long (int argc, char *const *argv, const char *shortopts,
44
const struct option *longopts, int *longind)
46
return getopt (argc, argv, shortopts);
48
#endif /* not HAVE_GETOPT_LONG */
50
#if !defined(HAVE_GETDELIM) && !defined(HAVE_GETLINE)
51
/* copied from cvs 1.11.5 source */
52
/* getline.c -- Replacement for GNU C library function getline
54
Copyright (C) 1993 Free Software Foundation, Inc.
56
This program is free software; you can redistribute it and/or
57
modify it under the terms of the GNU General Public License as
58
published by the Free Software Foundation; either version 2 of the
59
License, or (at your option) any later version.
61
This program is distributed in the hope that it will be useful, but
62
WITHOUT ANY WARRANTY; without even the implied warranty of
63
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
64
General Public License for more details. */
66
/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */
68
#include <sys/types.h>
73
#define GETLINE_NO_LIMIT -1
78
char *malloc (), *realloc ();
81
/* Always add at least this many bytes when extending the buffer. */
84
/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
85
+ OFFSET (and null-terminate it). If LIMIT is non-negative, then
86
read no more than LIMIT chars.
88
*LINEPTR is a pointer returned from malloc (or NULL), pointing to
89
*N characters of space. It is realloc'd as necessary.
91
Return the number of characters read (not including the null
92
terminator), or -1 on error or EOF. On a -1 return, the caller
93
should check feof(), if not then errno has been set to indicate the
97
getstr (char **lineptr, size_t *n, FILE *stream, int terminator,
98
int offset, int limit)
100
int nchars_avail; /* Allocated but unused chars in *LINEPTR. */
101
char *read_pos; /* Where we're reading into *LINEPTR. */
104
if (!lineptr || !n || !stream)
113
*lineptr = malloc (*n);
122
nchars_avail = *n - offset;
123
read_pos = *lineptr + offset;
136
/* If limit is negative, then we shouldn't pay attention to
137
it, so decrement only if positive. */
144
/* We always want at least one char left in the buffer, since we
145
always (unless we get an error while reading the first char)
146
NUL-terminate the line buffer. */
148
assert((*lineptr + *n) == (read_pos + nchars_avail));
149
if (nchars_avail < 2)
156
nchars_avail = *n + *lineptr - read_pos;
157
*lineptr = realloc (*lineptr, *n);
163
read_pos = *n - nchars_avail + *lineptr;
164
assert((*lineptr + *n) == (read_pos + nchars_avail));
169
/* Might like to return partial line, but there is no
170
place for us to store errno. And we don't want to just
178
/* Return partial line, if any. */
179
if (read_pos == *lineptr)
189
/* Return the line. */
193
/* Done - NUL terminate and return the number of chars read. */
196
ret = read_pos - (*lineptr + offset);
201
getline (char **lineptr, size_t * n, FILE * stream)
203
return getstr (lineptr, n, stream, '\n', 0, GETLINE_NO_LIMIT);
207
getline_safe (char **lineptr, size_t *n, FILE *stream, int limit)
209
return getstr (lineptr, n, stream, '\n', 0, limit);
212
#endif /* not HAVE_GETDELIM and not HAVE_GETLINE */
214
#if !defined(HAVE_SVC_GETCALLER) && !defined(svc_getcaller)
215
const struct sockaddr_in *
216
svc_getcaller(const SVCXPRT *xprt)
218
# ifdef HAVE_SVC_GETRPCCALLER
219
const struct netbuf *addr;
220
addr = svc_getrpccaller(xprt);
221
log_msg ("warning: Bogus svc_getcaller() called");
222
/* XXX find out how the result from svc_getrpccaller relates to
224
assert(sizeof(struct sockaddr_in) == addr->len);
225
return (const struct sockaddr_in *)addr->buf;
226
# else /* not HAVE_SVC_GETRPCCALLER */
227
# error "Missing both svc_getcaller() and svc_getrpccaller()"
228
# endif /* not HAVE_SVC_GETRPCCALLER */
230
#endif /* not HAVE_SVC_GETCALLER */
233
#ifndef HAVE__RPC_DTABLESIZE
234
# if HAVE_GETDTABLESIZE
235
int _rpc_dtablesize()
240
size = getdtablesize();
245
# include <sys/resource.h>
246
int _rpc_dtablesize()
253
if (getrlimit(RLIMIT_NOFILE, &rlb) >= 0)
259
# endif /* not HAVE_GETDTABLESIZE */
260
#endif /* not HAVE__RPC_DTABLESIZE */
262
#ifndef HAVE_INET_ATON
263
/* Source: http://mail.gnu.org/archive/html/autoconf/2002-08/msg00036.html */
264
/* $Id: compat.c,v 1.1.2.5 2005/05/19 12:12:06 kukuk Exp $
266
** Replacement for a missing inet_aton.
268
** Written by Russ Allbery <rra@bogus.example.com>
269
** This work is hereby placed in the public domain by its author.
271
** Provides the same functionality as the standard library routine
272
** inet_aton for those platforms that don't have it. inet_aton is
276
/* #include "config.h" */
277
/* #include "clibrary.h" */
278
#include <netinet/in.h>
280
/* If we're running the test suite, rename inet_ntoa to avoid conflicts with
281
the system version. */
283
# define inet_aton test_inet_aton
284
int test_inet_aton(const char *, struct in_addr *);
288
inet_aton(const char *s, struct in_addr *addr)
290
unsigned long octet[4], address;
295
if (s == NULL) return 0;
297
/* Step through each period-separated part of the address. If we see
298
more than four parts, the address is invalid. */
299
for (p = s; *p != 0; part++) {
300
if (part > 3) return 0;
302
/* Determine the base of the section we're looking at. Numbers are
303
represented the same as in C; octal starts with 0, hex starts
304
with 0x, and anything else is decimal. */
317
/* Make sure there's actually a number. (A section of just "0"
318
would set base to 8 and leave us pointing at a period; allow
320
if (*p == '.' && base != 8) return 0;
323
/* Now, parse this segment of the address. For each digit, multiply
324
the result so far by the base and then add the value of the
325
digit. Be careful of arithmetic overflow in cases where an
326
unsigned long is 32 bits; we need to detect it *before* we
327
multiply by the base since otherwise we could overflow and wrap
328
and then not detect the error. */
329
for (; *p != 0 && *p != '.'; p++) {
330
if (octet[part] > 0xffffffffUL / base) return 0;
332
/* Use a switch statement to parse each digit rather than
333
assuming ASCII. Probably pointless portability.... */
335
case '0': i = 0; break;
336
case '1': i = 1; break;
337
case '2': i = 2; break;
338
case '3': i = 3; break;
339
case '4': i = 4; break;
340
case '5': i = 5; break;
341
case '6': i = 6; break;
342
case '7': i = 7; break;
343
case '8': i = 8; break;
344
case '9': i = 9; break;
345
case 'A': case 'a': i = 10; break;
346
case 'B': case 'b': i = 11; break;
347
case 'C': case 'c': i = 12; break;
348
case 'D': case 'd': i = 13; break;
349
case 'E': case 'e': i = 14; break;
350
case 'F': case 'f': i = 15; break;
353
if (i >= base) return 0;
354
octet[part] = (octet[part] * base) + i;
357
/* Advance over periods; the top of the loop will increment the
358
count of parts we've seen. We need a check here to detect an
359
illegal trailing period. */
362
if (*p == 0) return 0;
365
if (part == 0) return 0;
367
/* IPv4 allows three types of address specification:
373
If there are fewer than four segments, the final segment accounts for
374
all of the remaining portion of the address. For example, in the a.b
375
form, b is the final 24 bits of the address. We also allow a simple
376
number, which is interpreted as the 32-bit number corresponding to
377
the full IPv4 address.
379
The first for loop below ensures that any initial segments represent
380
only 8 bits of the address and builds the upper portion of the IPv4
381
address. Then, the remaining segment is checked to make sure it's no
382
bigger than the remaining space in the address and then is added into
385
for (i = 0; i < part - 1; i++) {
386
if (octet[i] > 0xff) return 0;
387
address |= octet[i] << (8 * (3 - i));
389
if (octet[i] > (0xffffffffUL >> (i * 8))) return 0;
391
if (addr != NULL) addr->s_addr = htonl(address);
394
#endif /* not HAVE_INET_ATON */
397
#ifndef HAVE_INET_PTON
398
#include <arpa/inet.h>
399
#include <sys/socket.h>
401
inet_pton(int af, const char *src, void *dst)
405
return inet_aton(src, (struct in_addr *)dst);
409
#endif /* AF_INET6 */
411
fprintf(stderr, "warning: Bogus inet_pton() called\n");
412
errno = EAFNOSUPPORT;
417
#endif /* not HAVE_INET_PTON */
419
#ifndef HAVE_XDR_YPXFRSTAT
423
xdr_ypxfrstat(XDR *xdrs, ypxfrstat *objp)
425
if (!xdr_enum(xdrs, (enum_t *)objp))
430
#endif /* not HAVE_XDR_YPXFRSTAT */
432
#ifndef HAVE_XDR_DOMAINNAME
435
xdr_domainname(XDR *xdrs, domainname *objp)
437
if (!xdr_string(xdrs, objp, YPMAXDOMAIN))
442
#endif /* not HAVE_XDR_DOMAINNAME */
444
#ifndef HAVE_XDR_YPRESP_XFR
447
xdr_ypresp_xfr(XDR *xdrs, ypresp_xfr *objp)
449
if (!xdr_u_int(xdrs, &objp->transid))
452
if (!xdr_ypxfrstat(xdrs, &objp->xfrstat))
457
#endif /* not HAVE_XDR_YPRESP_XFR */
459
#ifndef HAVE_XDR_YPMAP_PARMS
461
xdr_ypmap_parms(XDR *xdrs, ypmap_parms *objp)
463
if (!xdr_domainname(xdrs, &objp->domain))
465
if (!xdr_mapname(xdrs, &objp->map))
467
if (!xdr_u_int(xdrs, &objp->ordernum))
469
if (!xdr_peername(xdrs, &objp->peer))
473
#endif /* not HAVE_XDR_YPMAP_PARMS */
476
#ifndef HAVE_XDR_YPREQ_XFR
478
xdr_ypreq_xfr(XDR *xdrs, ypreq_xfr *objp)
480
if (!xdr_ypmap_parms(xdrs, &objp->map_parms))
482
if (!xdr_u_int(xdrs, &objp->transid))
484
if (!xdr_u_int(xdrs, &objp->prog))
486
if (!xdr_u_int(xdrs, &objp->port))
490
#endif /* not HAVE_XDR_YPREQ_XFR */
492
#ifndef HAVE_XDR_MAPNAME
494
xdr_mapname (XDR *xdrs, mapname *objp)
496
if (!xdr_string (xdrs, objp, YPMAXMAP))
501
#endif /* not HAVE_XDR_MAPNAME */
503
#ifndef HAVE_XDR_PEERNAME
505
xdr_peername (XDR *xdrs, peername *objp)
507
if (!xdr_string (xdrs, objp, YPMAXPEER))
511
#endif /* not HAVE_XDR_PEERNAME */
513
#ifndef HAVE_XDR_YPSTAT
515
xdr_ypstat (XDR *xdrs, ypstat *objp)
517
if (!xdr_enum (xdrs, (enum_t *) objp))
522
#endif /* not HAVE_XDR_YPSTAT */
524
#ifndef HAVE_XDR_YPRESP_MASTER
526
xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
528
if (!xdr_ypstat (xdrs, &objp->stat))
530
if (!xdr_peername (xdrs, &objp->peer))
534
#endif /* not HAVE_XDR_YPRESP_MASTER */
536
#ifndef HAVE_XDR_YPBIND_BINDING
538
xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp)
540
if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4))
542
if (!xdr_opaque (xdrs, objp->ypbind_binding_port, 2))
546
#endif /* not HAVE_XDR_YPBIND_BINDING */
548
#ifndef HAVE_XDR_YPREQ_NOKEY
550
xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
552
if (!xdr_domainname (xdrs, &objp->domain))
555
if (!xdr_mapname (xdrs, &objp->map))
560
#endif /* not HAVE_XDR_YPREQ_NOKEY */
562
#ifndef HAVE_XDR_YPPUSH_STATUS
564
xdr_yppush_status(XDR *xdrs, yppush_status *objp)
566
if (!xdr_enum(xdrs, (enum_t *)objp))
570
#endif /* not HAVE_XDR_YPPUSH_STATUS */
572
#ifndef HAVE_XDR_YPPUSHRESP_XFR
574
xdr_yppushresp_xfr(XDR *xdrs, yppushresp_xfr *objp)
576
if (!xdr_u_int(xdrs, &objp->transid))
578
if (!xdr_yppush_status(xdrs, &objp->status))
582
#endif /* not HAVE_XDR_YPPUSHRESP_XFR */