summaryrefslogtreecommitdiffstats
path: root/contrib/amd/libamu
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>1999-09-15 02:50:52 +0000
committerobrien <obrien@FreeBSD.org>1999-09-15 02:50:52 +0000
commite0215a27a74ac4806bc4d13ea6da0e9f444dbf18 (patch)
tree6449eb4f97cd02d168d1b036b9a7151c52272f4f /contrib/amd/libamu
parent452637dcc0d7040351cf90be4968d48917b45f8e (diff)
parent422815db966fe7dc38dfc5df2be5e83d5ea9f48c (diff)
downloadFreeBSD-src-e0215a27a74ac4806bc4d13ea6da0e9f444dbf18.zip
FreeBSD-src-e0215a27a74ac4806bc4d13ea6da0e9f444dbf18.tar.gz
This commit was generated by cvs2svn to compensate for changes in r51292,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/amd/libamu')
-rw-r--r--contrib/amd/libamu/alloca.c504
-rw-r--r--contrib/amd/libamu/amu.h4
-rw-r--r--contrib/amd/libamu/hasmntopt.c4
-rw-r--r--contrib/amd/libamu/misc_rpc.c4
-rw-r--r--contrib/amd/libamu/mtab.c4
-rw-r--r--contrib/amd/libamu/nfs_prot_xdr.c4
-rw-r--r--contrib/amd/libamu/util.c4
-rw-r--r--contrib/amd/libamu/wire.c443
-rw-r--r--contrib/amd/libamu/xdr_func.c4
-rw-r--r--contrib/amd/libamu/xutil.c55
10 files changed, 829 insertions, 201 deletions
diff --git a/contrib/amd/libamu/alloca.c b/contrib/amd/libamu/alloca.c
new file mode 100644
index 0000000..31fb4e0
--- /dev/null
+++ b/contrib/amd/libamu/alloca.c
@@ -0,0 +1,504 @@
+/* alloca.c -- allocate automatically reclaimed memory
+ (Mostly) portable public-domain implementation -- D A Gwyn
+
+ This implementation of the PWB library alloca function,
+ which is used to allocate space off the run-time stack so
+ that it is automatically reclaimed upon procedure exit,
+ was inspired by discussions with J. Q. Johnson of Cornell.
+ J.Otto Tennant <jot@cray.com> contributed the Cray support.
+
+ There are some preprocessor constants that can
+ be defined when compiling for your specific system, for
+ improved efficiency; however, the defaults should be okay.
+
+ The general concept of this implementation is to keep
+ track of all alloca-allocated blocks, and reclaim any
+ that are found to be deeper in the stack than the current
+ invocation. This heuristic does not reclaim storage as
+ soon as it becomes invalid, but it will do so eventually.
+
+ As a special case, alloca(0) reclaims storage without
+ allocating any. It is a good idea to use alloca(0) in
+ your main control loop, etc. to force garbage collection. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#ifdef emacs
+#include "blockinput.h"
+#endif
+
+/* If compiling with GCC 2, this file's not needed. */
+#if !defined (__GNUC__) || __GNUC__ < 2
+
+/* If someone has defined alloca as a macro,
+ there must be some other way alloca is supposed to work. */
+#ifndef alloca
+
+#ifdef emacs
+#ifdef static
+/* actually, only want this if static is defined as ""
+ -- this is for usg, in which emacs must undefine static
+ in order to make unexec workable
+ */
+#ifndef STACK_DIRECTION
+you
+lose
+-- must know STACK_DIRECTION at compile-time
+#endif /* STACK_DIRECTION undefined */
+#endif /* static */
+#endif /* emacs */
+
+/* If your stack is a linked list of frames, you have to
+ provide an "address metric" ADDRESS_FUNCTION macro. */
+
+#if defined (CRAY) && defined (CRAY_STACKSEG_END)
+long i00afunc ();
+#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
+#else
+#define ADDRESS_FUNCTION(arg) &(arg)
+#endif
+
+#if __STDC__
+typedef void *pointer;
+#else
+typedef char *pointer;
+#endif
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+/* Different portions of Emacs need to call different versions of
+ malloc. The Emacs executable needs alloca to call xmalloc, because
+ ordinary malloc isn't protected from input signals. On the other
+ hand, the utilities in lib-src need alloca to call malloc; some of
+ them are very simple, and don't have an xmalloc routine.
+
+ Non-Emacs programs expect this to call use xmalloc.
+
+ Callers below should use malloc. */
+
+#ifndef emacs
+#define malloc xmalloc
+#endif
+extern pointer malloc ();
+
+/* Define STACK_DIRECTION if you know the direction of stack
+ growth for your system; otherwise it will be automatically
+ deduced at run-time.
+
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown */
+
+#ifndef STACK_DIRECTION
+#define STACK_DIRECTION 0 /* Direction unknown. */
+#endif
+
+#if STACK_DIRECTION != 0
+
+#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
+
+#else /* STACK_DIRECTION == 0; need run-time code. */
+
+static int stack_dir; /* 1 or -1 once known. */
+#define STACK_DIR stack_dir
+
+static void
+find_stack_direction ()
+{
+ static char *addr = NULL; /* Address of first `dummy', once known. */
+ auto char dummy; /* To get stack address. */
+
+ if (addr == NULL)
+ { /* Initial entry. */
+ addr = ADDRESS_FUNCTION (dummy);
+
+ find_stack_direction (); /* Recurse once. */
+ }
+ else
+ {
+ /* Second entry. */
+ if (ADDRESS_FUNCTION (dummy) > addr)
+ stack_dir = 1; /* Stack grew upward. */
+ else
+ stack_dir = -1; /* Stack grew downward. */
+ }
+}
+
+#endif /* STACK_DIRECTION == 0 */
+
+/* An "alloca header" is used to:
+ (a) chain together all alloca'ed blocks;
+ (b) keep track of stack depth.
+
+ It is very important that sizeof(header) agree with malloc
+ alignment chunk size. The following default should work okay. */
+
+#ifndef ALIGN_SIZE
+#define ALIGN_SIZE sizeof(double)
+#endif
+
+typedef union hdr
+{
+ char align[ALIGN_SIZE]; /* To force sizeof(header). */
+ struct
+ {
+ union hdr *next; /* For chaining headers. */
+ char *deep; /* For stack depth measure. */
+ } h;
+} header;
+
+static header *last_alloca_header = NULL; /* -> last alloca header. */
+
+/* Return a pointer to at least SIZE bytes of storage,
+ which will be automatically reclaimed upon exit from
+ the procedure that called alloca. Originally, this space
+ was supposed to be taken from the current stack frame of the
+ caller, but that method cannot be made to work for some
+ implementations of C, for example under Gould's UTX/32. */
+
+pointer
+alloca (size)
+ unsigned size;
+{
+ auto char probe; /* Probes stack depth: */
+ register char *depth = ADDRESS_FUNCTION (probe);
+
+#if STACK_DIRECTION == 0
+ if (STACK_DIR == 0) /* Unknown growth direction. */
+ find_stack_direction ();
+#endif
+
+ /* Reclaim garbage, defined as all alloca'd storage that
+ was allocated from deeper in the stack than currently. */
+
+ {
+ register header *hp; /* Traverses linked list. */
+
+#ifdef emacs
+ BLOCK_INPUT;
+#endif
+
+ for (hp = last_alloca_header; hp != NULL;)
+ if ((STACK_DIR > 0 && hp->h.deep > depth)
+ || (STACK_DIR < 0 && hp->h.deep < depth))
+ {
+ register header *np = hp->h.next;
+
+ free ((pointer) hp); /* Collect garbage. */
+
+ hp = np; /* -> next header. */
+ }
+ else
+ break; /* Rest are not deeper. */
+
+ last_alloca_header = hp; /* -> last valid storage. */
+
+#ifdef emacs
+ UNBLOCK_INPUT;
+#endif
+ }
+
+ if (size == 0)
+ return NULL; /* No allocation required. */
+
+ /* Allocate combined header + user data storage. */
+
+ {
+ register pointer new = malloc (sizeof (header) + size);
+ /* Address of header. */
+
+ if (new == 0)
+ abort();
+
+ ((header *) new)->h.next = last_alloca_header;
+ ((header *) new)->h.deep = depth;
+
+ last_alloca_header = (header *) new;
+
+ /* User storage begins just after header. */
+
+ return (pointer) ((char *) new + sizeof (header));
+ }
+}
+
+#if defined (CRAY) && defined (CRAY_STACKSEG_END)
+
+#ifdef DEBUG_I00AFUNC
+#include <stdio.h>
+#endif
+
+#ifndef CRAY_STACK
+#define CRAY_STACK
+#ifndef CRAY2
+/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
+struct stack_control_header
+ {
+ long shgrow:32; /* Number of times stack has grown. */
+ long shaseg:32; /* Size of increments to stack. */
+ long shhwm:32; /* High water mark of stack. */
+ long shsize:32; /* Current size of stack (all segments). */
+ };
+
+/* The stack segment linkage control information occurs at
+ the high-address end of a stack segment. (The stack
+ grows from low addresses to high addresses.) The initial
+ part of the stack segment linkage control information is
+ 0200 (octal) words. This provides for register storage
+ for the routine which overflows the stack. */
+
+struct stack_segment_linkage
+ {
+ long ss[0200]; /* 0200 overflow words. */
+ long sssize:32; /* Number of words in this segment. */
+ long ssbase:32; /* Offset to stack base. */
+ long:32;
+ long sspseg:32; /* Offset to linkage control of previous
+ segment of stack. */
+ long:32;
+ long sstcpt:32; /* Pointer to task common address block. */
+ long sscsnm; /* Private control structure number for
+ microtasking. */
+ long ssusr1; /* Reserved for user. */
+ long ssusr2; /* Reserved for user. */
+ long sstpid; /* Process ID for pid based multi-tasking. */
+ long ssgvup; /* Pointer to multitasking thread giveup. */
+ long sscray[7]; /* Reserved for Cray Research. */
+ long ssa0;
+ long ssa1;
+ long ssa2;
+ long ssa3;
+ long ssa4;
+ long ssa5;
+ long ssa6;
+ long ssa7;
+ long sss0;
+ long sss1;
+ long sss2;
+ long sss3;
+ long sss4;
+ long sss5;
+ long sss6;
+ long sss7;
+ };
+
+#else /* CRAY2 */
+/* The following structure defines the vector of words
+ returned by the STKSTAT library routine. */
+struct stk_stat
+ {
+ long now; /* Current total stack size. */
+ long maxc; /* Amount of contiguous space which would
+ be required to satisfy the maximum
+ stack demand to date. */
+ long high_water; /* Stack high-water mark. */
+ long overflows; /* Number of stack overflow ($STKOFEN) calls. */
+ long hits; /* Number of internal buffer hits. */
+ long extends; /* Number of block extensions. */
+ long stko_mallocs; /* Block allocations by $STKOFEN. */
+ long underflows; /* Number of stack underflow calls ($STKRETN). */
+ long stko_free; /* Number of deallocations by $STKRETN. */
+ long stkm_free; /* Number of deallocations by $STKMRET. */
+ long segments; /* Current number of stack segments. */
+ long maxs; /* Maximum number of stack segments so far. */
+ long pad_size; /* Stack pad size. */
+ long current_address; /* Current stack segment address. */
+ long current_size; /* Current stack segment size. This
+ number is actually corrupted by STKSTAT to
+ include the fifteen word trailer area. */
+ long initial_address; /* Address of initial segment. */
+ long initial_size; /* Size of initial segment. */
+ };
+
+/* The following structure describes the data structure which trails
+ any stack segment. I think that the description in 'asdef' is
+ out of date. I only describe the parts that I am sure about. */
+
+struct stk_trailer
+ {
+ long this_address; /* Address of this block. */
+ long this_size; /* Size of this block (does not include
+ this trailer). */
+ long unknown2;
+ long unknown3;
+ long link; /* Address of trailer block of previous
+ segment. */
+ long unknown5;
+ long unknown6;
+ long unknown7;
+ long unknown8;
+ long unknown9;
+ long unknown10;
+ long unknown11;
+ long unknown12;
+ long unknown13;
+ long unknown14;
+ };
+
+#endif /* CRAY2 */
+#endif /* not CRAY_STACK */
+
+#ifdef CRAY2
+/* Determine a "stack measure" for an arbitrary ADDRESS.
+ I doubt that "lint" will like this much. */
+
+static long
+i00afunc (long *address)
+{
+ struct stk_stat status;
+ struct stk_trailer *trailer;
+ long *block, size;
+ long result = 0;
+
+ /* We want to iterate through all of the segments. The first
+ step is to get the stack status structure. We could do this
+ more quickly and more directly, perhaps, by referencing the
+ $LM00 common block, but I know that this works. */
+
+ STKSTAT (&status);
+
+ /* Set up the iteration. */
+
+ trailer = (struct stk_trailer *) (status.current_address
+ + status.current_size
+ - 15);
+
+ /* There must be at least one stack segment. Therefore it is
+ a fatal error if "trailer" is null. */
+
+ if (trailer == 0)
+ abort ();
+
+ /* Discard segments that do not contain our argument address. */
+
+ while (trailer != 0)
+ {
+ block = (long *) trailer->this_address;
+ size = trailer->this_size;
+ if (block == 0 || size == 0)
+ abort ();
+ trailer = (struct stk_trailer *) trailer->link;
+ if ((block <= address) && (address < (block + size)))
+ break;
+ }
+
+ /* Set the result to the offset in this segment and add the sizes
+ of all predecessor segments. */
+
+ result = address - block;
+
+ if (trailer == 0)
+ {
+ return result;
+ }
+
+ do
+ {
+ if (trailer->this_size <= 0)
+ abort ();
+ result += trailer->this_size;
+ trailer = (struct stk_trailer *) trailer->link;
+ }
+ while (trailer != 0);
+
+ /* We are done. Note that if you present a bogus address (one
+ not in any segment), you will get a different number back, formed
+ from subtracting the address of the first block. This is probably
+ not what you want. */
+
+ return (result);
+}
+
+#else /* not CRAY2 */
+/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
+ Determine the number of the cell within the stack,
+ given the address of the cell. The purpose of this
+ routine is to linearize, in some sense, stack addresses
+ for alloca. */
+
+static long
+i00afunc (long address)
+{
+ long stkl = 0;
+
+ long size, pseg, this_segment, stack;
+ long result = 0;
+
+ struct stack_segment_linkage *ssptr;
+
+ /* Register B67 contains the address of the end of the
+ current stack segment. If you (as a subprogram) store
+ your registers on the stack and find that you are past
+ the contents of B67, you have overflowed the segment.
+
+ B67 also points to the stack segment linkage control
+ area, which is what we are really interested in. */
+
+ stkl = CRAY_STACKSEG_END ();
+ ssptr = (struct stack_segment_linkage *) stkl;
+
+ /* If one subtracts 'size' from the end of the segment,
+ one has the address of the first word of the segment.
+
+ If this is not the first segment, 'pseg' will be
+ nonzero. */
+
+ pseg = ssptr->sspseg;
+ size = ssptr->sssize;
+
+ this_segment = stkl - size;
+
+ /* It is possible that calling this routine itself caused
+ a stack overflow. Discard stack segments which do not
+ contain the target address. */
+
+ while (!(this_segment <= address && address <= stkl))
+ {
+#ifdef DEBUG_I00AFUNC
+ fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
+#endif
+ if (pseg == 0)
+ break;
+ stkl = stkl - pseg;
+ ssptr = (struct stack_segment_linkage *) stkl;
+ size = ssptr->sssize;
+ pseg = ssptr->sspseg;
+ this_segment = stkl - size;
+ }
+
+ result = address - this_segment;
+
+ /* If you subtract pseg from the current end of the stack,
+ you get the address of the previous stack segment's end.
+ This seems a little convoluted to me, but I'll bet you save
+ a cycle somewhere. */
+
+ while (pseg != 0)
+ {
+#ifdef DEBUG_I00AFUNC
+ fprintf (stderr, "%011o %011o\n", pseg, size);
+#endif
+ stkl = stkl - pseg;
+ ssptr = (struct stack_segment_linkage *) stkl;
+ size = ssptr->sssize;
+ pseg = ssptr->sspseg;
+ result += size;
+ }
+ return (result);
+}
+
+#endif /* not CRAY2 */
+#endif /* CRAY */
+
+#endif /* no alloca */
+#endif /* not GCC version 2 */
diff --git a/contrib/amd/libamu/amu.h b/contrib/amd/libamu/amu.h
index 38532d0..a22371e 100644
--- a/contrib/amd/libamu/amu.h
+++ b/contrib/amd/libamu/amu.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: amu.h,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: amu.h,v 1.2 1999/01/10 21:54:36 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/hasmntopt.c b/contrib/amd/libamu/hasmntopt.c
index 2ed75f5..5f19e71 100644
--- a/contrib/amd/libamu/hasmntopt.c
+++ b/contrib/amd/libamu/hasmntopt.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@ n * modification, are permitted provided that the following conditions
*
* %W% (Berkeley) %G%
*
- * $Id: hasmntopt.c,v 1.1.1.1 1998/11/05 02:04:44 ezk Exp $
+ * $Id: hasmntopt.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/misc_rpc.c b/contrib/amd/libamu/misc_rpc.c
index ec34e35..fa402c3 100644
--- a/contrib/amd/libamu/misc_rpc.c
+++ b/contrib/amd/libamu/misc_rpc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: misc_rpc.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: misc_rpc.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/mtab.c b/contrib/amd/libamu/mtab.c
index 7fe95de..3bcc38d 100644
--- a/contrib/amd/libamu/mtab.c
+++ b/contrib/amd/libamu/mtab.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: mtab.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: mtab.c,v 1.2 1999/01/10 21:54:37 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/nfs_prot_xdr.c b/contrib/amd/libamu/nfs_prot_xdr.c
index cbe6793..874f57a 100644
--- a/contrib/amd/libamu/nfs_prot_xdr.c
+++ b/contrib/amd/libamu/nfs_prot_xdr.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: nfs_prot_xdr.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: nfs_prot_xdr.c,v 1.2 1999/01/10 21:54:38 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/util.c b/contrib/amd/libamu/util.c
index 0650de2..72fcdad 100644
--- a/contrib/amd/libamu/util.c
+++ b/contrib/amd/libamu/util.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: util.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: util.c,v 1.2 1999/01/10 21:54:39 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/wire.c b/contrib/amd/libamu/wire.c
index bd7b5ad..c8ed892 100644
--- a/contrib/amd/libamu/wire.c
+++ b/contrib/amd/libamu/wire.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: wire.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: wire.c,v 1.5 1999/09/08 23:36:52 ezk Exp $
*
*/
@@ -61,6 +61,14 @@
#include <amu.h>
+#ifdef HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif /* HAVE_IFADDRS_H */
+
+#ifdef HAVE_IRS_H
+# include <irs.h>
+#endif /* HAVE_IRS_H */
+
/*
* List of locally connected networks
*/
@@ -78,16 +86,9 @@ static addrlist *localnets = NULL;
# define IFF_LOOPBACK IFF_LOCAL_LOOPBACK
#endif /* defined(IFF_LOCAL_LOOPBACK) && !defined(IFF_LOOPBACK) */
-#if defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN)
-# define SIZE(ifr) (MAX((ifr)->ifr_addr.sa_len, sizeof((ifr)->ifr_addr)) + sizeof(ifr->ifr_name))
-#else /* not defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN) */
-# define SIZE(ifr) sizeof(struct ifreq)
-#endif /* not defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN) */
-
#define C(x) ((x) & 0xff)
#define GFBUFLEN 1024
-#define clist (ifc.ifc_ifcu.ifcu_req)
-#define count (ifc.ifc_len/sizeof(struct ifreq))
+#define S2IN(s) (((struct sockaddr_in *)(s))->sin_addr.s_addr)
/* return malloc'ed buffer. caller must free it */
@@ -101,7 +102,7 @@ print_wires(void)
int bufcount = 0;
int buf_size = 1024;
- buf = malloc(1024);
+ buf = SALLOC(1024);
if (!buf)
return NULL;
@@ -131,22 +132,262 @@ print_wires(void)
}
+static struct addrlist *
+getwire_lookup(u_long address, u_long netmask, int ishost)
+{
+ struct addrlist *al;
+ u_long subnet;
+ char netNumberBuf[64];
+ char buf[GFBUFLEN], *s;
+#ifdef HAVE_IRS_H
+ struct nwent *np;
+#else /* not HAVE_IRS_H */
+ struct netent *np;
+#endif /* not HAVE_IRS_H */
+
+ /*
+ * Add interface to local network singly linked list
+ */
+ al = ALLOC(struct addrlist);
+ al->ip_addr = address;
+ al->ip_mask = netmask;
+ al->ip_net_name = NO_SUBNET; /* fill in a bit later */
+ al->ip_net_num = "0.0.0.0"; /* fill in a bit later */
+ al->ip_next = NULL;
+
+ subnet = ntohl(address) & ntohl(netmask);
+
+ if (ishost)
+ np = NULL;
+ else {
+#ifdef HAVE_IRS_H
+ u_long mask = ntohl(netmask);
+ static struct irs_acc *irs_gen;
+ static struct irs_nw *irs_nw;
+ u_long net;
+ int maskbits;
+ u_char addr[4];
+
+ if (irs_gen == NULL)
+ irs_gen = irs_gen_acc("");
+ if (irs_gen && irs_nw == NULL)
+ irs_nw = (*irs_gen->nw_map)(irs_gen);
+ net = ntohl(address) & (mask = ntohl(netmask));
+ addr[0] = (0xFF000000 & net) >> 24;
+ addr[1] = (0x00FF0000 & net) >> 16;
+ addr[2] = (0x0000FF00 & net) >> 8;
+ addr[3] = (0x000000FF & net);
+ for (maskbits = 32; !(mask & 1); mask >>= 1)
+ maskbits--;
+ np = (*irs_nw->byaddr)(irs_nw, addr, maskbits, AF_INET);
+#else /* not HAVE_IRS_H */
+ np = getnetbyaddr(subnet, AF_INET);
+ /*
+ * Some systems (IRIX 6.4) cannot getnetbyaddr on networks such as
+ * "128.59.16.0". Instead, they need to look for the short form of
+ * the network, "128.59.16". So if the first getnetbyaddr failed, we
+ * shift the subnet way from zeros and try again.
+ */
+ if (!np) {
+ u_long short_subnet = subnet;
+ while(short_subnet && (short_subnet & 0x000000ff) == 0)
+ short_subnet >>= 8;
+ np = getnetbyaddr(short_subnet, AF_INET);
+ if (np)
+ plog(XLOG_WARNING, "getnetbyaddr failed on 0x%x, succeeded on 0x%x",
+ (u_int) subnet, (u_int) short_subnet);
+ }
+#endif /* not HAVE_IRS_H */
+ }
+
+ if ((subnet & 0xffffff) == 0) {
+ sprintf(netNumberBuf, "%lu", C(subnet >> 24));
+ } else if ((subnet & 0xffff) == 0) {
+ sprintf(netNumberBuf, "%lu.%lu",
+ C(subnet >> 24), C(subnet >> 16));
+ } else if ((subnet & 0xff) == 0) {
+ sprintf(netNumberBuf, "%lu.%lu.%lu",
+ C(subnet >> 24), C(subnet >> 16),
+ C(subnet >> 8));
+ } else {
+ sprintf(netNumberBuf, "%lu.%lu.%lu.%lu",
+ C(subnet >> 24), C(subnet >> 16),
+ C(subnet >> 8), C(subnet));
+ }
+
+ /* fill in network number (string) */
+ al->ip_net_num = strdup(netNumberBuf);
+
+ if (np != NULL)
+ s = np->n_name;
+ else {
+ struct hostent *hp;
+
+ subnet = address & netmask;
+ hp = gethostbyaddr((char *) &subnet, 4, AF_INET);
+ if (hp != NULL)
+ s = (char *) hp->h_name;
+ else
+ s = inet_dquad(buf, subnet);
+ }
+
+ /* fill in network name (string) */
+ al->ip_net_name = strdup(s);
+
+ return (al);
+}
+
+
+/*
+ * Make a dotted quad from a 32bit IP address
+ * addr is in network byte order.
+ * sizeof(buf) needs to be at least 16.
+ */
+char *
+inet_dquad(char *buf, u_long addr)
+{
+ addr = ntohl(addr);
+ sprintf(buf, "%ld.%ld.%ld.%ld",
+ ((addr >> 24) & 0xff),
+ ((addr >> 16) & 0xff),
+ ((addr >> 8) & 0xff),
+ ((addr >> 0) & 0xff));
+ return buf;
+}
+
+
+/*
+ * Determine whether a network is on a local network
+ * (addr) is in network byte order.
+ */
+int
+islocalnet(u_long addr)
+{
+ addrlist *al;
+#ifdef DEBUG
+ char buf[16];
+#endif /* DEBUG */
+
+ for (al = localnets; al; al = al->ip_next)
+ if (((addr ^ al->ip_addr) & al->ip_mask) == 0)
+ return TRUE;
+
+#ifdef DEBUG
+ plog(XLOG_INFO, "%s is on a remote network", inet_dquad(buf, addr));
+#endif /* DEBUG */
+
+ return FALSE;
+}
+
+
+/*
+ * Determine whether a network name is one of the local networks
+ * of a host.
+ */
+int
+is_network_member(const char *net)
+{
+ addrlist *al;
+
+ for (al = localnets; al; al = al->ip_next)
+ if (STREQ(net, al->ip_net_name) || STREQ(net, al->ip_net_num))
+ return TRUE;
+
+ return FALSE;
+}
+
+
+#ifdef HAVE_GETIFADDRS
+void
+getwire(char **name1, char **number1)
+{
+ addrlist *al = NULL, *tail = NULL;
+ struct ifaddrs *ifaddrs, *ifap;
+#ifndef HAVE_FIELD_STRUCT_IFADDRS_IFA_NEXT
+ int count = 0, i;
+#endif /* not HAVE_FIELD_STRUCT_IFADDRS_IFA_NEXT */
+
+ ifaddrs = NULL;
+#ifdef HAVE_FIELD_STRUCT_IFADDRS_IFA_NEXT
+ if (getifaddrs(&ifaddrs) < 0)
+ goto out;
+
+ for (ifap = ifaddrs; ifap != NULL; ifap = ifap->ifa_next) {
+#else /* not HAVE_FIELD_STRUCT_IFADDRS_IFA_NEXT */
+ if (getifaddrs(&ifaddrs, &count) < 0)
+ goto out;
+
+ for (i = 0,ifap = ifaddrs; i < count; ifap++, i++) {
+#endif /* HAVE_FIELD_STRUCT_IFADDRS_IFA_NEXT */
+
+ if (!ifap || !ifap->ifa_addr || ifap->ifa_addr->sa_family != AF_INET)
+ continue;
+
+ /*
+ * If the interface is a loopback, or its not running
+ * then ignore it.
+ */
+ if ((ifap->ifa_flags & IFF_LOOPBACK) != 0)
+ continue;
+ if ((ifap->ifa_flags & IFF_RUNNING) == 0)
+ continue;
+
+ if ((ifap->ifa_flags & IFF_POINTOPOINT) == 0)
+ al = getwire_lookup(S2IN(ifap->ifa_addr), S2IN(ifap->ifa_netmask), 0);
+ else
+ al = getwire_lookup(S2IN(ifap->ifa_dstaddr), 0xffffffff, 1);
+
+ /* append to the end of the list */
+ if (!localnets) {
+ localnets = tail = al;
+ tail->ip_next = NULL;
+ } else {
+ tail->ip_next = al;
+ tail = al;
+ }
+ }
+
+out:
+ if (ifaddrs)
+ XFREE(ifaddrs);
+
+ if (localnets) {
+ *name1 = localnets->ip_net_name;
+ *number1 = localnets->ip_net_num;
+ } else {
+ *name1 = NO_SUBNET;
+ *number1 = "0.0.0.0";
+ }
+}
+
+#else /* not HAVE_GETIFADDRS */
+
+#if defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN)
+# define SIZE(ifr) (MAX((ifr)->ifr_addr.sa_len, sizeof((ifr)->ifr_addr)) + sizeof(ifr->ifr_name))
+#else /* not defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN) */
+# define SIZE(ifr) sizeof(struct ifreq)
+#endif /* not defined(HAVE_FIELD_STRUCT_IFREQ_IFR_ADDR) && defined(HAVE_FIELD_STRUCT_SOCKADDR_SA_LEN) */
+
+#define clist (ifc.ifc_ifcu.ifcu_req)
+#define count (ifc.ifc_len/sizeof(struct ifreq))
+
+
void
getwire(char **name1, char **number1)
{
- struct hostent *hp;
- struct netent *np;
struct ifconf ifc;
struct ifreq *ifr;
caddr_t cp, cplim;
- u_long address, netmask, subnet;
- char buf[GFBUFLEN], *s;
int fd = -1;
+ u_long address;
+ addrlist *al = NULL, *tail = NULL;
+ char buf[GFBUFLEN];
+#if 0
u_long net;
u_long mask;
u_long subnetshift;
- char netNumberBuf[64];
- addrlist *al = NULL, *tail = NULL;
+ char buf[GFBUFLEN], *s;
+#endif
#ifndef SIOCGIFFLAGS
/* if cannot get interface flags, return nothing */
@@ -194,8 +435,8 @@ getwire(char **name1, char **number1)
if (ifr->ifr_addr.sa_family != AF_INET)
continue;
- else
- address = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+
+ address = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
/*
* Get interface flags
@@ -225,23 +466,17 @@ getwire(char **name1, char **number1)
(ifr->ifr_flags & IFF_UP) == 0)
continue;
- /*
- * Get the netmask of this interface
- */
- if (ioctl(fd, SIOCGIFNETMASK, (caddr_t) ifr) < 0)
- continue;
+ if ((ifr->ifr_flags & IFF_POINTOPOINT) == 0) {
+ /*
+ * Get the netmask of this interface
+ */
+ if (ioctl(fd, SIOCGIFNETMASK, (caddr_t) ifr) < 0)
+ continue;
- netmask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+ al = getwire_lookup(address, S2IN(&ifr->ifr_addr), 0);
+ } else
+ al = getwire_lookup(address, 0xffffffff, 1);
- /*
- * Add interface to local network singly linked list
- */
- al = ALLOC(struct addrlist);
- al->ip_addr = address;
- al->ip_mask = netmask;
- al->ip_net_name = NO_SUBNET; /* fill in a bit later */
- al->ip_net_num = "0.0.0.0"; /* fill in a bit later */
- al->ip_next = NULL;
/* append to the end of the list */
if (!localnets) {
localnets = tail = al;
@@ -250,86 +485,6 @@ getwire(char **name1, char **number1)
tail->ip_next = al;
tail = al;
}
-
- /*
- * Figure out the subnet's network address
- */
- subnet = address & netmask;
-
-#ifdef IN_CLASSA
- subnet = htonl(subnet);
-
- if (IN_CLASSA(subnet)) {
- mask = IN_CLASSA_NET;
- subnetshift = 8;
- } else if (IN_CLASSB(subnet)) {
- mask = IN_CLASSB_NET;
- subnetshift = 8;
- } else {
- mask = IN_CLASSC_NET;
- subnetshift = 4;
- }
-
- /*
- * If there are more bits than the standard mask
- * would suggest, subnets must be in use.
- * Guess at the subnet mask, assuming reasonable
- * width subnet fields.
- * XXX: Or-in at least 1 byte's worth of 1s to make
- * sure the top bits remain set.
- */
- while (subnet & ~mask)
- mask = (mask >> subnetshift) | 0xff000000;
-
- net = subnet & mask;
- while ((mask & 1) == 0)
- mask >>= 1, net >>= 1;
-
- /*
- * Now get a usable name.
- * First use the network database,
- * then the host database,
- * and finally just make a dotted quad.
- */
- np = getnetbyaddr(net, AF_INET);
-
- /* the network address has been masked off */
- if ((subnet & 0xffffff) == 0) {
- sprintf(netNumberBuf, "%lu", C(subnet >> 24));
- } else if ((subnet & 0xffff) == 0) {
- sprintf(netNumberBuf, "%lu.%lu",
- C(subnet >> 24), C(subnet >> 16));
- } else if ((subnet & 0xff) == 0) {
- sprintf(netNumberBuf, "%lu.%lu.%lu",
- C(subnet >> 24), C(subnet >> 16),
- C(subnet >> 8));
- } else {
- sprintf(netNumberBuf, "%lu.%lu.%lu.%lu",
- C(subnet >> 24), C(subnet >> 16),
- C(subnet >> 8), C(subnet));
- }
-
- /* fill in network number (string) */
- al->ip_net_num = strdup(netNumberBuf);
-
-#else /* not IN_CLASSA */
- /* This is probably very wrong. */
- np = getnetbyaddr(subnet, AF_INET);
-#endif /* not IN_CLASSA */
-
- if (np)
- s = np->n_name;
- else {
- subnet = address & netmask;
- hp = gethostbyaddr((char *) &subnet, 4, AF_INET);
- if (hp)
- s = (char *) hp->h_name;
- else
- s = inet_dquad(buf, subnet);
- }
-
- /* fill in network name (string) */
- al->ip_net_name = strdup(s);
}
out:
@@ -343,62 +498,4 @@ out:
*number1 = "0.0.0.0";
}
}
-
-
-/*
- * Make a dotted quad from a 32bit IP address
- * addr is in network byte order.
- * sizeof(buf) needs to be at least 16.
- */
-char *
-inet_dquad(char *buf, u_long addr)
-{
- addr = ntohl(addr);
- sprintf(buf, "%ld.%ld.%ld.%ld",
- ((addr >> 24) & 0xff),
- ((addr >> 16) & 0xff),
- ((addr >> 8) & 0xff),
- ((addr >> 0) & 0xff));
- return buf;
-}
-
-
-/*
- * Determine whether a network is on a local network
- * (addr) is in network byte order.
- */
-int
-islocalnet(u_long addr)
-{
- addrlist *al;
-#ifdef DEBUG
- char buf[16];
-#endif /* DEBUG */
-
- for (al = localnets; al; al = al->ip_next)
- if (((addr ^ al->ip_addr) & al->ip_mask) == 0)
- return TRUE;
-
-#ifdef DEBUG
- plog(XLOG_INFO, "%s is on a remote network", inet_dquad(buf, addr));
-#endif /* DEBUG */
-
- return FALSE;
-}
-
-
-/*
- * Determine whether a network name is one of the local networks
- * of a host.
- */
-int
-is_network_member(const char *net)
-{
- addrlist *al;
-
- for (al = localnets; al; al = al->ip_next)
- if (STREQ(net, al->ip_net_name) || STREQ(net, al->ip_net_num))
- return TRUE;
-
- return FALSE;
-}
+#endif /* not HAVE_GETIFADDRS */
diff --git a/contrib/amd/libamu/xdr_func.c b/contrib/amd/libamu/xdr_func.c
index 365d390..deeb205 100644
--- a/contrib/amd/libamu/xdr_func.c
+++ b/contrib/amd/libamu/xdr_func.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: xdr_func.c,v 1.1.1.1 1998/11/05 02:04:45 ezk Exp $
+ * $Id: xdr_func.c,v 1.2 1999/01/10 21:54:39 ezk Exp $
*
*/
diff --git a/contrib/amd/libamu/xutil.c b/contrib/amd/libamu/xutil.c
index d069f7a..5ba4938 100644
--- a/contrib/amd/libamu/xutil.c
+++ b/contrib/amd/libamu/xutil.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997-1998 Erez Zadok
+ * Copyright (c) 1997-1999 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
@@ -38,7 +38,7 @@
*
* %W% (Berkeley) %G%
*
- * $Id: xutil.c,v 1.2 1998/12/27 06:25:24 ezk Exp $
+ * $Id: xutil.c,v 1.6 1999/09/08 23:36:53 ezk Exp $
*
*/
@@ -48,7 +48,12 @@
#include <am_defs.h>
#include <amu.h>
-FILE *logfp = stderr; /* Log errors to stderr initially */
+/*
+ * Logfp is the default logging device, and is initialized to stderr by
+ * default in dplog/plog below, and in
+ * amd/amfs_program.c:amfs_program_exec().
+ */
+FILE *logfp = NULL;
static char *am_progname = "unknown"; /* "amd" */
static char am_hostname[MAXHOSTNAMELEN + 1] = "unknown"; /* Hostname */
@@ -272,30 +277,38 @@ checkup_mem(void)
/*
* Take a log format string and expand occurrences of %m
- * with the current error code taken from errno.
+ * with the current error code taken from errno. Make sure
+ * 'e' never gets longer than maxlen characters.
*/
static void
-expand_error(char *f, char *e)
+expand_error(char *f, char *e, int maxlen)
{
extern int sys_nerr;
- char *p;
+ char *p, *q;
int error = errno;
+ int len = 0;
- for (p = f; (*e = *p); e++, p++) {
+ for (p = f, q = e; (*q = *p) && len < maxlen; len++, q++, p++) {
if (p[0] == '%' && p[1] == 'm') {
const char *errstr;
if (error < 0 || error >= sys_nerr)
errstr = NULL;
else
- errstr = sys_errlist[error];
+#ifdef HAVE_STRERROR
+ errstr = strerror(error);
+#else /* not HAVE_STRERROR */
+ errstr = sys_errlist[error];
+#endif /* not HAVE_STRERROR */
if (errstr)
- strcpy(e, errstr);
+ strcpy(q, errstr);
else
- sprintf(e, "Error %d", error);
- e += strlen(e) - 1;
+ sprintf(q, "Error %d", error);
+ len += strlen(q) - 1;
+ q += strlen(q) - 1;
p++;
}
}
+ e[maxlen-1] = '\0'; /* null terminate, to be sure */
}
@@ -367,6 +380,9 @@ dplog(char *fmt, ...)
{
va_list ap;
+ if (!logfp)
+ logfp = stderr; /* initialize before possible first use */
+
va_start(ap, fmt);
real_plog(XLOG_DEBUG, fmt, ap);
va_end(ap);
@@ -379,6 +395,9 @@ plog(int lvl, char *fmt, ...)
{
va_list ap;
+ if (!logfp)
+ logfp = stderr; /* initialize before possible first use */
+
va_start(ap, fmt);
real_plog(lvl, fmt, ap);
va_end(ap);
@@ -401,9 +420,15 @@ real_plog(int lvl, char *fmt, va_list vargs)
checkup_mem();
#endif /* DEBUG_MEM */
- expand_error(fmt, efmt);
+ expand_error(fmt, efmt, 1024);
+ /*
+ * XXX: ptr is 1024 bytes long. It is possible to write into it
+ * more than 1024 bytes, if efmt is already large, and vargs expand
+ * as well.
+ */
vsprintf(ptr, efmt, vargs);
+ msg[1023] = '\0'; /* null terminate, to be sure */
ptr += strlen(ptr);
if (ptr[-1] == '\n')
@@ -616,6 +641,7 @@ switch_option(char *opt)
return rc;
}
+#ifdef LOG_DAEMON
/*
* get syslog facility to use.
* logfile can be "syslog", "syslog:daemon", "syslog:local7", etc.
@@ -647,10 +673,10 @@ get_syslog_facility(const char *logfile)
if (STREQ(facstr, "mail"))
return LOG_MAIL;
#endif /* not LOG_MAIL */
-#ifdef LOG_DAEMON
+
if (STREQ(facstr, "daemon"))
return LOG_DAEMON;
-#endif /* not LOG_DAEMON */
+
#ifdef LOG_AUTH
if (STREQ(facstr, "auth"))
return LOG_AUTH;
@@ -712,6 +738,7 @@ get_syslog_facility(const char *logfile)
plog(XLOG_WARNING, "unknown syslog facility \"%s\", using LOG_DAEMON", facstr);
return LOG_DAEMON;
}
+#endif /* not LOG_DAEMON */
/*
OpenPOWER on IntegriCloud