2009-08-07 23:35:55 +04:00
|
|
|
/* $NetBSD: af_inet.c,v 1.13 2009/08/07 19:35:55 dyoung Exp $ */
|
2005-03-20 05:43:50 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* 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. 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2009-08-07 23:35:55 +04:00
|
|
|
__RCSID("$NetBSD: af_inet.c,v 1.13 2009/08/07 19:35:55 dyoung Exp $");
|
2005-03-20 05:43:50 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#include <assert.h>
|
2005-03-20 05:43:50 +03:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2006-08-26 22:14:28 +04:00
|
|
|
#include <util.h>
|
2005-03-20 05:43:50 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
#include "env.h"
|
2005-03-20 05:43:50 +03:00
|
|
|
#include "extern.h"
|
2008-05-08 11:13:20 +04:00
|
|
|
#include "af_inetany.h"
|
2005-03-20 05:43:50 +03:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void in_constructor(void) __attribute__((constructor));
|
|
|
|
static void in_status(prop_dictionary_t, prop_dictionary_t, bool);
|
|
|
|
static void in_commit_address(prop_dictionary_t, prop_dictionary_t);
|
2008-05-12 03:25:46 +04:00
|
|
|
static void in_alias(const char *, prop_dictionary_t, prop_dictionary_t,
|
|
|
|
struct in_aliasreq *);
|
2006-11-13 08:13:38 +03:00
|
|
|
static void in_preference(const char *, const struct sockaddr *);
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static struct afswtch af = {
|
|
|
|
.af_name = "inet", .af_af = AF_INET, .af_status = in_status,
|
|
|
|
.af_addr_commit = in_commit_address
|
|
|
|
};
|
|
|
|
|
2008-05-13 00:59:13 +04:00
|
|
|
static void
|
2008-05-06 08:33:42 +04:00
|
|
|
in_alias(const char *ifname, prop_dictionary_t env, prop_dictionary_t oenv,
|
2008-05-12 03:25:46 +04:00
|
|
|
struct in_aliasreq *creq)
|
2005-03-20 05:43:50 +03:00
|
|
|
{
|
2008-05-06 08:33:42 +04:00
|
|
|
struct ifreq ifr;
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
bool alias;
|
|
|
|
int s;
|
2008-05-06 08:33:42 +04:00
|
|
|
unsigned short flags;
|
|
|
|
struct in_aliasreq in_addreq;
|
2009-08-07 23:35:55 +04:00
|
|
|
const struct sockaddr_in * const asin = &in_addreq.ifra_addr;
|
|
|
|
const struct sockaddr_in * const dsin = &in_addreq.ifra_dstaddr;
|
|
|
|
const struct sockaddr_in * const bsin = &in_addreq.ifra_broadaddr;
|
|
|
|
char hbuf[NI_MAXHOST];
|
|
|
|
const int niflag = Nflag ? 0 : NI_NUMERICHOST;
|
2005-03-20 05:43:50 +03:00
|
|
|
|
|
|
|
if (lflag)
|
|
|
|
return;
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
alias = true;
|
2005-03-20 05:43:50 +03:00
|
|
|
|
|
|
|
/* Get the non-alias address for this interface. */
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((s = getsock(AF_INET)) == -1) {
|
2006-06-14 15:05:42 +04:00
|
|
|
if (errno == EAFNOSUPPORT)
|
2005-03-20 05:43:50 +03:00
|
|
|
return;
|
|
|
|
err(EXIT_FAILURE, "socket");
|
|
|
|
}
|
2008-05-06 08:33:42 +04:00
|
|
|
memset(&ifr, 0, sizeof(ifr));
|
|
|
|
estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
2005-03-20 05:43:50 +03:00
|
|
|
if (ioctl(s, SIOCGIFADDR, &ifr) == -1) {
|
2008-05-12 03:25:46 +04:00
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
|
2005-03-20 05:43:50 +03:00
|
|
|
return;
|
2008-05-12 03:25:46 +04:00
|
|
|
warn("SIOCGIFADDR");
|
2005-03-20 05:43:50 +03:00
|
|
|
}
|
|
|
|
/* If creq and ifr are the same address, this is not an alias. */
|
2008-05-12 03:25:46 +04:00
|
|
|
if (memcmp(&ifr.ifr_addr, &creq->ifra_addr, sizeof(ifr.ifr_addr)) == 0)
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
alias = false;
|
2008-05-12 03:25:46 +04:00
|
|
|
in_addreq = *creq;
|
2005-03-20 05:43:50 +03:00
|
|
|
if (ioctl(s, SIOCGIFALIAS, &in_addreq) == -1) {
|
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
warn("SIOCGIFALIAS");
|
|
|
|
}
|
|
|
|
|
2009-08-07 23:35:55 +04:00
|
|
|
if (getnameinfo((const struct sockaddr *)asin, asin->sin_len,
|
|
|
|
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
|
|
|
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
|
|
|
|
printf("\tinet %s%s", alias ? "alias " : "", hbuf);
|
2008-05-06 08:33:42 +04:00
|
|
|
|
|
|
|
if (getifflags(env, oenv, &flags) == -1)
|
|
|
|
err(EXIT_FAILURE, "%s: getifflags", __func__);
|
2005-03-20 05:43:50 +03:00
|
|
|
|
2009-08-07 23:35:55 +04:00
|
|
|
if (flags & IFF_POINTOPOINT) {
|
|
|
|
if (getnameinfo((const struct sockaddr *)dsin, dsin->sin_len,
|
|
|
|
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
|
|
|
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
|
|
|
|
printf(" -> %s", hbuf);
|
|
|
|
}
|
2005-03-20 05:43:50 +03:00
|
|
|
|
2008-05-12 03:25:46 +04:00
|
|
|
printf(" netmask 0x%x", ntohl(in_addreq.ifra_mask.sin_addr.s_addr));
|
2005-03-20 05:43:50 +03:00
|
|
|
|
|
|
|
if (flags & IFF_BROADCAST) {
|
2009-08-07 23:35:55 +04:00
|
|
|
if (getnameinfo((const struct sockaddr *)bsin, bsin->sin_len,
|
|
|
|
hbuf, sizeof(hbuf), NULL, 0, niflag))
|
|
|
|
strlcpy(hbuf, "", sizeof(hbuf)); /* some message? */
|
|
|
|
printf(" broadcast %s", hbuf);
|
2005-03-20 05:43:50 +03:00
|
|
|
}
|
2006-11-13 08:13:38 +03:00
|
|
|
}
|
|
|
|
|
2008-05-12 03:25:46 +04:00
|
|
|
static int16_t
|
2006-11-13 08:13:38 +03:00
|
|
|
in_get_preference(const char *ifname, const struct sockaddr *sa)
|
|
|
|
{
|
|
|
|
struct if_addrprefreq ifap;
|
2008-05-06 08:33:42 +04:00
|
|
|
int s;
|
2006-11-13 08:13:38 +03:00
|
|
|
|
2008-05-06 08:33:42 +04:00
|
|
|
if ((s = getsock(AF_INET)) == -1) {
|
2006-11-13 08:13:38 +03:00
|
|
|
if (errno == EPROTONOSUPPORT)
|
|
|
|
return 0;
|
|
|
|
err(EXIT_FAILURE, "socket");
|
|
|
|
}
|
2008-05-06 08:33:42 +04:00
|
|
|
memset(&ifap, 0, sizeof(ifap));
|
2008-05-12 03:25:46 +04:00
|
|
|
estrlcpy(ifap.ifap_name, ifname, sizeof(ifap.ifap_name));
|
2008-05-06 08:33:42 +04:00
|
|
|
memcpy(&ifap.ifap_addr, sa, MIN(sizeof(ifap.ifap_addr), sa->sa_len));
|
2006-11-13 08:13:38 +03:00
|
|
|
if (ioctl(s, SIOCGIFADDRPREF, &ifap) == -1) {
|
|
|
|
if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT)
|
|
|
|
return 0;
|
|
|
|
warn("SIOCGIFADDRPREF");
|
|
|
|
}
|
|
|
|
return ifap.ifap_preference;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
in_preference(const char *ifname, const struct sockaddr *sa)
|
|
|
|
{
|
2008-05-12 03:25:46 +04:00
|
|
|
int16_t preference;
|
2006-11-13 08:13:38 +03:00
|
|
|
|
|
|
|
if (lflag)
|
|
|
|
return;
|
|
|
|
|
|
|
|
preference = in_get_preference(ifname, sa);
|
2008-05-12 03:25:46 +04:00
|
|
|
printf(" preference %" PRId16, preference);
|
2005-03-20 05:43:50 +03:00
|
|
|
}
|
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
2008-05-06 20:15:17 +04:00
|
|
|
in_status(prop_dictionary_t env, prop_dictionary_t oenv, bool force)
|
2005-03-20 05:43:50 +03:00
|
|
|
{
|
|
|
|
struct ifaddrs *ifap, *ifa;
|
2008-05-12 03:25:46 +04:00
|
|
|
struct in_aliasreq ifra;
|
2006-11-13 08:13:38 +03:00
|
|
|
int printprefs = 0;
|
2008-05-06 08:33:42 +04:00
|
|
|
const char *ifname;
|
|
|
|
|
|
|
|
if ((ifname = getifname(env)) == NULL)
|
|
|
|
err(EXIT_FAILURE, "%s: getifname", __func__);
|
2005-03-20 05:43:50 +03:00
|
|
|
|
|
|
|
if (getifaddrs(&ifap) != 0)
|
|
|
|
err(EXIT_FAILURE, "getifaddrs");
|
2008-05-12 03:25:46 +04:00
|
|
|
|
2006-11-13 08:13:38 +03:00
|
|
|
/* Print address preference numbers if any address has a non-zero
|
|
|
|
* preference assigned.
|
|
|
|
*/
|
2008-05-12 03:25:46 +04:00
|
|
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
2008-05-06 08:33:42 +04:00
|
|
|
if (strcmp(ifname, ifa->ifa_name) != 0)
|
2006-11-13 08:13:38 +03:00
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
continue;
|
|
|
|
if (in_get_preference(ifa->ifa_name, ifa->ifa_addr) != 0) {
|
|
|
|
printprefs = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-12 03:25:46 +04:00
|
|
|
for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
|
2008-05-06 08:33:42 +04:00
|
|
|
if (strcmp(ifname, ifa->ifa_name) != 0)
|
2005-03-20 05:43:50 +03:00
|
|
|
continue;
|
|
|
|
if (ifa->ifa_addr->sa_family != AF_INET)
|
|
|
|
continue;
|
2008-05-12 03:25:46 +04:00
|
|
|
if (sizeof(ifra.ifra_addr) < ifa->ifa_addr->sa_len)
|
2005-03-20 05:43:50 +03:00
|
|
|
continue;
|
|
|
|
|
2008-05-12 03:25:46 +04:00
|
|
|
memset(&ifra, 0, sizeof(ifra));
|
|
|
|
estrlcpy(ifra.ifra_name, ifa->ifa_name, sizeof(ifra.ifra_name));
|
|
|
|
memcpy(&ifra.ifra_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);
|
|
|
|
in_alias(ifa->ifa_name, env, oenv, &ifra);
|
2006-11-13 08:13:38 +03:00
|
|
|
if (printprefs)
|
|
|
|
in_preference(ifa->ifa_name, ifa->ifa_addr);
|
|
|
|
printf("\n");
|
|
|
|
}
|
2005-03-20 05:43:50 +03:00
|
|
|
freeifaddrs(ifap);
|
|
|
|
}
|
2008-05-08 11:13:20 +04:00
|
|
|
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
static void
|
2008-05-08 11:13:20 +04:00
|
|
|
in_commit_address(prop_dictionary_t env, prop_dictionary_t oenv)
|
|
|
|
{
|
|
|
|
struct ifreq in_ifr;
|
|
|
|
struct in_aliasreq in_ifra;
|
|
|
|
struct afparam inparam = {
|
|
|
|
.req = BUFPARAM(in_ifra)
|
|
|
|
, .dgreq = BUFPARAM(in_ifr)
|
|
|
|
, .name = {
|
|
|
|
{.buf = in_ifr.ifr_name,
|
|
|
|
.buflen = sizeof(in_ifr.ifr_name)}
|
|
|
|
, {.buf = in_ifra.ifra_name,
|
|
|
|
.buflen = sizeof(in_ifra.ifra_name)}
|
|
|
|
}
|
|
|
|
, .dgaddr = BUFPARAM(in_ifr.ifr_addr)
|
|
|
|
, .addr = BUFPARAM(in_ifra.ifra_addr)
|
|
|
|
, .dst = BUFPARAM(in_ifra.ifra_dstaddr)
|
|
|
|
, .brd = BUFPARAM(in_ifra.ifra_broadaddr)
|
|
|
|
, .mask = BUFPARAM(in_ifra.ifra_mask)
|
|
|
|
, .aifaddr = IFADDR_PARAM(SIOCAIFADDR)
|
|
|
|
, .difaddr = IFADDR_PARAM(SIOCDIFADDR)
|
|
|
|
, .gifaddr = IFADDR_PARAM(SIOCGIFADDR)
|
|
|
|
, .defmask = {.buf = NULL, .buflen = 0}
|
|
|
|
};
|
2008-05-12 02:07:23 +04:00
|
|
|
memset(&in_ifr, 0, sizeof(in_ifr));
|
|
|
|
memset(&in_ifra, 0, sizeof(in_ifra));
|
2008-05-08 11:13:20 +04:00
|
|
|
commit_address(env, oenv, &inparam);
|
|
|
|
}
|
Let us add/remove features from ifconfig, such as support for
various address families (inet, inet6, iso, atalk) and protocols
(802.11, 802.3ad, CARP), simply by trimming the list of sources in
the Makefile. This helps one customize ifconfig for an embedded
device or for install media, and it eliminates a lot of grotty
#ifdef'age. Now, the ifconfig syntax and semantics are finalized
at run-time using the constructor routines in each address-family/protocol
module.
(In principle, ifconfig could load virtually all of its syntax from
shared objects.)
Extract a lot of common code into subroutines, in order to shrink
the ifconfig binary a bit. Make all of the address families share
code for address addition/replacement/removal, and delete "legacy"
code for manipulating addresses. That may have broken atalk and
iso, despite my best efforts.
Extract an include file, Makefile.inc, containing the make-fu that
both ifconfig and x_ifconfig share.
Sprinkle static. Change some int's to bool's. Constify.
Add RCS Ids to carp.c and env.c. Move media code to a new file,
media.c. Delete several unneeded header files.
Set, reset, and display the IEEE 802.11 attribute, 'dot11RTSThreshold'.
Bug fix: do not require both a interface address and a destination
address for point-to-point interfaces, but accept a interface
address by itself.
2008-07-02 11:44:13 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
in_constructor(void)
|
|
|
|
{
|
|
|
|
register_family(&af);
|
|
|
|
}
|