Ported latest traceroute, courtesy of Hugo Santos.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20492 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,9 +8,19 @@ if $(TARGET_PLATFORM) != haiku {
|
|||||||
# Unfortunately we get more than we want, namely all POSIX headers.
|
# Unfortunately we get more than we want, namely all POSIX headers.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local defines = [ FDefines HAVE_MALLOC_H=1 HAVE_SYS_SELECT=1 HAVE_NET_ROUTE_H=1
|
||||||
|
HAVE_STRERROR=1 HAVE_USLEEP=1 HAVE_SETLINEBUF=1
|
||||||
|
BYTESWAP_IP_HDR=1 HAVE_MALLOC_H=1
|
||||||
|
HAVE_ICMP_NEXTMTU=1 HAVE_SOCKADDR_SA_LEN=1 ] ;
|
||||||
|
|
||||||
|
SubDirCcFlags $(defines) ;
|
||||||
|
SubDirC++Flags $(defines) ;
|
||||||
|
|
||||||
BinCommand traceroute :
|
BinCommand traceroute :
|
||||||
arc4random.c
|
findsaddr-generic.c
|
||||||
|
ifaddrlist.c
|
||||||
traceroute.c
|
traceroute.c
|
||||||
|
version.c
|
||||||
: $(NETWORK_LIBS) $(SELECT_UNAME_ETC_LIB) ;
|
: $(NETWORK_LIBS) $(SELECT_UNAME_ETC_LIB) ;
|
||||||
|
|
||||||
# Installation -- in the test directory for the time being
|
# Installation -- in the test directory for the time being
|
||||||
|
|||||||
@@ -1,149 +0,0 @@
|
|||||||
/*
|
|
||||||
* Arc4 random number generator for OpenBSD.
|
|
||||||
* Copyright 1996 David Mazieres <[email protected]>.
|
|
||||||
*
|
|
||||||
* Modification and redistribution in source and binary forms is
|
|
||||||
* permitted provided that due credit is given to the author and the
|
|
||||||
* OpenBSD project by leaving this copyright notice intact.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This code is derived from section 17.1 of Applied Cryptography,
|
|
||||||
* second edition, which describes a stream cipher allegedly
|
|
||||||
* compatible with RSA Labs "RC4" cipher (the actual description of
|
|
||||||
* which is a trade secret). The same algorithm is used as a stream
|
|
||||||
* cipher called "arcfour" in Tatu Ylonen's ssh package.
|
|
||||||
*
|
|
||||||
* Here the stream cipher has been modified always to include the time
|
|
||||||
* when initializing the state. That makes it impossible to
|
|
||||||
* regenerate the same random sequence twice, so this can't be used
|
|
||||||
* for encryption, but will generate good random numbers.
|
|
||||||
*
|
|
||||||
* RC4 is a registered trademark of RSA Laboratories.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <kernel/OS.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#define inline __inline
|
|
||||||
#else /* !__GNUC__ */
|
|
||||||
#define inline
|
|
||||||
#endif /* !__GNUC__ */
|
|
||||||
|
|
||||||
struct arc4_stream {
|
|
||||||
uint8 i;
|
|
||||||
uint8 j;
|
|
||||||
uint8 s[256];
|
|
||||||
};
|
|
||||||
|
|
||||||
int rs_initialized;
|
|
||||||
static struct arc4_stream rs;
|
|
||||||
|
|
||||||
uint32 arc4random(void);
|
|
||||||
|
|
||||||
|
|
||||||
static inline void arc4_init(struct arc4_stream *as)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
|
|
||||||
for (n = 0; n < 256; n++)
|
|
||||||
as->s[n] = n;
|
|
||||||
as->i = 0;
|
|
||||||
as->j = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline void arc4_addrandom(struct arc4_stream *as,
|
|
||||||
u_char *dat, int datlen)
|
|
||||||
{
|
|
||||||
int n;
|
|
||||||
uint8 si;
|
|
||||||
|
|
||||||
as->i--;
|
|
||||||
for (n = 0; n < 256; n++) {
|
|
||||||
as->i = (as->i + 1);
|
|
||||||
si = as->s[as->i];
|
|
||||||
as->j = (as->j + si + dat[n % datlen]);
|
|
||||||
as->s[as->i] = as->s[as->j];
|
|
||||||
as->s[as->j] = si;
|
|
||||||
}
|
|
||||||
as->j = as->i;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void arc4_stir(struct arc4_stream *as)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
struct {
|
|
||||||
struct timeval tv;
|
|
||||||
u_int rnd[(128 - sizeof(struct timeval)) / sizeof(u_int)];
|
|
||||||
} rdat;
|
|
||||||
|
|
||||||
gettimeofday(&rdat.tv, NULL);
|
|
||||||
fd = open("/dev/arandom", O_RDONLY);
|
|
||||||
if (fd != -1) {
|
|
||||||
read(fd, rdat.rnd, sizeof(rdat.rnd));
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
/* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take
|
|
||||||
* whatever was on the stack... */
|
|
||||||
|
|
||||||
arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline uint8 arc4_getbyte(struct arc4_stream *as)
|
|
||||||
{
|
|
||||||
uint8 si, sj;
|
|
||||||
|
|
||||||
as->i = (as->i + 1);
|
|
||||||
si = as->s[as->i];
|
|
||||||
as->j = (as->j + si);
|
|
||||||
sj = as->s[as->j];
|
|
||||||
as->s[as->i] = sj;
|
|
||||||
as->s[as->j] = si;
|
|
||||||
return (as->s[(si + sj) & 0xff]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline uint32 arc4_getword(struct arc4_stream *as)
|
|
||||||
{
|
|
||||||
uint32 val;
|
|
||||||
val = arc4_getbyte(as) << 24;
|
|
||||||
val |= arc4_getbyte(as) << 16;
|
|
||||||
val |= arc4_getbyte(as) << 8;
|
|
||||||
val |= arc4_getbyte(as);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void arc4random_stir(void)
|
|
||||||
{
|
|
||||||
if (!rs_initialized) {
|
|
||||||
arc4_init(&rs);
|
|
||||||
rs_initialized = 1;
|
|
||||||
}
|
|
||||||
arc4_stir(&rs);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
void arc4random_addrandom(u_char *dat, int datlen)
|
|
||||||
{
|
|
||||||
if (!rs_initialized)
|
|
||||||
arc4random_stir();
|
|
||||||
arc4_addrandom(&rs, dat, datlen);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint32 arc4random(void)
|
|
||||||
{
|
|
||||||
if (!rs_initialized)
|
|
||||||
arc4random_stir();
|
|
||||||
return arc4_getword(&rs);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2000
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Computer Systems
|
||||||
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||||
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"@(#) $Id: findsaddr-generic.c,v 1.1 2000/11/23 20:17:12 leres Exp $ (LBL)";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
|
#include <sys/sockio.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/time.h> /* concession to AIX */
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
|
struct mbuf;
|
||||||
|
struct rtentry;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "gnuc.h"
|
||||||
|
#ifdef HAVE_OS_PROTO_H
|
||||||
|
#include "os-proto.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "findsaddr.h"
|
||||||
|
#include "ifaddrlist.h"
|
||||||
|
#include "traceroute.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the source address for the given destination address
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
findsaddr(register const struct sockaddr_in *to,
|
||||||
|
register struct sockaddr_in *from)
|
||||||
|
{
|
||||||
|
register int n;
|
||||||
|
struct ifaddrlist *al;
|
||||||
|
static char errbuf[132];
|
||||||
|
|
||||||
|
/* Get the interface address list */
|
||||||
|
if ((n = ifaddrlist(&al, errbuf)) < 0)
|
||||||
|
return (errbuf);
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return ("Can't find any network interfaces");
|
||||||
|
|
||||||
|
setsin(from, al->addr);
|
||||||
|
if (n > 1)
|
||||||
|
fprintf(stderr,
|
||||||
|
"%s: Warning: Multiple interfaces found; using %s @ %s\n",
|
||||||
|
prog, inet_ntoa(from->sin_addr), al->device);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2000
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the University of California,
|
||||||
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* @(#) $Id: findsaddr.h,v 1.1 2000/11/19 23:13:38 leres Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
const char *findsaddr(const struct sockaddr_in *, struct sockaddr_in *);
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/* @(#) $Header: gnuc.h,v 1.3 95/10/09 02:47:01 leres Exp $ (LBL) */
|
||||||
|
|
||||||
|
/* Define __P() macro, if necessary */
|
||||||
|
#ifndef __P
|
||||||
|
#if __STDC__
|
||||||
|
#define __P(protos) protos
|
||||||
|
#else
|
||||||
|
#define __P(protos) ()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* inline foo */
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define inline __inline
|
||||||
|
#else
|
||||||
|
#define inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Handle new and old "dead" routine prototypes
|
||||||
|
*
|
||||||
|
* For example:
|
||||||
|
*
|
||||||
|
* __dead void foo(void) __attribute__((volatile));
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#ifndef __dead
|
||||||
|
#define __dead volatile
|
||||||
|
#endif
|
||||||
|
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|
||||||
|
#ifndef __attribute__
|
||||||
|
#define __attribute__(args)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifndef __dead
|
||||||
|
#define __dead
|
||||||
|
#endif
|
||||||
|
#ifndef __attribute__
|
||||||
|
#define __attribute__(args)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1997, 1998, 1999, 2000
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the Computer Systems
|
||||||
|
* Engineering Group at Lawrence Berkeley Laboratory.
|
||||||
|
* 4. Neither the name of the University nor of the Laboratory may be used
|
||||||
|
* to endorse or promote products derived from this software without
|
||||||
|
* specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static const char rcsid[] =
|
||||||
|
"@(#) $Id: ifaddrlist.c,v 1.9 2000/11/23 20:01:55 leres Exp $ (LBL)";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#ifdef HAVE_SYS_SOCKIO_H
|
||||||
|
#include <sys/sockio.h>
|
||||||
|
#endif
|
||||||
|
#include <sys/time.h> /* concession to AIX */
|
||||||
|
|
||||||
|
#include <sys/sockio.h> /* for SIOCGIFCONF */
|
||||||
|
|
||||||
|
#if __STDC__
|
||||||
|
struct mbuf;
|
||||||
|
struct rtentry;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "gnuc.h"
|
||||||
|
#ifdef HAVE_OS_PROTO_H
|
||||||
|
#include "os-proto.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ifaddrlist.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return the interface list
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ifaddrlist(register struct ifaddrlist **ipaddrp, register char *errbuf)
|
||||||
|
{
|
||||||
|
register int fd, nipaddr;
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
register int n;
|
||||||
|
#endif
|
||||||
|
register struct ifreq *ifrp, *ifend, *ifnext, *mp;
|
||||||
|
register struct sockaddr_in *sin;
|
||||||
|
register struct ifaddrlist *al;
|
||||||
|
struct ifconf ifc;
|
||||||
|
struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
|
||||||
|
#define MAX_IPADDR (sizeof(ibuf) / sizeof(ibuf[0]))
|
||||||
|
static struct ifaddrlist ifaddrlist[MAX_IPADDR];
|
||||||
|
char device[sizeof(ifr.ifr_name) + 1];
|
||||||
|
|
||||||
|
fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (fd < 0) {
|
||||||
|
(void)sprintf(errbuf, "socket: %s", strerror(errno));
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ifc.ifc_len = sizeof(ibuf);
|
||||||
|
ifc.ifc_buf = (caddr_t)ibuf;
|
||||||
|
|
||||||
|
if (ioctl(fd, SIOCGIFCONF, (char *)&ifc) < 0) {
|
||||||
|
if (errno == EINVAL)
|
||||||
|
(void)sprintf(errbuf,
|
||||||
|
"SIOCGIFCONF: ifreq struct too small (%d bytes)",
|
||||||
|
sizeof(ibuf));
|
||||||
|
else
|
||||||
|
(void)sprintf(errbuf, "SIOCGIFCONF: %s",
|
||||||
|
strerror(errno));
|
||||||
|
(void)close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
ifrp = ibuf;
|
||||||
|
ifend = (struct ifreq *)((char *)ibuf + ifc.ifc_len);
|
||||||
|
|
||||||
|
al = ifaddrlist;
|
||||||
|
mp = NULL;
|
||||||
|
nipaddr = 0;
|
||||||
|
for (; ifrp < ifend; ifrp = ifnext) {
|
||||||
|
#ifdef HAVE_SOCKADDR_SA_LEN
|
||||||
|
n = ifrp->ifr_addr.sa_len + sizeof(ifrp->ifr_name);
|
||||||
|
/*
|
||||||
|
* our ifreqs from SIOCGIFCONF dumps are very packed
|
||||||
|
*/
|
||||||
|
ifnext = (struct ifreq *)((char *)ifrp + n);
|
||||||
|
if (ifrp->ifr_addr.sa_family != AF_INET)
|
||||||
|
continue;
|
||||||
|
#else
|
||||||
|
ifnext = ifrp + 1;
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Need a template to preserve address info that is
|
||||||
|
* used below to locate the next entry. (Otherwise,
|
||||||
|
* SIOCGIFFLAGS stomps over it because the requests
|
||||||
|
* are returned in a union.)
|
||||||
|
*/
|
||||||
|
strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
|
||||||
|
if (ioctl(fd, SIOCGIFFLAGS, (char *)&ifr, sizeof(ifr)) < 0) {
|
||||||
|
if (errno == ENXIO)
|
||||||
|
continue;
|
||||||
|
(void)sprintf(errbuf, "SIOCGIFFLAGS: %.*s: %s",
|
||||||
|
(int)sizeof(ifr.ifr_name), ifr.ifr_name,
|
||||||
|
strerror(errno));
|
||||||
|
(void)close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Must be up */
|
||||||
|
if ((ifr.ifr_flags & IFF_UP) == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
/* don't use loopback */
|
||||||
|
if ((ifr.ifr_flags & IFF_LOOPBACK) != 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
(void)strncpy(device, ifr.ifr_name, sizeof(ifr.ifr_name));
|
||||||
|
device[sizeof(device) - 1] = '\0';
|
||||||
|
#ifdef sun
|
||||||
|
/* Ignore sun virtual interfaces */
|
||||||
|
if (strchr(device, ':') != NULL)
|
||||||
|
continue;
|
||||||
|
#endif
|
||||||
|
if (ioctl(fd, SIOCGIFADDR, (char *)&ifr, sizeof(ifr)) < 0) {
|
||||||
|
(void)sprintf(errbuf, "SIOCGIFADDR: %s: %s",
|
||||||
|
device, strerror(errno));
|
||||||
|
(void)close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nipaddr >= MAX_IPADDR) {
|
||||||
|
(void)sprintf(errbuf, "Too many interfaces (%d)",
|
||||||
|
MAX_IPADDR);
|
||||||
|
(void)close(fd);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
sin = (struct sockaddr_in *)&ifr.ifr_addr;
|
||||||
|
al->addr = sin->sin_addr.s_addr;
|
||||||
|
al->device = strdup(device);
|
||||||
|
++al;
|
||||||
|
++nipaddr;
|
||||||
|
}
|
||||||
|
(void)close(fd);
|
||||||
|
|
||||||
|
*ipaddrp = ifaddrlist;
|
||||||
|
return (nipaddr);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1997
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the University of California,
|
||||||
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* @(#) $Header: traceroute.h,v 1.1 97/01/04 19:33:33 leres Locked $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct ifaddrlist {
|
||||||
|
u_int32_t addr;
|
||||||
|
char *device;
|
||||||
|
};
|
||||||
|
|
||||||
|
int ifaddrlist(struct ifaddrlist **, char *);
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2000
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that: (1) source code distributions
|
||||||
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
||||||
|
* distributions including binary code include the above copyright notice and
|
||||||
|
* this paragraph in its entirety in the documentation or other materials
|
||||||
|
* provided with the distribution, and (3) all advertising materials mentioning
|
||||||
|
* features or use of this software display the following acknowledgement:
|
||||||
|
* ``This product includes software developed by the University of California,
|
||||||
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
||||||
|
* the University nor the names of its contributors may be used to endorse
|
||||||
|
* or promote products derived from this software without specific prior
|
||||||
|
* written permission.
|
||||||
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* @(#) $Id: traceroute.h,v 1.1 2000/11/23 20:06:54 leres Exp $ (LBL)
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern char *prog;
|
||||||
|
|
||||||
|
void setsin(struct sockaddr_in *, u_int32_t);
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
char version[] = "1.4a12";
|
||||||
Reference in New Issue
Block a user