ifiter_sysctl.c revision 461a00bbdee50a46ba7fcfb3f9f2847d3bda5ad3
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999, 2000 Internet Software Consortium.
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * copyright notice and this permission notice appear in all copies.
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley *
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26cf4737b3e84c3a686a5eacebf22ac39e57d4caMark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * SOFTWARE.
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley */
5c7d67e3e68f8dbc45ffd4e1ea94696899b7b966Bob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley/*
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * Obtain the list of network interfaces using sysctl.
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley * See TCP/IP Illustrated Volume 2, sections 19.8, 19.14,
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington * and 19.16.
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉 */
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉
386d3a99c190bad55edf44d076e6bd087e230ab8Tatuya JINMEI 神明達哉#include <sys/param.h>
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley#include <sys/sysctl.h>
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley#include <net/route.h>
801dceea23d11975f5a5ae6ccbdf1dbde6b7af13David Lawrence#include <net/if_dl.h>
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence/* XXX what about Alpha? */
801dceea23d11975f5a5ae6ccbdf1dbde6b7af13David Lawrence#ifdef sgi
bed86971bf7eb315e9c64f75bba331917f4557cfBob Halley#define ROUNDUP(a) ((a) > 0 ? \
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington (1 + (((a) - 1) | (sizeof(__uint64_t) - 1))) : \
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews sizeof(__uint64_t))
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence#else
eefea43215016bce437ab4a7441b2851fd182960David Lawrence#define ROUNDUP(a) ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) \
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington : sizeof(long))
440be4c866f6935ac069db79a414304507a664c2Michael Graff#endif
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt#define IFITER_MAGIC 0x49464953U /* IFIS. */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt#define VALID_IFITER(t) ((t) != NULL && (t)->magic == IFITER_MAGIC)
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Huntstruct isc_interfaceiter {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int magic; /* Magic number. */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mem_t *mctx;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void *buf; /* Buffer for sysctl data. */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int bufsize; /* Bytes allocated. */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int bufused; /* Bytes used. */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int pos; /* Current offset in
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt sysctl data. */
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington isc_interface_t current; /* Current interface data. */
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington isc_result_t result; /* Last result code. */
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellington};
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
ae8b7e02a8e5d7febba7d79b2c759add95a48f60Brian Wellingtonstatic int mib[6] = {
1b32bc7da1da9059abd68d6dd15b23e8a442afa3Brian Wellington CTL_NET,
1b32bc7da1da9059abd68d6dd15b23e8a442afa3Brian Wellington PF_ROUTE,
0d89afffb26d5e53a761fc425dab3dda07c7e191Brian Wellington 0,
1b32bc7da1da9059abd68d6dd15b23e8a442afa3Brian Wellington 0, /* Any address family. */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 NET_RT_IFLIST,
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt 0 /* Flags. */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt};
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉isc_result_t
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Huntisc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp)
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt{
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt isc_interfaceiter_t *iter;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt isc_result_t result;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt size_t bufsize;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt size_t bufused;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt REQUIRE(mctx != NULL);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt REQUIRE(iterp != NULL);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt REQUIRE(*iterp == NULL);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt iter = isc_mem_get(mctx, sizeof(*iter));
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt if (iter == NULL)
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt return (ISC_R_NOMEMORY);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt iter->mctx = mctx;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt iter->buf = 0;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt /* Determine the amount of memory needed. */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt bufsize = 0;
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews if (sysctl(mib, 6, NULL, &bufsize, NULL, (size_t) 0) < 0) {
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews UNEXPECTED_ERROR(__FILE__, __LINE__,
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews "getting interface list size: sysctl: %s",
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 strerror(errno));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = ISC_R_UNEXPECTED;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 goto failure;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->bufsize = bufsize;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->buf = isc_mem_get(iter->mctx, iter->bufsize);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (iter->buf == NULL) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = ISC_R_NOMEMORY;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 goto failure;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 bufused = bufsize;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (sysctl(mib, 6, iter->buf, &bufused, NULL, (size_t) 0) < 0) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 UNEXPECTED_ERROR(__FILE__, __LINE__,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 "getting interface list: sysctl: %s",
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 strerror(errno));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 result = ISC_R_UNEXPECTED;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 goto failure;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 }
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->bufused = bufused;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 INSIST(iter->bufused <= iter->bufsize);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /*
d7201de09b85929a86b157f4b2d91667c68c6b52Automatic Updater * A newly created iterator has an undefined position
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * until isc_interfaceiter_first() is called.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->pos = (unsigned int) -1;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->result = ISC_R_FAILURE;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt iter->magic = IFITER_MAGIC;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt *iterp = iter;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt return (ISC_R_SUCCESS);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 failure:
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (iter->buf != NULL)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mem_put(mctx, iter->buf, iter->bufsize);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mem_put(mctx, iter, sizeof *iter);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return (result);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉}
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Get information about the current interface to iter->current.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * If successful, return ISC_R_SUCCESS.
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews * If the interface has an unsupported address family,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * return ISC_R_IGNORE. In case of other failure,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * return ISC_R_UNEXPECTED.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉static isc_result_t
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉internal_current(isc_interfaceiter_t *iter) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 struct ifa_msghdr *ifam, *ifam_end;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE(VALID_IFITER(iter));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE (iter->pos < (unsigned int) iter->bufused);
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews
62f016d5d301713c72a59e83d3ab41170a77f674Mark Andrews ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt ifam_end = (struct ifa_msghdr *) ((char *) iter->buf + iter->bufused);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt if (ifam->ifam_type == RTM_IFINFO) {
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt struct if_msghdr *ifm = (struct if_msghdr *) ifam;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt struct sockaddr_dl *sdl = (struct sockaddr_dl *) (ifm + 1);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt unsigned int namelen;
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
8fec8134ea13c2c082c3e63f1ce0afd851e45a91Tatuya JINMEI 神明達哉 memset(&iter->current, 0, sizeof(iter->current));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 namelen = sdl->sdl_nlen;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley if (namelen > sizeof(iter->current.name) - 1)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein namelen = sizeof(iter->current.name) - 1;
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley memcpy(iter->current.name, sdl->sdl_data, namelen);
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley iter->current.flags = 0;
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley if ((ifam->ifam_flags & IFF_UP) != 0)
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein iter->current.flags |= INTERFACE_F_UP;
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley if ((ifam->ifam_flags & IFF_POINTOPOINT) != 0)
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley iter->current.flags |= INTERFACE_F_POINTTOPOINT;
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley if ((ifam->ifam_flags & IFF_LOOPBACK) != 0)
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley iter->current.flags |= INTERFACE_F_LOOPBACK;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley /*
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater * This is not an interface address.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Force another iteration.
97f1a75cf072c2cab98b4bc28c4d2491cfcd3086Bob Halley */
97f1a75cf072c2cab98b4bc28c4d2491cfcd3086Bob Halley return (ISC_R_IGNORE);
97f1a75cf072c2cab98b4bc28c4d2491cfcd3086Bob Halley } else if (ifam->ifam_type == RTM_NEWADDR) {
97f1a75cf072c2cab98b4bc28c4d2491cfcd3086Bob Halley int i;
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater int family;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 struct sockaddr *mask_sa = NULL;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley struct sockaddr *addr_sa = NULL;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley struct sockaddr *dst_sa = NULL;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley struct sockaddr *sa = (struct sockaddr *)(ifam + 1);
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley family = sa->sa_family;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews for (i = 0; i < RTAX_MAX; i++)
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley {
91cd0f93ad34d23e8b09dca337120f64fbe8f0a1Andreas Gustafsson if ((ifam->ifam_addrs & (1 << i)) == 0)
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley continue;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley INSIST(sa < (struct sockaddr *) ifam_end);
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews switch (i) {
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley case RTAX_NETMASK: /* Netmask */
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence mask_sa = sa;
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence break;
9cd6d409b78a6f833b681c13a68fbdc7c024fe66David Lawrence case RTAX_IFA: /* Interface address */
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews addr_sa = sa;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley break;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley case RTAX_BRD: /* Broadcast or destination address */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence dst_sa = sa;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley break;
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley }
dd324bd791a766c48d90ce9e43d1ab1446378983Bob Halley#ifdef ISC_PLATFORM_HAVESALEN
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt sa = (struct sockaddr *)((char*)(sa)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 + ROUNDUP(sa->sa_len));
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#else
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley#ifdef sgi
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt /* Do as the contributed SGI code does. */
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt sa = (struct sockaddr *)((char*)(sa)
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt + ROUNDUP(_FAKE_SA_LEN_DST(sa)));
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt#else
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 /* XXX untested. */
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley sa = (struct sockaddr *)((char*)(sa)
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley + ROUNDUP(sizeof(struct sockaddr)));
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley#endif
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley#endif
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley }
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley if (addr_sa == NULL)
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley return (ISC_R_IGNORE);
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley family = addr_sa->sa_family;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley if (family != AF_INET) /* XXX IP6 */
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews return (ISC_R_IGNORE);
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews iter->current.af = family;
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley get_addr(family, &iter->current.address, addr_sa);
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley if (mask_sa != NULL)
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt get_addr(family, &iter->current.netmask, mask_sa);
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley if (dst_sa != NULL &&
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt (iter->current.flags & IFF_POINTOPOINT) != 0)
a829555ed724caa56b1ff7716d7eda2266491eafBob Halley get_addr(family, &iter->current.dstaddress, dst_sa);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 return (ISC_R_SUCCESS);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 } else {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 printf("warning: unexpected interface list message type\n");
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt return (ISC_R_IGNORE);
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt }
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt}
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt/*
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * Step the iterator to the next interface. Unlike
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * isc_interfaceiter_next(), this may leave the iterator
634a52966f2324e6d5ceda191fd873ba1cfeb936Evan Hunt * positioned on an interface that will ultimately
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * be ignored. Return ISC_R_NOMORE if there are no more
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt * interfaces, otherwise ISC_R_SUCCESS.
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt */
634a52966f2324e6d5ceda191fd873ba1cfeb936Evan Huntstatic isc_result_t
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Huntinternal_next(isc_interfaceiter_t *iter) {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 struct ifa_msghdr *ifam;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 REQUIRE (iter->pos < (unsigned int) iter->bufused);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 ifam = (struct ifa_msghdr *) ((char *) iter->buf + iter->pos);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 iter->pos += ifam->ifam_msglen;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 if (iter->pos >= iter->bufused)
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley return (ISC_R_NOMORE);
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
0e58c0998df1ccd1a289b2c3f078e7d03d9331d3Bob Halley return (ISC_R_SUCCESS);
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley}
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halleystatic void
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halleyinternal_destroy(isc_interfaceiter_t *iter) {
96f55bdc736f8559b3a57260db6f0e964c44070dBob Halley iter = iter; /* Unused. */
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley /* Do nothing. */
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley}
b99bfa184bc9375421b5df915eea7dfac6a68a99Evan Hunt
03dd96d177e4ed6771be7fb5f86a3a9d5f17be4eBob Halley