1998-09-06 21:51:32 +04:00
|
|
|
/* $NetBSD: ifconfig.c,v 1.49 1998/09/06 17:51:32 christos Exp $ */
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 03:35:17 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1997-03-17 06:08:46 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-08-06 03:35:17 +04:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
|
|
|
|
* NASA Ames Research Center.
|
|
|
|
*
|
1997-03-17 06:08:46 +03:00
|
|
|
* 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:
|
1998-08-06 03:35:17 +04:00
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
1997-03-17 06:08:46 +03:00
|
|
|
*
|
1998-08-06 03:35:17 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
1997-03-17 06:08:46 +03:00
|
|
|
*/
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-09-23 05:38:45 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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 University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. 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 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.
|
|
|
|
*/
|
|
|
|
|
1997-09-15 05:53:35 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-09-15 05:53:35 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
|
|
|
|
#else
|
1998-09-06 21:51:32 +04:00
|
|
|
__RCSID("$NetBSD: ifconfig.c,v 1.49 1998/09/06 17:51:32 christos Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-26 04:46:49 +03:00
|
|
|
#include <net/if_dl.h>
|
1997-03-17 06:08:46 +03:00
|
|
|
#include <net/if_media.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
1997-04-03 06:07:58 +04:00
|
|
|
#include <netatalk/at.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define NSIP
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <netdb.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define EON
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/iso_var.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1994-09-23 05:38:45 +04:00
|
|
|
#include <unistd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
struct ifreq ifr, ridreq;
|
1997-05-05 10:32:11 +04:00
|
|
|
struct ifaliasreq addreq __attribute__((aligned(4)));
|
1993-03-21 12:45:37 +03:00
|
|
|
struct iso_aliasreq iso_addreq;
|
|
|
|
struct sockaddr_in netmask;
|
1997-04-03 06:07:58 +04:00
|
|
|
struct netrange at_nr; /* AppleTalk net range */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
char name[30];
|
1997-04-10 23:10:16 +04:00
|
|
|
int flags, metric, mtu, setaddr, setipdst, doalias;
|
1994-12-05 23:15:31 +03:00
|
|
|
int clearaddr, s;
|
1997-05-30 09:44:11 +04:00
|
|
|
int newaddr = -1;
|
1994-12-05 23:15:31 +03:00
|
|
|
int nsellength = 1;
|
1997-03-17 06:08:46 +03:00
|
|
|
int af;
|
1998-09-06 21:51:32 +04:00
|
|
|
int Aflag, aflag, dflag, mflag, lflag, uflag;
|
1997-09-08 09:26:08 +04:00
|
|
|
int reset_if_flags;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void notealias __P((char *, int));
|
|
|
|
void notrailers __P((char *, int));
|
|
|
|
void setifaddr __P((char *, int));
|
|
|
|
void setifdstaddr __P((char *, int));
|
|
|
|
void setifflags __P((char *, int));
|
1997-04-03 06:07:58 +04:00
|
|
|
void setifbroadaddr __P((char *, int));
|
|
|
|
void setifipdst __P((char *, int));
|
|
|
|
void setifmetric __P((char *, int));
|
1997-04-10 23:10:16 +04:00
|
|
|
void setifmtu __P((char *, int));
|
1997-04-03 06:07:58 +04:00
|
|
|
void setifnetmask __P((char *, int));
|
|
|
|
void setnsellength __P((char *, int));
|
|
|
|
void setsnpaoffset __P((char *, int));
|
|
|
|
void setatrange __P((char *, int));
|
|
|
|
void setatphase __P((char *, int));
|
|
|
|
void checkatrange __P ((struct sockaddr_at *));
|
|
|
|
void setmedia __P((char *, int));
|
|
|
|
void setmediaopt __P((char *, int));
|
|
|
|
void unsetmediaopt __P((char *, int));
|
1998-08-09 02:33:17 +04:00
|
|
|
void setmediainst __P((char *, int));
|
1997-04-03 06:07:58 +04:00
|
|
|
void fixnsel __P((struct sockaddr_iso *));
|
|
|
|
int main __P((int, char *[]));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/*
|
|
|
|
* Media stuff. Whenever a media command is first performed, the
|
|
|
|
* currently select media is grabbed for this interface. If `media'
|
|
|
|
* is given, the current media word is modifed. `mediaopt' commands
|
|
|
|
* only modify the set and clear words. They then operate on the
|
|
|
|
* current media word later.
|
|
|
|
*/
|
|
|
|
int media_current;
|
|
|
|
int mediaopt_set;
|
|
|
|
int mediaopt_clear;
|
|
|
|
|
1998-08-08 22:14:20 +04:00
|
|
|
int actions; /* Actions performed */
|
1998-08-08 05:30:18 +04:00
|
|
|
|
1998-08-08 22:14:20 +04:00
|
|
|
#define A_MEDIA 0x0001 /* media command */
|
|
|
|
#define A_MEDIAOPTSET 0x0002 /* mediaopt command */
|
|
|
|
#define A_MEDIAOPTCLR 0x0004 /* -mediaopt command */
|
|
|
|
#define A_MEDIAOPT (A_MEDIAOPTSET|A_MEDIAOPTCLR)
|
1998-08-09 02:33:17 +04:00
|
|
|
#define A_MEDIAINST 0x0008 /* instance or inst command */
|
1998-08-08 05:30:18 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define NEXTARG 0xffffff
|
|
|
|
|
|
|
|
struct cmd {
|
|
|
|
char *c_name;
|
|
|
|
int c_parameter; /* NEXTARG means next argv */
|
1998-08-08 22:14:20 +04:00
|
|
|
int c_action; /* defered action */
|
1997-04-03 06:07:58 +04:00
|
|
|
void (*c_func) __P((char *, int));
|
1993-03-21 12:45:37 +03:00
|
|
|
} cmds[] = {
|
1998-08-08 05:30:18 +04:00
|
|
|
{ "up", IFF_UP, 0, setifflags } ,
|
|
|
|
{ "down", -IFF_UP, 0, setifflags },
|
|
|
|
{ "trailers", -1, 0, notrailers },
|
|
|
|
{ "-trailers", 1, 0, notrailers },
|
|
|
|
{ "arp", -IFF_NOARP, 0, setifflags },
|
|
|
|
{ "-arp", IFF_NOARP, 0, setifflags },
|
|
|
|
{ "debug", IFF_DEBUG, 0, setifflags },
|
|
|
|
{ "-debug", -IFF_DEBUG, 0, setifflags },
|
|
|
|
{ "alias", IFF_UP, 0, notealias },
|
|
|
|
{ "-alias", -IFF_UP, 0, notealias },
|
|
|
|
{ "delete", -IFF_UP, 0, notealias },
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef notdef
|
|
|
|
#define EN_SWABIPS 0x1000
|
1998-08-08 05:30:18 +04:00
|
|
|
{ "swabips", EN_SWABIPS, 0, setifflags },
|
|
|
|
{ "-swabips", -EN_SWABIPS, 0, setifflags },
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
1998-08-08 05:30:18 +04:00
|
|
|
{ "netmask", NEXTARG, 0, setifnetmask },
|
|
|
|
{ "metric", NEXTARG, 0, setifmetric },
|
|
|
|
{ "mtu", NEXTARG, 0, setifmtu },
|
|
|
|
{ "broadcast", NEXTARG, 0, setifbroadaddr },
|
|
|
|
{ "ipdst", NEXTARG, 0, setifipdst },
|
1995-10-09 02:03:54 +03:00
|
|
|
#ifndef INET_ONLY
|
1998-08-08 05:30:18 +04:00
|
|
|
{ "range", NEXTARG, 0, setatrange },
|
|
|
|
{ "phase", NEXTARG, 0, setatphase },
|
|
|
|
{ "snpaoffset", NEXTARG, 0, setsnpaoffset },
|
|
|
|
{ "nsellength", NEXTARG, 0, setnsellength },
|
1995-10-09 02:03:54 +03:00
|
|
|
#endif /* INET_ONLY */
|
1998-08-08 05:30:18 +04:00
|
|
|
{ "link0", IFF_LINK0, 0, setifflags } ,
|
|
|
|
{ "-link0", -IFF_LINK0, 0, setifflags } ,
|
|
|
|
{ "link1", IFF_LINK1, 0, setifflags } ,
|
|
|
|
{ "-link1", -IFF_LINK1, 0, setifflags } ,
|
|
|
|
{ "link2", IFF_LINK2, 0, setifflags } ,
|
|
|
|
{ "-link2", -IFF_LINK2, 0, setifflags } ,
|
1998-08-08 22:14:20 +04:00
|
|
|
{ "media", NEXTARG, A_MEDIA, setmedia },
|
|
|
|
{ "mediaopt", NEXTARG, A_MEDIAOPTSET, setmediaopt },
|
|
|
|
{ "-mediaopt", NEXTARG, A_MEDIAOPTCLR, unsetmediaopt },
|
1998-08-09 02:33:17 +04:00
|
|
|
{ "instance", NEXTARG, A_MEDIAINST, setmediainst },
|
|
|
|
{ "inst", NEXTARG, A_MEDIAINST, setmediainst },
|
1998-08-08 05:30:18 +04:00
|
|
|
{ 0, 0, 0, setifaddr },
|
|
|
|
{ 0, 0, 0, setifdstaddr },
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1997-04-03 06:07:58 +04:00
|
|
|
void adjust_nsellength __P((void));
|
1994-12-05 23:15:31 +03:00
|
|
|
int getinfo __P((struct ifreq *));
|
|
|
|
void getsock __P((int));
|
|
|
|
void printall __P((void));
|
1998-09-06 21:51:32 +04:00
|
|
|
void printalias __P((const char *));
|
1994-12-05 23:15:31 +03:00
|
|
|
void printb __P((char *, unsigned short, char *));
|
1997-03-26 04:46:49 +03:00
|
|
|
void status __P((const u_int8_t *, int));
|
1997-04-03 06:07:58 +04:00
|
|
|
void usage __P((void));
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
const char *get_media_type_string __P((int));
|
|
|
|
const char *get_media_subtype_string __P((int));
|
|
|
|
int get_media_subtype __P((int, const char *));
|
|
|
|
int get_media_options __P((int, const char *));
|
|
|
|
int lookup_media_word __P((struct ifmedia_description *, int,
|
|
|
|
const char *));
|
1998-08-06 23:22:00 +04:00
|
|
|
void print_media_word __P((int, int, int));
|
1998-08-08 05:30:18 +04:00
|
|
|
void process_media_commands __P((void));
|
|
|
|
void init_current_media __P((void));
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-09-23 05:38:45 +04:00
|
|
|
* XNS support liberally adapted from code written at the University of
|
|
|
|
* Maryland principally by James O'Toole and Chris Torek.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1998-09-06 21:51:32 +04:00
|
|
|
void in_alias __P((struct ifreq *));
|
1994-12-05 23:15:31 +03:00
|
|
|
void in_status __P((int));
|
|
|
|
void in_getaddr __P((char *, int));
|
1997-04-03 06:07:58 +04:00
|
|
|
void at_status __P((int));
|
|
|
|
void at_getaddr __P((char *, int));
|
1994-12-05 23:15:31 +03:00
|
|
|
void xns_status __P((int));
|
|
|
|
void xns_getaddr __P((char *, int));
|
|
|
|
void iso_status __P((int));
|
|
|
|
void iso_getaddr __P((char *, int));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/* Known address families */
|
|
|
|
struct afswtch {
|
|
|
|
char *af_name;
|
|
|
|
short af_af;
|
1997-04-03 06:07:58 +04:00
|
|
|
void (*af_status) __P((int));
|
|
|
|
void (*af_getaddr) __P((char *, int));
|
1994-10-31 07:24:09 +03:00
|
|
|
u_long af_difaddr;
|
|
|
|
u_long af_aifaddr;
|
1993-03-21 12:45:37 +03:00
|
|
|
caddr_t af_ridreq;
|
|
|
|
caddr_t af_addreq;
|
|
|
|
} afs[] = {
|
|
|
|
#define C(x) ((caddr_t) &x)
|
|
|
|
{ "inet", AF_INET, in_status, in_getaddr,
|
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
|
1995-10-09 02:03:54 +03:00
|
|
|
#ifndef INET_ONLY /* small version, for boot media */
|
1997-04-03 06:07:58 +04:00
|
|
|
{ "atalk", AF_APPLETALK, at_status, at_getaddr,
|
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(addreq), C(addreq) },
|
1993-03-21 12:45:37 +03:00
|
|
|
{ "ns", AF_NS, xns_status, xns_getaddr,
|
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
|
|
|
|
{ "iso", AF_ISO, iso_status, iso_getaddr,
|
1996-09-08 18:37:39 +04:00
|
|
|
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(iso_addreq) },
|
1995-10-09 02:03:54 +03:00
|
|
|
#endif /* INET_ONLY */
|
1993-03-21 12:45:37 +03:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct afswtch *afp; /*the address family being set or asked about*/
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
struct afswtch *lookup_af __P((const char *));
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
1998-09-06 21:51:32 +04:00
|
|
|
int ch;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* Parse command-line options */
|
|
|
|
aflag = mflag = 0;
|
1998-09-06 21:51:32 +04:00
|
|
|
while ((ch = getopt(argc, argv, "Aadlmu")) != -1) {
|
1997-03-17 06:08:46 +03:00
|
|
|
switch (ch) {
|
1998-09-06 21:51:32 +04:00
|
|
|
case 'A':
|
|
|
|
Aflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
case 'a':
|
|
|
|
aflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-04-21 05:17:57 +04:00
|
|
|
case 'd':
|
|
|
|
dflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-03-28 01:50:09 +03:00
|
|
|
case 'l':
|
|
|
|
lflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
case 'm':
|
|
|
|
mflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-04-21 05:17:57 +04:00
|
|
|
case 'u':
|
|
|
|
uflag = 1;
|
|
|
|
break;
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1997-03-28 01:50:09 +03:00
|
|
|
/*
|
|
|
|
* -l means "list all interfaces", and is mutally exclusive with
|
|
|
|
* all other flags/commands.
|
|
|
|
*
|
|
|
|
* -a means "print status of all interfaces".
|
|
|
|
*/
|
|
|
|
if (lflag && (aflag || mflag || argc))
|
|
|
|
usage();
|
|
|
|
if (aflag || lflag) {
|
1997-03-17 06:08:46 +03:00
|
|
|
if (argc > 1)
|
1995-01-22 00:22:16 +03:00
|
|
|
usage();
|
1997-03-17 06:08:46 +03:00
|
|
|
else if (argc == 1) {
|
|
|
|
afp = lookup_af(argv[0]);
|
|
|
|
if (afp == NULL)
|
|
|
|
usage();
|
1997-04-03 06:07:58 +04:00
|
|
|
}
|
|
|
|
if (afp)
|
|
|
|
af = ifr.ifr_addr.sa_family = afp->af_af;
|
|
|
|
else
|
|
|
|
af = ifr.ifr_addr.sa_family = afs[0].af_af;
|
1994-09-23 05:38:45 +04:00
|
|
|
printall();
|
1993-05-04 13:26:52 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* Make sure there's an interface name. */
|
|
|
|
if (argc < 1)
|
|
|
|
usage();
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(name, argv[0], sizeof(name));
|
1997-03-17 06:08:46 +03:00
|
|
|
argc--; argv++;
|
|
|
|
|
|
|
|
/* Check for address family. */
|
|
|
|
afp = NULL;
|
|
|
|
if (argc > 0) {
|
|
|
|
afp = lookup_af(argv[0]);
|
|
|
|
if (afp != NULL) {
|
|
|
|
argv++;
|
|
|
|
argc--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (afp == NULL)
|
|
|
|
afp = afs;
|
|
|
|
af = ifr.ifr_addr.sa_family = afp->af_af;
|
|
|
|
|
|
|
|
/* Get information about the interface. */
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1994-09-23 05:38:45 +04:00
|
|
|
if (getinfo(&ifr) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(1);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* No more arguments means interface status. */
|
1994-09-23 05:38:45 +04:00
|
|
|
if (argc == 0) {
|
1997-03-26 04:46:49 +03:00
|
|
|
status(NULL, 0);
|
1993-05-04 13:26:52 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* Process commands. */
|
1993-03-21 12:45:37 +03:00
|
|
|
while (argc > 0) {
|
1997-09-15 05:53:35 +04:00
|
|
|
struct cmd *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (p = cmds; p->c_name; p++)
|
1997-03-17 06:08:46 +03:00
|
|
|
if (strcmp(argv[0], p->c_name) == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
if (p->c_name == 0 && setaddr)
|
|
|
|
p++; /* got src, do dst */
|
|
|
|
if (p->c_func) {
|
|
|
|
if (p->c_parameter == NEXTARG) {
|
1997-03-17 06:08:46 +03:00
|
|
|
if (argc < 2)
|
1994-01-22 05:04:35 +03:00
|
|
|
errx(1, "'%s' requires argument",
|
|
|
|
p->c_name);
|
1997-04-03 06:07:58 +04:00
|
|
|
(*p->c_func)(argv[1], 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
argc--, argv++;
|
|
|
|
} else
|
1997-03-17 06:08:46 +03:00
|
|
|
(*p->c_func)(argv[0], p->c_parameter);
|
1998-08-08 22:14:20 +04:00
|
|
|
actions |= p->c_action;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
argc--, argv++;
|
|
|
|
}
|
1995-10-09 02:03:54 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Process any media commands that may have been issued. */
|
|
|
|
process_media_commands();
|
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
#ifndef INET_ONLY
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (af == AF_ISO)
|
|
|
|
adjust_nsellength();
|
1997-04-03 06:07:58 +04:00
|
|
|
|
|
|
|
if (af == AF_APPLETALK)
|
|
|
|
checkatrange((struct sockaddr_at *) &addreq.ifra_addr);
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (setipdst && af==AF_NS) {
|
|
|
|
struct nsip_req rq;
|
|
|
|
int size = sizeof(rq);
|
|
|
|
|
|
|
|
rq.rq_ns = addreq.ifra_addr;
|
|
|
|
rq.rq_ip = addreq.ifra_dstaddr;
|
|
|
|
|
|
|
|
if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0)
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("encapsulation routing");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1995-10-09 02:03:54 +03:00
|
|
|
|
|
|
|
#endif /* INET_ONLY */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (clearaddr) {
|
|
|
|
int ret;
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(afp->af_ridreq, name, sizeof ifr.ifr_name);
|
1997-03-17 06:08:46 +03:00
|
|
|
if ((ret = ioctl(s, afp->af_difaddr, afp->af_ridreq)) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL && (doalias >= 0)) {
|
|
|
|
/* means no previous address for interface */
|
|
|
|
} else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCDIFADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
1997-05-30 09:44:11 +04:00
|
|
|
if (newaddr > 0) {
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(afp->af_addreq, name, sizeof ifr.ifr_name);
|
1997-03-17 06:08:46 +03:00
|
|
|
if (ioctl(s, afp->af_aifaddr, afp->af_addreq) < 0)
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCAIFADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-09-08 09:26:08 +04:00
|
|
|
if (reset_if_flags && ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
|
|
|
|
err(1, "SIOCSIFFLAGS");
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(0);
|
|
|
|
}
|
1993-05-04 13:26:52 +04:00
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
struct afswtch *
|
|
|
|
lookup_af(cp)
|
|
|
|
const char *cp;
|
|
|
|
{
|
|
|
|
struct afswtch *a;
|
|
|
|
|
|
|
|
for (a = afs; a->af_name != NULL; a++)
|
|
|
|
if (strcmp(a->af_name, cp) == 0)
|
|
|
|
return (a);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
void
|
|
|
|
getsock(naf)
|
|
|
|
int naf;
|
|
|
|
{
|
|
|
|
static int oaf = -1;
|
|
|
|
|
|
|
|
if (oaf == naf)
|
|
|
|
return;
|
|
|
|
if (oaf != -1)
|
|
|
|
close(s);
|
|
|
|
s = socket(naf, SOCK_DGRAM, 0);
|
|
|
|
if (s < 0)
|
|
|
|
oaf = -1;
|
|
|
|
else
|
|
|
|
oaf = naf;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
getinfo(ifr)
|
|
|
|
struct ifreq *ifr;
|
|
|
|
{
|
|
|
|
|
|
|
|
getsock(af);
|
|
|
|
if (s < 0)
|
|
|
|
err(1, "socket");
|
|
|
|
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)ifr) < 0) {
|
1997-04-03 06:07:58 +04:00
|
|
|
warn("SIOCGIFFLAGS %s", ifr->ifr_name);
|
1994-09-23 05:38:45 +04:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
flags = ifr->ifr_flags;
|
|
|
|
if (ioctl(s, SIOCGIFMETRIC, (caddr_t)ifr) < 0) {
|
1997-04-03 06:07:58 +04:00
|
|
|
warn("SIOCGIFMETRIC %s", ifr->ifr_name);
|
1994-09-23 05:38:45 +04:00
|
|
|
metric = 0;
|
|
|
|
} else
|
|
|
|
metric = ifr->ifr_metric;
|
1997-04-10 23:10:16 +04:00
|
|
|
if (ioctl(s, SIOCGIFMTU, (caddr_t)ifr) < 0)
|
|
|
|
mtu = 0;
|
|
|
|
else
|
1997-07-14 16:54:27 +04:00
|
|
|
mtu = ifr->ifr_mtu;
|
1994-09-23 05:38:45 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-09-06 21:51:32 +04:00
|
|
|
void
|
|
|
|
printalias(iname)
|
|
|
|
const char *iname;
|
|
|
|
{
|
|
|
|
char inbuf[8192];
|
|
|
|
struct ifconf ifc;
|
|
|
|
struct ifreq *ifr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ifc.ifc_len = sizeof(inbuf);
|
|
|
|
ifc.ifc_buf = inbuf;
|
|
|
|
getsock(af);
|
|
|
|
if (s < 0)
|
|
|
|
err(1, "socket");
|
|
|
|
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
|
|
|
|
err(1, "SIOCGIFCONF");
|
|
|
|
ifr = ifc.ifc_req;
|
|
|
|
for (i = 0; i < ifc.ifc_len; ) {
|
|
|
|
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
|
|
|
|
i += sizeof(ifr->ifr_name) +
|
|
|
|
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
|
|
|
|
? ifr->ifr_addr.sa_len
|
|
|
|
: sizeof(struct sockaddr));
|
|
|
|
if (!strncmp(iname, ifr->ifr_name, sizeof(ifr->ifr_name))) {
|
|
|
|
if (ifr->ifr_addr.sa_family == AF_INET)
|
|
|
|
in_alias(ifr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
void
|
1993-05-04 13:26:52 +04:00
|
|
|
printall()
|
|
|
|
{
|
|
|
|
char inbuf[8192];
|
1997-03-26 04:46:49 +03:00
|
|
|
const struct sockaddr_dl *sdl = NULL;
|
1993-05-04 13:26:52 +04:00
|
|
|
struct ifconf ifc;
|
|
|
|
struct ifreq ifreq, *ifr;
|
1997-03-28 01:50:09 +03:00
|
|
|
int i, idx;
|
1993-05-04 13:26:52 +04:00
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
ifc.ifc_len = sizeof(inbuf);
|
1993-05-04 13:26:52 +04:00
|
|
|
ifc.ifc_buf = inbuf;
|
1994-09-23 05:38:45 +04:00
|
|
|
getsock(af);
|
|
|
|
if (s < 0)
|
|
|
|
err(1, "socket");
|
|
|
|
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
|
|
|
|
err(1, "SIOCGIFCONF");
|
1993-05-04 13:26:52 +04:00
|
|
|
ifr = ifc.ifc_req;
|
|
|
|
ifreq.ifr_name[0] = '\0';
|
1997-04-21 05:17:57 +04:00
|
|
|
for (i = 0, idx = 0; i < ifc.ifc_len; ) {
|
1994-09-23 05:38:45 +04:00
|
|
|
ifr = (struct ifreq *)((caddr_t)ifc.ifc_req + i);
|
1996-01-04 23:11:20 +03:00
|
|
|
i += sizeof(ifr->ifr_name) +
|
|
|
|
(ifr->ifr_addr.sa_len > sizeof(struct sockaddr)
|
|
|
|
? ifr->ifr_addr.sa_len
|
|
|
|
: sizeof(struct sockaddr));
|
1997-03-26 04:46:49 +03:00
|
|
|
if (ifr->ifr_addr.sa_family == AF_LINK)
|
|
|
|
sdl = (const struct sockaddr_dl *) &ifr->ifr_addr;
|
1994-09-23 05:38:45 +04:00
|
|
|
if (!strncmp(ifreq.ifr_name, ifr->ifr_name,
|
1998-09-06 21:51:32 +04:00
|
|
|
sizeof(ifr->ifr_name))) {
|
|
|
|
if (Aflag && ifr->ifr_addr.sa_family == AF_INET)
|
|
|
|
in_alias(ifr);
|
1994-09-23 05:38:45 +04:00
|
|
|
continue;
|
1998-09-06 21:51:32 +04:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(name, ifr->ifr_name, sizeof(ifr->ifr_name));
|
1993-05-04 13:26:52 +04:00
|
|
|
ifreq = *ifr;
|
1997-03-28 01:50:09 +03:00
|
|
|
|
1997-04-21 05:17:57 +04:00
|
|
|
if (getinfo(&ifreq) < 0)
|
|
|
|
continue;
|
|
|
|
if (dflag && (flags & IFF_UP) != 0)
|
|
|
|
continue;
|
|
|
|
if (uflag && (flags & IFF_UP) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
idx++;
|
1997-03-28 01:50:09 +03:00
|
|
|
/*
|
|
|
|
* Are we just listing the interfaces?
|
|
|
|
*/
|
|
|
|
if (lflag) {
|
1997-04-21 05:17:57 +04:00
|
|
|
if (idx > 1)
|
1997-03-28 01:50:09 +03:00
|
|
|
putchar(' ');
|
1997-04-21 05:17:57 +04:00
|
|
|
fputs(name, stdout);
|
1997-03-28 01:50:09 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1997-03-26 04:46:49 +03:00
|
|
|
if (sdl == NULL) {
|
|
|
|
status(NULL, 0);
|
|
|
|
} else {
|
|
|
|
status(LLADDR(sdl), sdl->sdl_alen);
|
|
|
|
sdl = NULL;
|
|
|
|
}
|
1993-05-04 13:26:52 +04:00
|
|
|
}
|
1997-03-28 01:50:09 +03:00
|
|
|
if (lflag)
|
|
|
|
putchar('\n');
|
1993-05-04 13:26:52 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define RIDADDR 0
|
|
|
|
#define ADDR 1
|
|
|
|
#define MASK 2
|
|
|
|
#define DSTADDR 3
|
|
|
|
|
|
|
|
/*ARGSUSED*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
setifaddr(addr, param)
|
|
|
|
char *addr;
|
1994-12-05 23:15:31 +03:00
|
|
|
int param;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Delay the ioctl to set the interface addr until flags are all set.
|
|
|
|
* The address interpretation may depend on the flags,
|
|
|
|
* and the flags may change when the address is set.
|
|
|
|
*/
|
|
|
|
setaddr++;
|
1997-05-30 09:44:11 +04:00
|
|
|
if (newaddr == -1)
|
|
|
|
newaddr = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (doalias == 0)
|
|
|
|
clearaddr = 1;
|
|
|
|
(*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR));
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setifnetmask(addr, d)
|
1993-03-21 12:45:37 +03:00
|
|
|
char *addr;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
(*afp->af_getaddr)(addr, MASK);
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setifbroadaddr(addr, d)
|
1993-03-21 12:45:37 +03:00
|
|
|
char *addr;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
(*afp->af_getaddr)(addr, DSTADDR);
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setifipdst(addr, d)
|
1993-03-21 12:45:37 +03:00
|
|
|
char *addr;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
in_getaddr(addr, DSTADDR);
|
|
|
|
setipdst++;
|
|
|
|
clearaddr = 0;
|
|
|
|
newaddr = 0;
|
|
|
|
}
|
1994-12-05 23:15:31 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))
|
|
|
|
/*ARGSUSED*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
notealias(addr, param)
|
|
|
|
char *addr;
|
1994-12-05 23:15:31 +03:00
|
|
|
int param;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (setaddr && doalias == 0 && param < 0)
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memcpy(rqtosa(af_ridreq), rqtosa(af_addreq),
|
|
|
|
rqtosa(af_addreq)->sa_len);
|
1993-03-21 12:45:37 +03:00
|
|
|
doalias = param;
|
|
|
|
if (param < 0) {
|
|
|
|
clearaddr = 1;
|
|
|
|
newaddr = 0;
|
|
|
|
} else
|
|
|
|
clearaddr = 0;
|
|
|
|
}
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
/*ARGSUSED*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1994-09-23 05:38:45 +04:00
|
|
|
notrailers(vname, value)
|
|
|
|
char *vname;
|
|
|
|
int value;
|
|
|
|
{
|
1997-04-21 05:17:57 +04:00
|
|
|
puts("Note: trailers are no longer sent, but always received");
|
1994-09-23 05:38:45 +04:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*ARGSUSED*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
setifdstaddr(addr, param)
|
|
|
|
char *addr;
|
|
|
|
int param;
|
|
|
|
{
|
|
|
|
(*afp->af_getaddr)(addr, DSTADDR);
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
setifflags(vname, value)
|
|
|
|
char *vname;
|
1994-12-05 23:15:31 +03:00
|
|
|
int value;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0)
|
|
|
|
err(1, "SIOCGIFFLAGS");
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
flags = ifr.ifr_flags;
|
|
|
|
|
|
|
|
if (value < 0) {
|
|
|
|
value = -value;
|
|
|
|
flags &= ~value;
|
|
|
|
} else
|
|
|
|
flags |= value;
|
|
|
|
ifr.ifr_flags = flags;
|
|
|
|
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
|
1994-09-23 05:38:45 +04:00
|
|
|
err(1, "SIOCSIFFLAGS");
|
1997-09-08 09:26:08 +04:00
|
|
|
|
|
|
|
reset_if_flags = 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setifmetric(val, d)
|
1993-03-21 12:45:37 +03:00
|
|
|
char *val;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
ifr.ifr_metric = atoi(val);
|
|
|
|
if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCSIFMETRIC");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-04-10 23:10:16 +04:00
|
|
|
void
|
|
|
|
setifmtu(val, d)
|
|
|
|
char *val;
|
|
|
|
int d;
|
|
|
|
{
|
|
|
|
(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1997-07-14 16:54:27 +04:00
|
|
|
ifr.ifr_mtu = atoi(val);
|
1997-04-10 23:10:16 +04:00
|
|
|
if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)
|
|
|
|
warn("SIOCSIFMTU");
|
|
|
|
}
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
void
|
1998-08-08 05:30:18 +04:00
|
|
|
init_current_media()
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
|
|
|
struct ifmediareq ifmr;
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/*
|
|
|
|
* If we have not yet done so, grab the currently-selected
|
|
|
|
* media.
|
|
|
|
*/
|
1998-08-08 22:14:20 +04:00
|
|
|
if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {
|
1998-08-08 05:30:18 +04:00
|
|
|
(void) memset(&ifmr, 0, sizeof(ifmr));
|
|
|
|
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
|
|
|
|
/*
|
|
|
|
* If we get E2BIG, the kernel is telling us
|
|
|
|
* that there are more, so we can ignore it.
|
|
|
|
*/
|
|
|
|
if (errno != E2BIG)
|
|
|
|
err(1, "SGIOCGIFMEDIA");
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
media_current = ifmr.ifm_current;
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Sanity. */
|
|
|
|
if (IFM_TYPE(media_current) == 0)
|
|
|
|
errx(1, "%s: no link type?", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
process_media_commands()
|
|
|
|
{
|
|
|
|
|
1998-08-08 22:14:20 +04:00
|
|
|
if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Nothing to do. */
|
|
|
|
return;
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/*
|
1998-08-08 05:30:18 +04:00
|
|
|
* Media already set up, and commands sanity-checked. Set/clear
|
|
|
|
* any options, and we're ready to go.
|
1997-03-17 06:08:46 +03:00
|
|
|
*/
|
1998-08-08 05:30:18 +04:00
|
|
|
media_current |= mediaopt_set;
|
|
|
|
media_current &= ~mediaopt_clear;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1998-08-08 05:30:18 +04:00
|
|
|
ifr.ifr_media = media_current;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)
|
|
|
|
err(1, "SIOCSIFMEDIA");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-08 05:30:18 +04:00
|
|
|
setmedia(val, d)
|
1997-03-17 06:08:46 +03:00
|
|
|
char *val;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
1998-08-08 05:30:18 +04:00
|
|
|
int type, subtype, inst;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
init_current_media();
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Only one media command may be given. */
|
1998-08-08 22:14:20 +04:00
|
|
|
if (actions & A_MEDIA)
|
1998-08-08 05:30:18 +04:00
|
|
|
errx(1, "only one `media' command may be issued");
|
|
|
|
|
|
|
|
/* Must not come after mediaopt commands */
|
1998-08-08 22:14:20 +04:00
|
|
|
if (actions & A_MEDIAOPT)
|
1998-08-08 05:30:18 +04:00
|
|
|
errx(1, "may not issue `media' after `mediaopt' commands");
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-09 02:33:17 +04:00
|
|
|
/*
|
|
|
|
* No need to check if `instance' has been issued; setmediainst()
|
|
|
|
* craps out if `media' has not been specified.
|
|
|
|
*/
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
type = IFM_TYPE(media_current);
|
|
|
|
inst = IFM_INST(media_current);
|
|
|
|
|
|
|
|
/* Look up the subtype. */
|
|
|
|
subtype = get_media_subtype(type, val);
|
|
|
|
|
|
|
|
/* Build the new current media word. */
|
|
|
|
media_current = IFM_MAKEWORD(type, subtype, 0, inst);
|
|
|
|
|
|
|
|
/* Media will be set after other processing is complete. */
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-08 05:30:18 +04:00
|
|
|
setmediaopt(val, d)
|
1997-03-17 06:08:46 +03:00
|
|
|
char *val;
|
1998-08-08 05:30:18 +04:00
|
|
|
int d;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
init_current_media();
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Can only issue `mediaopt' once. */
|
1998-08-08 22:14:20 +04:00
|
|
|
if (actions & A_MEDIAOPTSET)
|
1998-08-08 05:30:18 +04:00
|
|
|
errx(1, "only one `mediaopt' command may be issued");
|
1997-03-18 04:50:01 +03:00
|
|
|
|
1998-08-09 02:33:17 +04:00
|
|
|
/* Can't issue `mediaopt' if `instance' has already been issued. */
|
|
|
|
if (actions & A_MEDIAINST)
|
|
|
|
errx(1, "may not issue `mediaopt' after `instance'");
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
mediaopt_set = get_media_options(IFM_TYPE(media_current), val);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Media will be set after other processing is complete. */
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
void
|
|
|
|
unsetmediaopt(val, d)
|
|
|
|
char *val;
|
|
|
|
int d;
|
|
|
|
{
|
1997-03-18 04:50:01 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
init_current_media();
|
1997-03-18 04:50:01 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Can only issue `-mediaopt' once. */
|
1998-08-08 22:14:20 +04:00
|
|
|
if (actions & A_MEDIAOPTCLR)
|
1998-08-08 05:30:18 +04:00
|
|
|
errx(1, "only one `-mediaopt' command may be issued");
|
1997-03-18 04:50:01 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* May not issue `media' and `-mediaopt'. */
|
1998-08-08 22:14:20 +04:00
|
|
|
if (actions & A_MEDIA)
|
1998-08-08 05:30:18 +04:00
|
|
|
errx(1, "may not issue both `media' and `-mediaopt'");
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-09 02:33:17 +04:00
|
|
|
/*
|
|
|
|
* No need to check for A_MEDIAINST, since the test for A_MEDIA
|
|
|
|
* implicitly checks for A_MEDIAINST.
|
|
|
|
*/
|
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
mediaopt_clear = get_media_options(IFM_TYPE(media_current), val);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-08 05:30:18 +04:00
|
|
|
/* Media will be set after other processing is complete. */
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
1998-08-09 02:33:17 +04:00
|
|
|
void
|
|
|
|
setmediainst(val, d)
|
|
|
|
char *val;
|
|
|
|
int d;
|
|
|
|
{
|
|
|
|
int type, subtype, options, inst;
|
|
|
|
|
|
|
|
init_current_media();
|
|
|
|
|
|
|
|
/* Can only issue `instance' once. */
|
|
|
|
if (actions & A_MEDIAINST)
|
|
|
|
errx(1, "only one `instance' command may be issued");
|
|
|
|
|
|
|
|
/* Must have already specified `media' */
|
|
|
|
if ((actions & A_MEDIA) == 0)
|
|
|
|
errx(1, "must specify `media' before `instance'");
|
|
|
|
|
|
|
|
type = IFM_TYPE(media_current);
|
|
|
|
subtype = IFM_SUBTYPE(media_current);
|
|
|
|
options = IFM_OPTIONS(media_current);
|
|
|
|
|
|
|
|
inst = atoi(val);
|
|
|
|
if (inst < 0 || inst > IFM_INST_MAX)
|
|
|
|
errx(1, "invalid media instance: %s", val);
|
|
|
|
|
|
|
|
media_current = IFM_MAKEWORD(type, subtype, options, inst);
|
|
|
|
|
|
|
|
/* Media will be set after other processing is complete. */
|
|
|
|
}
|
|
|
|
|
1997-03-17 06:08:46 +03:00
|
|
|
struct ifmedia_description ifm_type_descriptions[] =
|
|
|
|
IFM_TYPE_DESCRIPTIONS;
|
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
struct ifmedia_description ifm_subtype_descriptions[] =
|
|
|
|
IFM_SUBTYPE_DESCRIPTIONS;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
struct ifmedia_description ifm_option_descriptions[] =
|
|
|
|
IFM_OPTION_DESCRIPTIONS;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
const char *
|
|
|
|
get_media_type_string(mword)
|
|
|
|
int mword;
|
|
|
|
{
|
|
|
|
struct ifmedia_description *desc;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
for (desc = ifm_type_descriptions; desc->ifmt_string != NULL;
|
|
|
|
desc++) {
|
|
|
|
if (IFM_TYPE(mword) == desc->ifmt_word)
|
|
|
|
return (desc->ifmt_string);
|
|
|
|
}
|
|
|
|
return ("<unknown type>");
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
const char *
|
|
|
|
get_media_subtype_string(mword)
|
|
|
|
int mword;
|
|
|
|
{
|
|
|
|
struct ifmedia_description *desc;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
for (desc = ifm_subtype_descriptions; desc->ifmt_string != NULL;
|
|
|
|
desc++) {
|
|
|
|
if (IFM_TYPE_MATCH(desc->ifmt_word, mword) &&
|
|
|
|
IFM_SUBTYPE(desc->ifmt_word) == IFM_SUBTYPE(mword))
|
|
|
|
return (desc->ifmt_string);
|
|
|
|
}
|
|
|
|
return ("<unknown subtype>");
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
get_media_subtype(type, val)
|
|
|
|
int type;
|
1998-08-06 06:24:40 +04:00
|
|
|
const char *val;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
1998-08-06 06:24:40 +04:00
|
|
|
int rval;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
rval = lookup_media_word(ifm_subtype_descriptions, type, val);
|
|
|
|
if (rval == -1)
|
|
|
|
errx(1, "unknown %s media subtype: %s",
|
|
|
|
get_media_type_string(type), val);
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
return (rval);
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
get_media_options(type, val)
|
|
|
|
int type;
|
1998-08-06 06:24:40 +04:00
|
|
|
const char *val;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
1998-08-06 06:24:40 +04:00
|
|
|
char *optlist, *str;
|
|
|
|
int option, rval = 0;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* We muck with the string, so copy it. */
|
|
|
|
optlist = strdup(val);
|
|
|
|
if (optlist == NULL)
|
|
|
|
err(1, "strdup");
|
1998-08-06 06:24:40 +04:00
|
|
|
str = optlist;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/*
|
1998-08-06 06:24:40 +04:00
|
|
|
* Look up the options in the user-provided comma-separated list.
|
1997-03-17 06:08:46 +03:00
|
|
|
*/
|
1998-08-06 06:24:40 +04:00
|
|
|
for (; (str = strtok(str, ",")) != NULL; str = NULL) {
|
|
|
|
option = lookup_media_word(ifm_option_descriptions, type, str);
|
|
|
|
if (option == -1)
|
|
|
|
errx(1, "unknown %s media option: %s",
|
|
|
|
get_media_type_string(type), str);
|
1997-03-17 06:08:46 +03:00
|
|
|
rval |= option;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(optlist);
|
|
|
|
return (rval);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-08-06 06:24:40 +04:00
|
|
|
lookup_media_word(desc, type, val)
|
1997-03-17 06:08:46 +03:00
|
|
|
struct ifmedia_description *desc;
|
1998-08-06 06:24:40 +04:00
|
|
|
int type;
|
|
|
|
const char *val;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
for (; desc->ifmt_string != NULL; desc++) {
|
|
|
|
if (IFM_TYPE_MATCH(desc->ifmt_word, type) &&
|
|
|
|
strcasecmp(desc->ifmt_string, val) == 0)
|
1997-03-17 06:08:46 +03:00
|
|
|
return (desc->ifmt_word);
|
1998-08-06 06:24:40 +04:00
|
|
|
}
|
1997-03-18 08:04:50 +03:00
|
|
|
return (-1);
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-08-06 23:22:00 +04:00
|
|
|
print_media_word(ifmw, print_type, as_syntax)
|
|
|
|
int ifmw, print_type, as_syntax;
|
1997-03-17 06:08:46 +03:00
|
|
|
{
|
|
|
|
struct ifmedia_description *desc;
|
1998-08-06 06:24:40 +04:00
|
|
|
int seen_option = 0;
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1998-08-06 06:24:40 +04:00
|
|
|
if (print_type)
|
|
|
|
printf("%s ", get_media_type_string(ifmw));
|
1998-08-06 23:22:00 +04:00
|
|
|
printf("%s%s", as_syntax ? "media " : "",
|
|
|
|
get_media_subtype_string(ifmw));
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
/* Find options. */
|
1998-08-06 06:24:40 +04:00
|
|
|
for (desc = ifm_option_descriptions; desc->ifmt_string != NULL;
|
|
|
|
desc++) {
|
|
|
|
if (IFM_TYPE_MATCH(desc->ifmt_word, ifmw) &&
|
|
|
|
(ifmw & desc->ifmt_word) != 0 &&
|
|
|
|
(seen_option & IFM_OPTIONS(desc->ifmt_word)) == 0) {
|
|
|
|
if (seen_option == 0)
|
1998-08-06 23:22:00 +04:00
|
|
|
printf(" %s", as_syntax ? "mediaopt " : "");
|
1998-08-06 06:24:40 +04:00
|
|
|
printf("%s%s", seen_option ? "," : "",
|
|
|
|
desc->ifmt_string);
|
|
|
|
seen_option |= IFM_OPTIONS(desc->ifmt_word);
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
}
|
1998-08-06 07:47:28 +04:00
|
|
|
if (IFM_INST(ifmw) != 0)
|
1998-08-09 02:33:17 +04:00
|
|
|
printf(" instance %d", IFM_INST(ifmw));
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define IFFBITS \
|
1994-09-23 05:38:45 +04:00
|
|
|
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
|
|
|
|
\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Print the status of the interface. If an address family was
|
|
|
|
* specified, show it and it only; otherwise, show them all.
|
|
|
|
*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-03-26 04:46:49 +03:00
|
|
|
status(ap, alen)
|
|
|
|
const u_int8_t *ap;
|
|
|
|
int alen;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-09-15 05:53:35 +04:00
|
|
|
struct afswtch *p = afp;
|
1997-03-17 06:08:46 +03:00
|
|
|
struct ifmediareq ifmr;
|
|
|
|
int *media_list, i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
printf("%s: ", name);
|
|
|
|
printb("flags", flags, IFFBITS);
|
|
|
|
if (metric)
|
|
|
|
printf(" metric %d", metric);
|
1997-04-10 23:10:16 +04:00
|
|
|
if (mtu)
|
|
|
|
printf(" mtu %d", mtu);
|
1993-03-21 12:45:37 +03:00
|
|
|
putchar('\n');
|
1997-03-26 04:46:49 +03:00
|
|
|
if (ap && alen > 0) {
|
|
|
|
printf("\taddress:");
|
|
|
|
for (i = 0; i < alen; i++, ap++)
|
|
|
|
printf("%c%02x", i > 0 ? ':' : ' ', *ap);
|
|
|
|
putchar('\n');
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifmr, 0, sizeof(ifmr));
|
|
|
|
(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
|
|
|
|
/*
|
|
|
|
* Interface doesn't support SIOC{G,S}IFMEDIA.
|
|
|
|
*/
|
|
|
|
goto proto_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ifmr.ifm_count == 0) {
|
1997-03-25 04:37:11 +03:00
|
|
|
warnx("%s: no media types?", name);
|
1997-03-17 06:08:46 +03:00
|
|
|
goto proto_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
media_list = (int *)malloc(ifmr.ifm_count * sizeof(int));
|
|
|
|
if (media_list == NULL)
|
|
|
|
err(1, "malloc");
|
|
|
|
ifmr.ifm_ulist = media_list;
|
|
|
|
|
|
|
|
if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
|
|
|
|
err(1, "SIOCGIFMEDIA");
|
|
|
|
|
|
|
|
printf("\tmedia: ");
|
1998-08-06 23:22:00 +04:00
|
|
|
print_media_word(ifmr.ifm_current, 1, 0);
|
1997-03-17 06:08:46 +03:00
|
|
|
if (ifmr.ifm_active != ifmr.ifm_current) {
|
1997-03-24 03:45:30 +03:00
|
|
|
putchar(' ');
|
1997-03-17 06:08:46 +03:00
|
|
|
putchar('(');
|
1998-08-06 23:22:00 +04:00
|
|
|
print_media_word(ifmr.ifm_active, 0, 0);
|
1997-03-17 06:08:46 +03:00
|
|
|
putchar(')');
|
|
|
|
}
|
1998-08-06 06:24:40 +04:00
|
|
|
putchar('\n');
|
1997-03-17 06:08:46 +03:00
|
|
|
|
|
|
|
if (ifmr.ifm_status & IFM_AVALID) {
|
1998-08-06 06:24:40 +04:00
|
|
|
printf("\tstatus: ");
|
1997-03-17 06:08:46 +03:00
|
|
|
switch (IFM_TYPE(ifmr.ifm_active)) {
|
|
|
|
case IFM_ETHER:
|
|
|
|
if (ifmr.ifm_status & IFM_ACTIVE)
|
|
|
|
printf("active");
|
|
|
|
else
|
|
|
|
printf("no carrier");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IFM_FDDI:
|
|
|
|
case IFM_TOKEN:
|
|
|
|
if (ifmr.ifm_status & IFM_ACTIVE)
|
|
|
|
printf("inserted");
|
|
|
|
else
|
|
|
|
printf("no ring");
|
|
|
|
break;
|
1998-08-06 06:24:40 +04:00
|
|
|
default:
|
|
|
|
printf("unknown");
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
1998-08-06 06:24:40 +04:00
|
|
|
putchar('\n');
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mflag) {
|
1998-08-06 23:22:00 +04:00
|
|
|
int type, printed_type;
|
|
|
|
|
|
|
|
for (type = IFM_NMIN; type <= IFM_NMAX; type += IFM_NMIN) {
|
|
|
|
for (i = 0, printed_type = 0; i < ifmr.ifm_count; i++) {
|
|
|
|
if (IFM_TYPE(media_list[i]) == type) {
|
|
|
|
if (printed_type == 0) {
|
|
|
|
printf("\tsupported %s media:\n",
|
|
|
|
get_media_type_string(type));
|
|
|
|
printed_type = 1;
|
|
|
|
}
|
|
|
|
printf("\t\t");
|
|
|
|
print_media_word(media_list[i], 0, 1);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
1997-03-17 06:08:46 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(media_list);
|
|
|
|
|
|
|
|
proto_status:
|
1993-03-21 12:45:37 +03:00
|
|
|
if ((p = afp) != NULL) {
|
|
|
|
(*p->af_status)(1);
|
1998-09-06 21:51:32 +04:00
|
|
|
if (Aflag & !aflag)
|
|
|
|
printalias(name);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else for (p = afs; p->af_name; p++) {
|
|
|
|
ifr.ifr_addr.sa_family = p->af_af;
|
|
|
|
(*p->af_status)(0);
|
1998-09-06 21:51:32 +04:00
|
|
|
if (Aflag & !aflag && p->af_af == AF_INET)
|
|
|
|
printalias(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
in_alias(creq)
|
|
|
|
struct ifreq *creq;
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
if (lflag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get the non-alias address for this interface. */
|
|
|
|
getsock(AF_INET);
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno == EPROTONOSUPPORT)
|
|
|
|
return;
|
|
|
|
err(1, "socket");
|
|
|
|
}
|
|
|
|
(void) memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
|
|
|
if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
|
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
warn("SIOCGIFADDR");
|
|
|
|
}
|
|
|
|
/* If creq and ifr are the same address, this is not an alias. */
|
|
|
|
if (memcmp(&ifr.ifr_addr, &creq->ifr_addr,
|
|
|
|
sizeof(creq->ifr_addr)) == 0)
|
|
|
|
return;
|
|
|
|
(void) memset(&addreq, 0, sizeof(addreq));
|
|
|
|
(void) strncpy(addreq.ifra_name, name, sizeof(addreq.ifra_name));
|
|
|
|
addreq.ifra_addr = creq->ifr_addr;
|
|
|
|
if (ioctl(s, SIOCGIFALIAS, (caddr_t)&addreq) < 0) {
|
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
warn("SIOCGIFALIAS");
|
|
|
|
}
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)&addreq.ifra_addr;
|
|
|
|
printf("\tinet alias %s", inet_ntoa(sin->sin_addr));
|
|
|
|
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
|
|
|
sin = (struct sockaddr_in *)&addreq.ifra_dstaddr;
|
|
|
|
printf(" -> %s", inet_ntoa(sin->sin_addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)&addreq.ifra_mask;
|
|
|
|
printf(" netmask 0x%x", ntohl(sin->sin_addr.s_addr));
|
|
|
|
|
|
|
|
if (flags & IFF_BROADCAST) {
|
|
|
|
sin = (struct sockaddr_in *)&addreq.ifra_broadaddr;
|
|
|
|
printf(" broadcast %s", inet_ntoa(sin->sin_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-09-06 21:51:32 +04:00
|
|
|
printf("\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
in_status(force)
|
|
|
|
int force;
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
getsock(AF_INET);
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno == EPROTONOSUPPORT)
|
|
|
|
return;
|
|
|
|
err(1, "socket");
|
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
if (!force)
|
|
|
|
return;
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
sin = (struct sockaddr_in *)&ifr.ifr_addr;
|
|
|
|
printf("\tinet %s ", inet_ntoa(sin->sin_addr));
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno != EADDRNOTAVAIL)
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFNETMASK");
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
netmask.sin_addr =
|
|
|
|
((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr;
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL)
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr.ifr_addr, 0,
|
|
|
|
sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFDSTADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
sin = (struct sockaddr_in *)&ifr.ifr_dstaddr;
|
|
|
|
printf("--> %s ", inet_ntoa(sin->sin_addr));
|
|
|
|
}
|
1994-01-22 05:04:35 +03:00
|
|
|
printf("netmask 0x%x ", ntohl(netmask.sin_addr.s_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
if (flags & IFF_BROADCAST) {
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFBRDADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL)
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr.ifr_addr, 0,
|
|
|
|
sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFBRDADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
sin = (struct sockaddr_in *)&ifr.ifr_addr;
|
|
|
|
if (sin->sin_addr.s_addr != 0)
|
|
|
|
printf("broadcast %s", inet_ntoa(sin->sin_addr));
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
#ifndef INET_ONLY
|
|
|
|
|
1997-04-03 06:07:58 +04:00
|
|
|
void
|
|
|
|
at_status(force)
|
|
|
|
int force;
|
|
|
|
{
|
|
|
|
struct sockaddr_at *sat, null_sat;
|
|
|
|
struct netrange *nr;
|
|
|
|
|
|
|
|
getsock(AF_APPLETALK);
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno == EPROTONOSUPPORT)
|
|
|
|
return;
|
|
|
|
err(1, "socket");
|
|
|
|
}
|
|
|
|
(void) memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
|
|
|
if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
|
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
if (!force)
|
|
|
|
return;
|
|
|
|
(void) memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
|
|
|
} else
|
|
|
|
warn("SIOCGIFADDR");
|
|
|
|
}
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
|
|
|
sat = (struct sockaddr_at *)&ifr.ifr_addr;
|
|
|
|
|
|
|
|
(void) memset(&null_sat, 0, sizeof(null_sat));
|
|
|
|
|
|
|
|
nr = (struct netrange *) &sat->sat_zero;
|
|
|
|
printf("\tatalk %d.%d range %d-%d phase %d",
|
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
|
|
|
|
ntohs(nr->nr_firstnet), ntohs(nr->nr_lastnet), nr->nr_phase);
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
|
|
|
if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
|
|
|
|
if (errno == EADDRNOTAVAIL)
|
|
|
|
(void) memset(&ifr.ifr_addr, 0,
|
|
|
|
sizeof(ifr.ifr_addr));
|
|
|
|
else
|
|
|
|
warn("SIOCGIFDSTADDR");
|
|
|
|
}
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
|
|
|
sat = (struct sockaddr_at *)&ifr.ifr_dstaddr;
|
|
|
|
if (!sat)
|
|
|
|
sat = &null_sat;
|
|
|
|
printf("--> %d.%d",
|
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node);
|
|
|
|
}
|
|
|
|
if (flags & IFF_BROADCAST) {
|
|
|
|
/* note RTAX_BRD overlap with IFF_POINTOPOINT */
|
|
|
|
sat = (struct sockaddr_at *)&ifr.ifr_broadaddr;
|
|
|
|
if (sat)
|
|
|
|
printf(" broadcast %d.%d", ntohs(sat->sat_addr.s_net),
|
|
|
|
sat->sat_addr.s_node);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
xns_status(force)
|
|
|
|
int force;
|
|
|
|
{
|
|
|
|
struct sockaddr_ns *sns;
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
getsock(AF_NS);
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno == EPROTONOSUPPORT)
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1994-09-23 05:38:45 +04:00
|
|
|
err(1, "socket");
|
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
if (!force)
|
|
|
|
return;
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
1993-03-21 12:45:37 +03:00
|
|
|
sns = (struct sockaddr_ns *)&ifr.ifr_addr;
|
|
|
|
printf("\tns %s ", ns_ntoa(sns->sns_addr));
|
|
|
|
if (flags & IFF_POINTOPOINT) { /* by W. Nesheim@Cornell */
|
1994-09-23 05:38:45 +04:00
|
|
|
if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL)
|
1994-09-23 18:26:58 +04:00
|
|
|
memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1994-09-23 05:38:45 +04:00
|
|
|
warn("SIOCGIFDSTADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1993-03-21 12:45:37 +03:00
|
|
|
sns = (struct sockaddr_ns *)&ifr.ifr_dstaddr;
|
|
|
|
printf("--> %s ", ns_ntoa(sns->sns_addr));
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
iso_status(force)
|
|
|
|
int force;
|
|
|
|
{
|
|
|
|
struct sockaddr_iso *siso;
|
|
|
|
|
1994-09-23 05:38:45 +04:00
|
|
|
getsock(AF_ISO);
|
|
|
|
if (s < 0) {
|
|
|
|
if (errno == EPROTONOSUPPORT)
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
1994-09-23 05:38:45 +04:00
|
|
|
err(1, "socket");
|
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr, 0, sizeof(ifr));
|
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
1996-09-08 18:37:39 +04:00
|
|
|
if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
if (!force)
|
|
|
|
return;
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1994-09-23 05:38:45 +04:00
|
|
|
} else
|
1996-09-08 18:37:39 +04:00
|
|
|
warn("SIOCGIFADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
|
1996-09-08 18:37:39 +04:00
|
|
|
siso = (struct sockaddr_iso *)&ifr.ifr_addr;
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("\tiso %s ", iso_ntoa(&siso->siso_addr));
|
1996-09-08 18:37:39 +04:00
|
|
|
if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) {
|
1994-09-23 05:38:45 +04:00
|
|
|
if (errno == EADDRNOTAVAIL)
|
1996-09-08 18:37:39 +04:00
|
|
|
memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1994-09-23 05:38:45 +04:00
|
|
|
else
|
1996-09-08 18:37:39 +04:00
|
|
|
warn("SIOCGIFNETMASK");
|
1993-03-21 12:45:37 +03:00
|
|
|
} else {
|
|
|
|
printf(" netmask %s ", iso_ntoa(&siso->siso_addr));
|
|
|
|
}
|
|
|
|
if (flags & IFF_POINTOPOINT) {
|
1996-09-08 18:37:39 +04:00
|
|
|
if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno == EADDRNOTAVAIL)
|
1996-09-08 18:37:39 +04:00
|
|
|
memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
1996-09-08 18:37:39 +04:00
|
|
|
warn("SIOCGIFDSTADDR");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1997-04-03 06:07:58 +04:00
|
|
|
(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
|
1996-09-08 18:37:39 +04:00
|
|
|
siso = (struct sockaddr_iso *)&ifr.ifr_addr;
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("--> %s ", iso_ntoa(&siso->siso_addr));
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
#endif /* INET_ONLY */
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define SIN(x) ((struct sockaddr_in *) &(x))
|
|
|
|
struct sockaddr_in *sintab[] = {
|
|
|
|
SIN(ridreq.ifr_addr), SIN(addreq.ifra_addr),
|
|
|
|
SIN(addreq.ifra_mask), SIN(addreq.ifra_broadaddr)};
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
in_getaddr(s, which)
|
|
|
|
char *s;
|
1994-12-05 23:15:31 +03:00
|
|
|
int which;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-09-15 05:53:35 +04:00
|
|
|
struct sockaddr_in *sin = sintab[which];
|
1993-03-21 12:45:37 +03:00
|
|
|
struct hostent *hp;
|
|
|
|
struct netent *np;
|
|
|
|
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
if (which != MASK)
|
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
|
1995-05-20 00:17:16 +04:00
|
|
|
if (inet_aton(s, &sin->sin_addr) == 0) {
|
1997-04-03 06:07:58 +04:00
|
|
|
if ((hp = gethostbyname(s)) != NULL)
|
|
|
|
(void) memcpy(&sin->sin_addr, hp->h_addr, hp->h_length);
|
|
|
|
else if ((np = getnetbyname(s)) != NULL)
|
1995-05-20 00:17:16 +04:00
|
|
|
sin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
|
|
|
|
else
|
|
|
|
errx(1, "%s: bad value", s);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print a value a la the %b format of the kernel's printf
|
|
|
|
*/
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
printb(s, v, bits)
|
|
|
|
char *s;
|
1997-09-15 05:53:35 +04:00
|
|
|
char *bits;
|
|
|
|
unsigned short v;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-09-15 05:53:35 +04:00
|
|
|
int i, any = 0;
|
|
|
|
char c;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
if (bits && *bits == 8)
|
|
|
|
printf("%s=%o", s, v);
|
|
|
|
else
|
|
|
|
printf("%s=%x", s, v);
|
|
|
|
bits++;
|
|
|
|
if (bits) {
|
|
|
|
putchar('<');
|
1997-04-03 06:07:58 +04:00
|
|
|
while ((i = *bits++) != 0) {
|
1993-03-21 12:45:37 +03:00
|
|
|
if (v & (1 << (i-1))) {
|
|
|
|
if (any)
|
|
|
|
putchar(',');
|
|
|
|
any = 1;
|
|
|
|
for (; (c = *bits) > 32; bits++)
|
|
|
|
putchar(c);
|
|
|
|
} else
|
|
|
|
for (; *bits > 32; bits++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
putchar('>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
#ifndef INET_ONLY
|
|
|
|
|
1997-04-03 06:07:58 +04:00
|
|
|
void
|
|
|
|
at_getaddr(addr, which)
|
|
|
|
char *addr;
|
|
|
|
int which;
|
|
|
|
{
|
|
|
|
struct sockaddr_at *sat = (struct sockaddr_at *) &addreq.ifra_addr;
|
|
|
|
u_int net, node;
|
|
|
|
|
|
|
|
sat->sat_family = AF_APPLETALK;
|
|
|
|
sat->sat_len = sizeof(*sat);
|
|
|
|
if (which == MASK)
|
|
|
|
errx(1, "AppleTalk does not use netmasks\n");
|
|
|
|
if (sscanf(addr, "%u.%u", &net, &node) != 2
|
|
|
|
|| net == 0 || net > 0xffff || node == 0 || node > 0xfe)
|
|
|
|
errx(1, "%s: illegal address", addr);
|
|
|
|
sat->sat_addr.s_net = htons(net);
|
|
|
|
sat->sat_addr.s_node = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setatrange(range, d)
|
|
|
|
char *range;
|
|
|
|
int d;
|
|
|
|
{
|
|
|
|
u_short first = 123, last = 123;
|
|
|
|
|
|
|
|
if (sscanf(range, "%hu-%hu", &first, &last) != 2
|
|
|
|
|| first == 0 || first > 0xffff
|
|
|
|
|| last == 0 || last > 0xffff || first > last)
|
|
|
|
errx(1, "%s: illegal net range: %u-%u", range, first, last);
|
|
|
|
at_nr.nr_firstnet = htons(first);
|
|
|
|
at_nr.nr_lastnet = htons(last);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
setatphase(phase, d)
|
|
|
|
char *phase;
|
|
|
|
int d;
|
|
|
|
{
|
|
|
|
if (!strcmp(phase, "1"))
|
|
|
|
at_nr.nr_phase = 1;
|
|
|
|
else if (!strcmp(phase, "2"))
|
|
|
|
at_nr.nr_phase = 2;
|
|
|
|
else
|
|
|
|
errx(1, "%s: illegal phase", phase);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
checkatrange(sat)
|
|
|
|
struct sockaddr_at *sat;
|
|
|
|
{
|
|
|
|
if (at_nr.nr_phase == 0)
|
|
|
|
at_nr.nr_phase = 2; /* Default phase 2 */
|
|
|
|
if (at_nr.nr_firstnet == 0)
|
|
|
|
at_nr.nr_firstnet = /* Default range of one */
|
|
|
|
at_nr.nr_lastnet = sat->sat_addr.s_net;
|
|
|
|
printf("\tatalk %d.%d range %d-%d phase %d\n",
|
|
|
|
ntohs(sat->sat_addr.s_net), sat->sat_addr.s_node,
|
|
|
|
ntohs(at_nr.nr_firstnet), ntohs(at_nr.nr_lastnet), at_nr.nr_phase);
|
|
|
|
if ((u_short) ntohs(at_nr.nr_firstnet) >
|
|
|
|
(u_short) ntohs(sat->sat_addr.s_net)
|
|
|
|
|| (u_short) ntohs(at_nr.nr_lastnet) <
|
|
|
|
(u_short) ntohs(sat->sat_addr.s_net))
|
|
|
|
errx(1, "AppleTalk address is not in range");
|
|
|
|
*((struct netrange *) &sat->sat_zero) = at_nr;
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#define SNS(x) ((struct sockaddr_ns *) &(x))
|
|
|
|
struct sockaddr_ns *snstab[] = {
|
|
|
|
SNS(ridreq.ifr_addr), SNS(addreq.ifra_addr),
|
|
|
|
SNS(addreq.ifra_mask), SNS(addreq.ifra_broadaddr)};
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
xns_getaddr(addr, which)
|
1994-12-05 23:15:31 +03:00
|
|
|
char *addr;
|
|
|
|
int which;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct sockaddr_ns *sns = snstab[which];
|
|
|
|
|
|
|
|
sns->sns_family = AF_NS;
|
|
|
|
sns->sns_len = sizeof(*sns);
|
|
|
|
sns->sns_addr = ns_addr(addr);
|
|
|
|
if (which == MASK)
|
1997-04-21 05:17:57 +04:00
|
|
|
puts("Attempt to set XNS netmask will be ineffectual");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SISO(x) ((struct sockaddr_iso *) &(x))
|
|
|
|
struct sockaddr_iso *sisotab[] = {
|
1996-09-08 18:37:39 +04:00
|
|
|
SISO(ridreq.ifr_addr), SISO(iso_addreq.ifra_addr),
|
1993-03-21 12:45:37 +03:00
|
|
|
SISO(iso_addreq.ifra_mask), SISO(iso_addreq.ifra_dstaddr)};
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
iso_getaddr(addr, which)
|
1994-12-05 23:15:31 +03:00
|
|
|
char *addr;
|
|
|
|
int which;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-09-15 05:53:35 +04:00
|
|
|
struct sockaddr_iso *siso = sisotab[which];
|
1993-03-21 12:45:37 +03:00
|
|
|
siso->siso_addr = *iso_addr(addr);
|
|
|
|
|
|
|
|
if (which == MASK) {
|
|
|
|
siso->siso_len = TSEL(siso) - (caddr_t)(siso);
|
|
|
|
siso->siso_nlen = 0;
|
|
|
|
} else {
|
|
|
|
siso->siso_len = sizeof(*siso);
|
|
|
|
siso->siso_family = AF_ISO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setsnpaoffset(val, d)
|
1995-10-09 02:03:54 +03:00
|
|
|
char *val;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1995-10-09 02:03:54 +03:00
|
|
|
{
|
|
|
|
iso_addreq.ifra_snpaoffset = atoi(val);
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1997-04-03 06:07:58 +04:00
|
|
|
setnsellength(val, d)
|
1993-03-21 12:45:37 +03:00
|
|
|
char *val;
|
1997-04-03 06:07:58 +04:00
|
|
|
int d;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
nsellength = atoi(val);
|
1994-01-22 05:04:35 +03:00
|
|
|
if (nsellength < 0)
|
|
|
|
errx(1, "Negative NSEL length is absurd");
|
|
|
|
if (afp == 0 || afp->af_af != AF_ISO)
|
|
|
|
errx(1, "Setting NSEL length valid only for iso");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
fixnsel(s)
|
1997-09-15 05:53:35 +04:00
|
|
|
struct sockaddr_iso *s;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (s->siso_family == 0)
|
|
|
|
return;
|
|
|
|
s->siso_tlen = nsellength;
|
|
|
|
}
|
|
|
|
|
1994-12-05 23:15:31 +03:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
adjust_nsellength()
|
|
|
|
{
|
|
|
|
fixnsel(sisotab[RIDADDR]);
|
|
|
|
fixnsel(sisotab[ADDR]);
|
|
|
|
fixnsel(sisotab[DSTADDR]);
|
|
|
|
}
|
1995-01-22 00:22:16 +03:00
|
|
|
|
1995-10-09 02:03:54 +03:00
|
|
|
#endif /* INET_ONLY */
|
|
|
|
|
1995-01-22 00:22:16 +03:00
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
1997-03-28 01:50:09 +03:00
|
|
|
fprintf(stderr,
|
1998-09-06 21:51:32 +04:00
|
|
|
"usage: ifconfig [ -m ] [ -A ] interface\n%s%s%s%s%s%s%s%s%s%s%s%s",
|
1995-01-22 00:22:16 +03:00
|
|
|
"\t[ af [ address [ dest_addr ] ] [ up ] [ down ] ",
|
|
|
|
"[ netmask mask ] ]\n",
|
|
|
|
"\t[ metric n ]\n",
|
1997-04-10 23:10:16 +04:00
|
|
|
"\t[ mtu n ]\n",
|
1995-01-22 00:22:16 +03:00
|
|
|
"\t[ arp | -arp ]\n",
|
1997-03-17 06:08:46 +03:00
|
|
|
"\t[ media mtype ]\n",
|
|
|
|
"\t[ mediaopt mopts ]\n",
|
|
|
|
"\t[ -mediaopt mopts ]\n",
|
1998-08-09 02:40:57 +04:00
|
|
|
"\t[ instance minst ]\n",
|
1995-01-22 00:22:16 +03:00
|
|
|
"\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n",
|
1998-09-06 21:51:32 +04:00
|
|
|
" ifconfig -a [ -A ] [ -m ] [ -d ] [ -u ] [ af ]\n",
|
1997-04-21 05:17:57 +04:00
|
|
|
" ifconfig -l [ -d ] [ -u ]\n");
|
1995-01-22 00:22:16 +03:00
|
|
|
exit(1);
|
|
|
|
}
|