Commit 3b84ea68 authored by Andreas Gustafsson's avatar Andreas Gustafsson
Browse files

use new isc_netaddr_t type to represent network addresses

parent 0237695c
......@@ -287,8 +287,9 @@ ns_interfacemgr_scan(ns_interfacemgr_t *mgr) {
iter_result = isc_interfaceiter_current(iter, &interface);
INSIST(iter_result == ISC_R_SUCCESS);
listen_addr = interface.address;
INSIST(listen_addr.type.sin.sin_family == AF_INET);
memset(&listen_addr, 0, sizeof(listen_addr));
listen_addr.type.sin.sin_family = AF_INET;
listen_addr.type.sin.sin_addr = interface.address.type.in;
listen_addr.type.sin.sin_port = htons(listen_port);
ifp = find_matching_interface(mgr, &listen_addr);
......
......@@ -42,7 +42,7 @@
#include <isc/result.h>
#include <isc/mem.h>
#include <isc/sockaddr.h>
#include <isc/netaddr.h>
/***
*** Types
......@@ -52,20 +52,15 @@ typedef struct isc_interfaceiter isc_interfaceiter_t;
/*
* Public structure describing a network interface.
*
* In 'address', 'netmask', and 'dstaddress',
* only the network address field (for IPv4, type.sin.sin_addr)
* is used. Other fields including the port and address family
* have undefined values.
*/
typedef struct {
char name[32]; /* Interface name, null-terminated. */
unsigned int af; /* Address family. */
isc_sockaddr_t address; /* Local address. */
isc_sockaddr_t netmask; /* Network mask
isc_netaddr_t address; /* Local address. */
isc_netaddr_t netmask; /* Network mask
(non-point-to-point only). */
isc_sockaddr_t dstaddress; /* Destination address
isc_netaddr_t dstaddress; /* Destination address
(point-to-point only). */
isc_uint32_t flags; /* Flags; see below. */
} isc_interface_t;
......
......@@ -148,16 +148,19 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp)
}
/*
* Copy a socket address. The address family is given explicity
* Extract the network address part from a "struct sockaddr".
*
* The address family is given explicity
* instead of using src->sa_family, because the latter does not work
* for copying the network mask as obtained by SIOCGIFNETMASK.
* for copying a network mask obtained by SIOCGIFNETMASK (it does
* not have a valid address family).
*/
static void
copy_sockaddr(int family, isc_sockaddr_t *dst, struct sockaddr *src) {
get_addr(int family, isc_netaddr_t *dst, struct sockaddr *src) {
switch (family) {
case AF_INET:
dst->type.sin.sin_family = AF_INET;
memcpy(&dst->type.sin.sin_addr,
memcpy(&dst->type.in,
&((struct sockaddr_in *) src)->sin_addr,
sizeof(struct in_addr));
break;
......@@ -198,7 +201,7 @@ internal_current(isc_interfaceiter_t *iter) {
INSIST(sizeof(ifreq.ifr_name) <= sizeof(iter->current.name));
memcpy(iter->current.name, ifreq.ifr_name, sizeof(ifreq.ifr_name));
copy_sockaddr(family, &iter->current.address, &ifreq.ifr_addr);
get_addr(family, &iter->current.address, &ifreq.ifr_addr);
/* Get interface flags. */
......@@ -233,8 +236,8 @@ internal_current(isc_interfaceiter_t *iter) {
strerror(errno));
return (ISC_R_UNEXPECTED);
}
copy_sockaddr(family, &iter->current.dstaddress,
&ifreq.ifr_dstaddr);
get_addr(family, &iter->current.dstaddress,
&ifreq.ifr_dstaddr);
} else {
if (ioctl(iter->socket, SIOCGIFNETMASK, (char *) &ifreq) < 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
......@@ -243,8 +246,8 @@ internal_current(isc_interfaceiter_t *iter) {
strerror(errno));
return (ISC_R_UNEXPECTED);
}
copy_sockaddr(family, &iter->current.netmask,
&ifreq.ifr_addr);
get_addr(family, &iter->current.netmask,
&ifreq.ifr_addr);
}
return (ISC_R_SUCCESS);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment