From 284349482f5293a9a23d0f72d7c2aab46b55843b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 22:48:25 +0000 Subject: r3443: the next stage in the include files re-organisation. I have created the include/system/ directory, which will contain the wrappers for the system includes for logical subsystems. So far I have created include/system/kerberos.h and include/system/network.h, which contain all the system includes for kerberos code and networking code. These are the included in subsystems that need kerberos or networking respectively. Note that this method avoids the mess of #ifdef HAVE_XXX_H in every C file, instead each C module includes the include/system/XXX.h file for the logical system support it needs, and the details are kept isolated in include/system/ This patch also creates a "struct ipv4_addr" which replaces "struct in_addr" in our code. That avoids every C file needing to import all the system networking headers. (This used to be commit 2e25c71853f8996f73755277e448e7d670810349) --- source4/lib/basic.m4 | 1 + source4/lib/basic.mk | 14 +- source4/lib/interface.c | 341 -------------------------------- source4/lib/interfaces.c | 407 --------------------------------------- source4/lib/netif/interface.c | 355 ++++++++++++++++++++++++++++++++++ source4/lib/netif/netif.c | 400 ++++++++++++++++++++++++++++++++++++++ source4/lib/netif/netif.h | 34 ++++ source4/lib/replace.c | 2 +- source4/lib/socket/access.c | 1 + source4/lib/socket/socket_ipv4.c | 13 +- source4/lib/socket/socket_ipv6.c | 1 + source4/lib/system.c | 22 +++ source4/lib/util.c | 15 +- source4/lib/util_sock.c | 21 +- source4/lib/util_strlist.c | 16 +- source4/lib/wins_srv.c | 30 +-- 16 files changed, 875 insertions(+), 798 deletions(-) delete mode 100644 source4/lib/interface.c delete mode 100644 source4/lib/interfaces.c create mode 100644 source4/lib/netif/interface.c create mode 100644 source4/lib/netif/netif.c create mode 100644 source4/lib/netif/netif.h (limited to 'source4/lib') diff --git a/source4/lib/basic.m4 b/source4/lib/basic.m4 index 6701ddaee5..1640ef2b9d 100644 --- a/source4/lib/basic.m4 +++ b/source4/lib/basic.m4 @@ -1,4 +1,5 @@ dnl # LIB BASIC subsystem SMB_SUBSYSTEM_MK(LIBREPLACE,lib/basic.mk) +SMB_SUBSYSTEM_MK(LIBNETIF,lib/basic.mk) SMB_SUBSYSTEM_MK(LIBBASIC,lib/basic.mk) diff --git a/source4/lib/basic.mk b/source4/lib/basic.mk index 56fc19dca7..55e654ec74 100644 --- a/source4/lib/basic.mk +++ b/source4/lib/basic.mk @@ -9,6 +9,16 @@ ADD_OBJ_FILES = \ # End SUBSYSTEM LIBREPLACE ############################## +############################## +# Start SUBSYSTEM LIBNETIF +[SUBSYSTEM::LIBNETIF] +INIT_OBJ_FILES = \ + lib/netif/interface.o +ADD_OBJ_FILES = \ + lib/netif/netif.o +# End SUBSYSTEM LIBNETIF +############################## + ############################## # Start SUBSYSTEM LIBBASIC [SUBSYSTEM::LIBBASIC] @@ -17,8 +27,6 @@ ADD_OBJ_FILES = \ lib/debug.o \ lib/fault.o \ lib/getsmbpass.o \ - lib/interface.o \ - lib/interfaces.o \ lib/pidfile.o \ lib/signal.o \ lib/system.o \ @@ -57,6 +65,6 @@ ADD_OBJ_FILES = \ lib/server_mutex.o \ lib/idtree.o REQUIRED_SUBSYSTEMS = \ - LIBTDB CHARSET LIBREPLACE + LIBTDB CHARSET LIBREPLACE LIBNETIF # End SUBSYSTEM LIBBASIC ############################## diff --git a/source4/lib/interface.c b/source4/lib/interface.c deleted file mode 100644 index 72568912af..0000000000 --- a/source4/lib/interface.c +++ /dev/null @@ -1,341 +0,0 @@ -/* - Unix SMB/CIFS implementation. - multiple interface handling - Copyright (C) Andrew Tridgell 1992-1998 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -static struct iface_struct *probed_ifaces; -static int total_probed; - -static struct in_addr allones_ip; -struct in_addr loopback_ip; - -/* used for network interfaces */ -struct interface { - struct interface *next, *prev; - struct in_addr ip; - struct in_addr bcast; - struct in_addr nmask; -}; - -static struct interface *local_interfaces; - -#define ALLONES ((uint32_t)0xFFFFFFFF) -#define MKBCADDR(_IP, _NM) ((_IP & _NM) | (_NM ^ ALLONES)) -#define MKNETADDR(_IP, _NM) (_IP & _NM) - -/**************************************************************************** -Try and find an interface that matches an ip. If we cannot, return NULL - **************************************************************************/ -static struct interface *iface_find(struct in_addr ip, BOOL CheckMask) -{ - struct interface *i; - if (is_zero_ip(ip)) return local_interfaces; - - for (i=local_interfaces;i;i=i->next) - if (CheckMask) { - if (same_net(i->ip,ip,i->nmask)) return i; - } else if ((i->ip).s_addr == ip.s_addr) return i; - - return NULL; -} - - -/**************************************************************************** -add an interface to the linked list of interfaces -****************************************************************************/ -static void add_interface(struct in_addr ip, struct in_addr nmask) -{ - struct interface *iface; - if (iface_find(ip, False)) { - DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); - return; - } - - if (ip_equal(nmask, allones_ip)) { - DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip))); - return; - } - - iface = (struct interface *)malloc(sizeof(*iface)); - if (!iface) return; - - ZERO_STRUCTPN(iface); - - iface->ip = ip; - iface->nmask = nmask; - iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); - - DLIST_ADD(local_interfaces, iface); - - DEBUG(2,("added interface ip=%s ",inet_ntoa(iface->ip))); - DEBUG(2,("bcast=%s ",inet_ntoa(iface->bcast))); - DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask))); -} - - - -/**************************************************************************** -interpret a single element from a interfaces= config line - -This handles the following different forms: - -1) wildcard interface name -2) DNS name -3) IP/masklen -4) ip/mask -5) bcast/mask -****************************************************************************/ -static void interpret_interface(TALLOC_CTX *mem_ctx, const char *token) -{ - struct in_addr ip, nmask; - char *p; - int i, added=0; - - zero_ip(&ip); - zero_ip(&nmask); - - /* first check if it is an interface name */ - for (i=0;i 2) { - nmask = interpret_addr2(p); - } else { - nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES)); - } - - /* maybe the first component was a broadcast address */ - if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) || - ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) { - for (i=0;i 0) { - probed_ifaces = memdup(ifaces, sizeof(ifaces[0])*total_probed); - } - - /* if we don't have a interfaces line then use all broadcast capable - interfaces except loopback */ - if (!ptr || !*ptr || !**ptr) { - if (total_probed <= 0) { - DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); - exit(1); - } - for (i=0;i 0 )&& (n != total_probed || - memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) { - return True; - } - - return False; -} - - -/**************************************************************************** - check if an IP is one of mine - **************************************************************************/ -BOOL ismyip(struct in_addr ip) -{ - struct interface *i; - for (i=local_interfaces;i;i=i->next) - if (ip_equal(i->ip,ip)) return True; - return False; -} - -/**************************************************************************** - check if a packet is from a local (known) net - **************************************************************************/ -BOOL is_local_net(struct in_addr from) -{ - struct interface *i; - for (i=local_interfaces;i;i=i->next) { - if((from.s_addr & i->nmask.s_addr) == - (i->ip.s_addr & i->nmask.s_addr)) - return True; - } - return False; -} - -/**************************************************************************** - how many interfaces do we have - **************************************************************************/ -int iface_count(void) -{ - int ret = 0; - struct interface *i; - - for (i=local_interfaces;i;i=i->next) - ret++; - return ret; -} - -/**************************************************************************** - return IP of the Nth interface - **************************************************************************/ -struct in_addr *iface_n_ip(int n) -{ - struct interface *i; - - for (i=local_interfaces;i && n;i=i->next) - n--; - - if (i) return &i->ip; - return NULL; -} - -/**************************************************************************** - return bcast of the Nth interface - **************************************************************************/ -struct in_addr *iface_n_bcast(int n) -{ - struct interface *i; - - for (i=local_interfaces;i && n;i=i->next) - n--; - - if (i) return &i->bcast; - return NULL; -} - - -/* these 3 functions return the ip/bcast/nmask for the interface - most appropriate for the given ip address. If they can't find - an appropriate interface they return the requested field of the - first known interface. */ - -struct in_addr *iface_ip(struct in_addr ip) -{ - struct interface *i = iface_find(ip, True); - return(i ? &i->ip : &local_interfaces->ip); -} - -/* - return True if a IP is directly reachable on one of our interfaces -*/ -BOOL iface_local(struct in_addr ip) -{ - return iface_find(ip, True) ? True : False; -} diff --git a/source4/lib/interfaces.c b/source4/lib/interfaces.c deleted file mode 100644 index 89ed144eec..0000000000 --- a/source4/lib/interfaces.c +++ /dev/null @@ -1,407 +0,0 @@ -/* - Unix SMB/CIFS implementation. - return a list of network interfaces - Copyright (C) Andrew Tridgell 1998 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - - -/* working out the interfaces for a OS is an incredibly non-portable - thing. We have several possible implementations below, and autoconf - tries each of them to see what works - - Note that this file does _not_ include includes.h. That is so this code - can be called directly from the autoconf tests. That also means - this code cannot use any of the normal Samba debug stuff or defines. - This is standalone code. - -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef AUTOCONF_TEST -struct iface_struct { - char name[16]; - struct in_addr ip; - struct in_addr netmask; -}; -#else -#include "config.h" -#include "interfaces.h" -#endif - -#ifdef HAVE_SYS_TIME_H -#include -#endif - -#ifndef SIOCGIFCONF -#ifdef HAVE_SYS_SOCKIO_H -#include -#endif -#endif - -#ifdef HAVE_STDLIB_H -#include -#endif - -#ifdef HAVE_STRING_H -#include -#endif - -#ifdef HAVE_STRINGS_H -#include -#endif - -#ifdef __COMPAR_FN_T -#define QSORT_CAST (__compar_fn_t) -#endif - -#ifndef QSORT_CAST -#define QSORT_CAST (int (*)(const void *, const void *)) -#endif - -#if HAVE_IFACE_IFCONF - -/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 - V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. - - It probably also works on any BSD style system. */ - -/**************************************************************************** - get the netmask address for a local interface -****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - struct ifconf ifc; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; - int total = 0; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - n = ifc.ifc_len / sizeof(struct ifreq); - - /* Loop through interfaces, looking for given IP address */ - for (i=n-1;i>=0 && total < max_interfaces;i--) { - if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { - continue; - } - - iname = ifr[i].ifr_name; - ipaddr = (*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr; - - if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) { - continue; - } - - if (!(ifr[i].ifr_flags & IFF_UP)) { - continue; - } - - if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { - continue; - } - - nmask = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; - total++; - } - - close(fd); - - return total; -} - -#elif HAVE_IFACE_IFREQ - -#ifndef I_STR -#include -#endif - -/**************************************************************************** -this should cover most of the streams based systems -Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code -****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - struct ifreq ifreq; - struct strioctl strioctl; - char buff[8192]; - int fd, i, n; - struct ifreq *ifr=NULL; - int total = 0; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - strioctl.ic_cmd = SIOCGIFCONF; - strioctl.ic_dp = buff; - strioctl.ic_len = sizeof(buff); - if (ioctl(fd, I_STR, &strioctl) < 0) { - close(fd); - return -1; - } - - /* we can ignore the possible sizeof(int) here as the resulting - number of interface structures won't change */ - n = strioctl.ic_len / sizeof(struct ifreq); - - /* we will assume that the kernel returns the length as an int - at the start of the buffer if the offered size is a - multiple of the structure size plus an int */ - if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { - ifr = (struct ifreq *)(buff + sizeof(int)); - } else { - ifr = (struct ifreq *)buff; - } - - /* Loop through interfaces */ - - for (i = 0; isin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; - - total++; - } - - close(fd); - - return total; -} - -#elif HAVE_IFACE_AIX - -/**************************************************************************** -this one is for AIX (tested on 4.2) -****************************************************************************/ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - char buff[8192]; - int fd, i; - struct ifconf ifc; - struct ifreq *ifr=NULL; - struct in_addr ipaddr; - struct in_addr nmask; - char *iname; - int total = 0; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { - return -1; - } - - - ifc.ifc_len = sizeof(buff); - ifc.ifc_buf = buff; - - if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { - close(fd); - return -1; - } - - ifr = ifc.ifc_req; - - /* Loop through interfaces */ - i = ifc.ifc_len; - - while (i > 0 && total < max_interfaces) { - uint_t inc; - - inc = ifr->ifr_addr.sa_len; - - if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { - goto next; - } - - ipaddr = (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr; - iname = ifr->ifr_name; - - if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { - goto next; - } - - if (!(ifr->ifr_flags & IFF_UP)) { - goto next; - } - - if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { - goto next; - } - - nmask = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr; - - strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); - ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; - ifaces[total].ip = ipaddr; - ifaces[total].netmask = nmask; - - total++; - - next: - /* - * Patch from Archie Cobbs (archie@whistle.com). The - * addresses in the SIOCGIFCONF interface list have a - * minimum size. Usually this doesn't matter, but if - * your machine has tunnel interfaces, etc. that have - * a zero length "link address", this does matter. */ - - if (inc < sizeof(ifr->ifr_addr)) - inc = sizeof(ifr->ifr_addr); - inc += IFNAMSIZ; - - ifr = (struct ifreq*) (((char*) ifr) + inc); - i -= inc; - } - - - close(fd); - return total; -} - -#else /* a dummy version */ -static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - return -1; -} -#endif - - -static int iface_comp(struct iface_struct *i1, struct iface_struct *i2) -{ - int r; - r = strcmp(i1->name, i2->name); - if (r) return r; - r = ntohl(i1->ip.s_addr) - ntohl(i2->ip.s_addr); - if (r) return r; - r = ntohl(i1->netmask.s_addr) - ntohl(i2->netmask.s_addr); - return r; -} - -/* this wrapper is used to remove duplicates from the interface list generated - above */ -int get_interfaces(struct iface_struct *ifaces, int max_interfaces) -{ - int total, i, j; - - total = _get_interfaces(ifaces, max_interfaces); - if (total <= 0) return total; - - /* now we need to remove duplicates */ - qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CAST iface_comp); - - for (i=1;inext) + if (CheckMask) { + if (same_net(i->ip,tov4(ip),i->nmask)) return i; + } else if ((i->ip).s_addr == ip.s_addr) return i; + + return NULL; +} + + +/**************************************************************************** +add an interface to the linked list of interfaces +****************************************************************************/ +static void add_interface(struct in_addr ip, struct in_addr nmask) +{ + struct interface *iface; + if (iface_find(ip, False)) { + DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); + return; + } + + if (ip_equal(nmask, allones_ip)) { + DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip))); + return; + } + + iface = (struct interface *)malloc(sizeof(*iface)); + if (!iface) return; + + ZERO_STRUCTPN(iface); + + iface->ip = tov4(ip); + iface->nmask = tov4(nmask); + iface->bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); + + DLIST_ADD(local_interfaces, iface); + + DEBUG(2,("added interface ip=%s ",sys_inet_ntoa(iface->ip))); + DEBUG(2,("bcast=%s ",sys_inet_ntoa(iface->bcast))); + DEBUG(2,("nmask=%s\n",sys_inet_ntoa(iface->nmask))); +} + + + +/**************************************************************************** +interpret a single element from a interfaces= config line + +This handles the following different forms: + +1) wildcard interface name +2) DNS name +3) IP/masklen +4) ip/mask +5) bcast/mask +****************************************************************************/ +static void interpret_interface(TALLOC_CTX *mem_ctx, const char *token) +{ + struct in_addr ip, nmask; + char *p; + int i, added=0; + + ip.s_addr = 0; + nmask.s_addr = 0; + + /* first check if it is an interface name */ + for (i=0;i 2) { + nmask.s_addr = interpret_addr2(p).s_addr; + } else { + nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES)); + } + + /* maybe the first component was a broadcast address */ + if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) || + ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) { + for (i=0;i 0) { + probed_ifaces = memdup(ifaces, sizeof(ifaces[0])*total_probed); + } + + /* if we don't have a interfaces line then use all broadcast capable + interfaces except loopback */ + if (!ptr || !*ptr || !**ptr) { + if (total_probed <= 0) { + DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); + exit(1); + } + for (i=0;i 0 )&& (n != total_probed || + memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) { + return True; + } + + return False; +} + + +/**************************************************************************** + check if an IP is one of mine + **************************************************************************/ +BOOL ismyip(struct ipv4_addr ip) +{ + struct interface *i; + for (i=local_interfaces;i;i=i->next) + if (ip_equal(i->ip,ip)) return True; + return False; +} + +/**************************************************************************** + check if a packet is from a local (known) net + **************************************************************************/ +BOOL is_local_net(struct ipv4_addr from) +{ + struct interface *i; + for (i=local_interfaces;i;i=i->next) { + if((from.s_addr & i->nmask.s_addr) == + (i->ip.s_addr & i->nmask.s_addr)) + return True; + } + return False; +} + +/**************************************************************************** + how many interfaces do we have + **************************************************************************/ +int iface_count(void) +{ + int ret = 0; + struct interface *i; + + for (i=local_interfaces;i;i=i->next) + ret++; + return ret; +} + +/**************************************************************************** + return IP of the Nth interface + **************************************************************************/ +struct ipv4_addr *iface_n_ip(int n) +{ + struct interface *i; + + for (i=local_interfaces;i && n;i=i->next) + n--; + + if (i) return &i->ip; + return NULL; +} + +/**************************************************************************** + return bcast of the Nth interface + **************************************************************************/ +struct ipv4_addr *iface_n_bcast(int n) +{ + struct interface *i; + + for (i=local_interfaces;i && n;i=i->next) + n--; + + if (i) return &i->bcast; + return NULL; +} + + +/* these 3 functions return the ip/bcast/nmask for the interface + most appropriate for the given ip address. If they can't find + an appropriate interface they return the requested field of the + first known interface. */ + +struct ipv4_addr *iface_ip(struct ipv4_addr ip) +{ + struct in_addr in; + struct interface *i; + in.s_addr = ip.s_addr; + i = iface_find(in, True); + return(i ? &i->ip : &local_interfaces->ip); +} + +/* + return True if a IP is directly reachable on one of our interfaces +*/ +BOOL iface_local(struct ipv4_addr ip) +{ + struct in_addr in; + in.s_addr = ip.s_addr; + return iface_find(in, True) ? True : False; +} diff --git a/source4/lib/netif/netif.c b/source4/lib/netif/netif.c new file mode 100644 index 0000000000..729aeedbe3 --- /dev/null +++ b/source4/lib/netif/netif.c @@ -0,0 +1,400 @@ +/* + Unix SMB/CIFS implementation. + return a list of network interfaces + Copyright (C) Andrew Tridgell 1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +/* working out the interfaces for a OS is an incredibly non-portable + thing. We have several possible implementations below, and autoconf + tries each of them to see what works + + Note that this file does _not_ include includes.h. That is so this code + can be called directly from the autoconf tests. That also means + this code cannot use any of the normal Samba debug stuff or defines. + This is standalone code. + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef AUTOCONF_TEST +#include "lib/netif/netif.h" +#include "config.h" +#endif + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#ifndef SIOCGIFCONF +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#endif + +#ifdef HAVE_STDLIB_H +#include +#endif + +#ifdef HAVE_STRING_H +#include +#endif + +#ifdef HAVE_STRINGS_H +#include +#endif + +#ifdef __COMPAR_FN_T +#define QSORT_CAST (__compar_fn_t) +#endif + +#ifndef QSORT_CAST +#define QSORT_CAST (int (*)(const void *, const void *)) +#endif + +#if HAVE_IFACE_IFCONF + +/* this works for Linux 2.2, Solaris 2.5, SunOS4, HPUX 10.20, OSF1 + V4.0, Ultrix 4.4, SCO Unix 3.2, IRIX 6.4 and FreeBSD 3.2. + + It probably also works on any BSD style system. */ + +/**************************************************************************** + get the netmask address for a local interface +****************************************************************************/ +static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) +{ + struct ifconf ifc; + char buff[8192]; + int fd, i, n; + struct ifreq *ifr=NULL; + int total = 0; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + + n = ifc.ifc_len / sizeof(struct ifreq); + + /* Loop through interfaces, looking for given IP address */ + for (i=n-1;i>=0 && total < max_interfaces;i--) { + if (ioctl(fd, SIOCGIFADDR, &ifr[i]) != 0) { + continue; + } + + iname = ifr[i].ifr_name; + ipaddr = (*(struct sockaddr_in *)&ifr[i].ifr_addr).sin_addr; + + if (ioctl(fd, SIOCGIFFLAGS, &ifr[i]) != 0) { + continue; + } + + if (!(ifr[i].ifr_flags & IFF_UP)) { + continue; + } + + if (ioctl(fd, SIOCGIFNETMASK, &ifr[i]) != 0) { + continue; + } + + nmask = ((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr; + + strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); + ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; + ifaces[total].ip = ipaddr; + ifaces[total].netmask = nmask; + total++; + } + + close(fd); + + return total; +} + +#elif HAVE_IFACE_IFREQ + +#ifndef I_STR +#include +#endif + +/**************************************************************************** +this should cover most of the streams based systems +Thanks to Andrej.Borsenkow@mow.siemens.ru for several ideas in this code +****************************************************************************/ +static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) +{ + struct ifreq ifreq; + struct strioctl strioctl; + char buff[8192]; + int fd, i, n; + struct ifreq *ifr=NULL; + int total = 0; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + strioctl.ic_cmd = SIOCGIFCONF; + strioctl.ic_dp = buff; + strioctl.ic_len = sizeof(buff); + if (ioctl(fd, I_STR, &strioctl) < 0) { + close(fd); + return -1; + } + + /* we can ignore the possible sizeof(int) here as the resulting + number of interface structures won't change */ + n = strioctl.ic_len / sizeof(struct ifreq); + + /* we will assume that the kernel returns the length as an int + at the start of the buffer if the offered size is a + multiple of the structure size plus an int */ + if (n*sizeof(struct ifreq) + sizeof(int) == strioctl.ic_len) { + ifr = (struct ifreq *)(buff + sizeof(int)); + } else { + ifr = (struct ifreq *)buff; + } + + /* Loop through interfaces */ + + for (i = 0; isin_addr; + + strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); + ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; + ifaces[total].ip = ipaddr; + ifaces[total].netmask = nmask; + + total++; + } + + close(fd); + + return total; +} + +#elif HAVE_IFACE_AIX + +/**************************************************************************** +this one is for AIX (tested on 4.2) +****************************************************************************/ +static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) +{ + char buff[8192]; + int fd, i; + struct ifconf ifc; + struct ifreq *ifr=NULL; + struct in_addr ipaddr; + struct in_addr nmask; + char *iname; + int total = 0; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + return -1; + } + + + ifc.ifc_len = sizeof(buff); + ifc.ifc_buf = buff; + + if (ioctl(fd, SIOCGIFCONF, &ifc) != 0) { + close(fd); + return -1; + } + + ifr = ifc.ifc_req; + + /* Loop through interfaces */ + i = ifc.ifc_len; + + while (i > 0 && total < max_interfaces) { + uint_t inc; + + inc = ifr->ifr_addr.sa_len; + + if (ioctl(fd, SIOCGIFADDR, ifr) != 0) { + goto next; + } + + ipaddr = (*(struct sockaddr_in *) &ifr->ifr_addr).sin_addr; + iname = ifr->ifr_name; + + if (ioctl(fd, SIOCGIFFLAGS, ifr) != 0) { + goto next; + } + + if (!(ifr->ifr_flags & IFF_UP)) { + goto next; + } + + if (ioctl(fd, SIOCGIFNETMASK, ifr) != 0) { + goto next; + } + + nmask = ((struct sockaddr_in *)&ifr->ifr_addr)->sin_addr; + + strncpy(ifaces[total].name, iname, sizeof(ifaces[total].name)-1); + ifaces[total].name[sizeof(ifaces[total].name)-1] = 0; + ifaces[total].ip = ipaddr; + ifaces[total].netmask = nmask; + + total++; + + next: + /* + * Patch from Archie Cobbs (archie@whistle.com). The + * addresses in the SIOCGIFCONF interface list have a + * minimum size. Usually this doesn't matter, but if + * your machine has tunnel interfaces, etc. that have + * a zero length "link address", this does matter. */ + + if (inc < sizeof(ifr->ifr_addr)) + inc = sizeof(ifr->ifr_addr); + inc += IFNAMSIZ; + + ifr = (struct ifreq*) (((char*) ifr) + inc); + i -= inc; + } + + + close(fd); + return total; +} + +#else /* a dummy version */ +static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces) +{ + return -1; +} +#endif + + +static int iface_comp(struct iface_struct *i1, struct iface_struct *i2) +{ + int r; + r = strcmp(i1->name, i2->name); + if (r) return r; + r = ntohl(i1->ip.s_addr) - ntohl(i2->ip.s_addr); + if (r) return r; + r = ntohl(i1->netmask.s_addr) - ntohl(i2->netmask.s_addr); + return r; +} + +/* this wrapper is used to remove duplicates from the interface list generated + above */ +int get_interfaces(struct iface_struct *ifaces, int max_interfaces) +{ + int total, i, j; + + total = _get_interfaces(ifaces, max_interfaces); + if (total <= 0) return total; + + /* now we need to remove duplicates */ + qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CAST iface_comp); + + for (i=1;i +#include +#include + +struct iface_struct { + char name[16]; + struct in_addr ip; + struct in_addr netmask; +}; + +#define MAX_INTERFACES 128 + diff --git a/source4/lib/replace.c b/source4/lib/replace.c index c23c65c8c8..28c60130f8 100644 --- a/source4/lib/replace.c +++ b/source4/lib/replace.c @@ -326,7 +326,7 @@ duplicate a string #ifndef WITH_PTHREADS /* REWRITE: not thread safe */ #ifdef REPLACE_INET_NTOA -char *rep_inet_ntoa(struct in_addr ip) +char *rep_inet_ntoa(struct ipv4_addr ip) { uint8_t *p = (uint8_t *)&ip.s_addr; static char buf[18]; diff --git a/source4/lib/socket/access.c b/source4/lib/socket/access.c index f33f8d56b1..f5093177dd 100644 --- a/source4/lib/socket/access.c +++ b/source4/lib/socket/access.c @@ -32,6 +32,7 @@ */ #include "includes.h" +#include "system/network.h" #define FAIL (-1) #define ALLONES ((uint32_t)0xFFFFFFFF) diff --git a/source4/lib/socket/socket_ipv4.c b/source4/lib/socket/socket_ipv4.c index f9318a29bb..9777705419 100644 --- a/source4/lib/socket/socket_ipv4.c +++ b/source4/lib/socket/socket_ipv4.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "system/network.h" static NTSTATUS ipv4_tcp_init(struct socket_context *sock) { @@ -41,8 +42,8 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, uint32_t flags) { struct sockaddr_in srv_addr; - struct in_addr my_ip; - struct in_addr srv_ip; + struct ipv4_addr my_ip; + struct ipv4_addr srv_ip; int ret; my_ip = interpret_addr2(my_address); @@ -53,7 +54,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN my_addr.sin_len = sizeof(my_addr); #endif - my_addr.sin_addr = my_ip; + my_addr.sin_addr.s_addr = my_ip.s_addr; my_addr.sin_port = htons(my_port); my_addr.sin_family = PF_INET; @@ -69,7 +70,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN srv_addr.sin_len = sizeof(srv_addr); #endif - srv_addr.sin_addr = srv_ip; + srv_addr.sin_addr.s_addr= srv_ip.s_addr; srv_addr.sin_port = htons(srv_port); srv_addr.sin_family = PF_INET; @@ -95,7 +96,7 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock, int queue_size, uint32_t flags) { struct sockaddr_in my_addr; - struct in_addr ip_addr; + struct ipv4_addr ip_addr; int ret; ip_addr = interpret_addr2(my_address); @@ -104,7 +105,7 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock, #ifdef HAVE_SOCK_SIN_LEN my_addr.sin_len = sizeof(my_addr); #endif - my_addr.sin_addr = ip_addr; + my_addr.sin_addr.s_addr = ip_addr.s_addr; my_addr.sin_port = htons(port); my_addr.sin_family = PF_INET; diff --git a/source4/lib/socket/socket_ipv6.c b/source4/lib/socket/socket_ipv6.c index 268212dcca..75e6fcab5c 100644 --- a/source4/lib/socket/socket_ipv6.c +++ b/source4/lib/socket/socket_ipv6.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" static struct in6_addr interpret_addr6(const char *name) { diff --git a/source4/lib/system.c b/source4/lib/system.c index 1407e7474e..2baa412622 100644 --- a/source4/lib/system.c +++ b/source4/lib/system.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" /* The idea is that this file will eventually have wrappers around all @@ -533,3 +534,24 @@ int sys_dup2(int oldfd, int newfd) #endif } + +const char *sys_inet_ntoa(struct ipv4_addr in) +{ + struct in_addr in2; + in2.s_addr = in.s_addr; + return inet_ntoa(in2); +} + +uint32_t sys_inet_addr(const char *s) +{ + return inet_addr(s); +} + +struct ipv4_addr sys_inet_makeaddr(int net, int host) +{ + struct in_addr in; + struct ipv4_addr in2; + in = inet_makeaddr(net, host); + in2.s_addr = in.s_addr; + return in2; +} diff --git a/source4/lib/util.c b/source4/lib/util.c index 07dc182580..7b6396fa93 100644 --- a/source4/lib/util.c +++ b/source4/lib/util.c @@ -23,6 +23,7 @@ */ #include "includes.h" +#include "system/network.h" /**************************************************************************n Find a suitable temporary directory. The result should be copied immediately @@ -421,7 +422,7 @@ uint32_t interpret_addr(const char *str) /* if it's in the form of an IP address then get the lib to interpret it */ if (is_ipaddress(str)) { - res = inet_addr(str); + res = sys_inet_addr(str); } else { /* otherwise assume it's a network name of some sort and use sys_gethostbyname */ @@ -446,9 +447,9 @@ uint32_t interpret_addr(const char *str) /******************************************************************* A convenient addition to interpret_addr(). ******************************************************************/ -struct in_addr interpret_addr2(const char *str) +struct ipv4_addr interpret_addr2(const char *str) { - struct in_addr ret; + struct ipv4_addr ret; uint32_t a = interpret_addr(str); ret.s_addr = a; return ret; @@ -458,7 +459,7 @@ struct in_addr interpret_addr2(const char *str) Check if an IP is the 0.0.0.0. ******************************************************************/ -BOOL is_zero_ip(struct in_addr ip) +BOOL is_zero_ip(struct ipv4_addr ip) { uint32_t a; putip((char *)&a,(char *)&ip); @@ -469,9 +470,9 @@ BOOL is_zero_ip(struct in_addr ip) Set an IP to 0.0.0.0. ******************************************************************/ -void zero_ip(struct in_addr *ip) +void zero_ip(struct ipv4_addr *ip) { - *ip = inet_makeaddr(0,0); + *ip = sys_inet_makeaddr(0,0); return; } @@ -480,7 +481,7 @@ void zero_ip(struct in_addr *ip) Are two IPs on the same subnet? ********************************************************************/ -BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask) +BOOL same_net(struct ipv4_addr ip1,struct ipv4_addr ip2,struct ipv4_addr mask) { uint32_t net1,net2,nmask; diff --git a/source4/lib/util_sock.c b/source4/lib/util_sock.c index 0cb23920f1..dbd71b58b6 100644 --- a/source4/lib/util_sock.c +++ b/source4/lib/util_sock.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "system/network.h" /**************************************************************************** @@ -156,7 +157,7 @@ void set_socket_options(int fd, const char *options) ****************************************************************************/ ssize_t read_udp_socket(int fd, char *buf, size_t len, - struct in_addr *from_addr, int *from_port) + struct ipv4_addr *from_addr, int *from_port) { ssize_t ret; struct sockaddr_in sock; @@ -169,7 +170,7 @@ ssize_t read_udp_socket(int fd, char *buf, size_t len, } if (from_addr) { - *from_addr = sock.sin_addr; + from_addr->s_addr = sock.sin_addr.s_addr; } if (from_port) { *from_port = ntohs(sock.sin_port); @@ -337,7 +338,7 @@ int open_socket_in( int type, int port, int dlevel, uint32_t socket_addr, BOOL r /**************************************************************************** create an outgoing socket. timeout is in milliseconds. **************************************************************************/ -int open_socket_out(int type, struct in_addr *addr, int port, int timeout) +int open_socket_out(int type, struct ipv4_addr *addr, int port, int timeout) { struct sockaddr_in sock_out; int res,ret; @@ -360,7 +361,7 @@ int open_socket_out(int type, struct in_addr *addr, int port, int timeout) /* set it non-blocking */ set_blocking(res,False); - DEBUG(3,("Connecting to %s at port %d\n",inet_ntoa(*addr),port)); + DEBUG(3,("Connecting to %s at port %d\n", sys_inet_ntoa(*addr),port)); /* and connect it to the destination */ connect_again: @@ -375,7 +376,7 @@ connect_again: if (ret < 0 && (errno == EINPROGRESS || errno == EALREADY || errno == EAGAIN)) { - DEBUG(1,("timeout connecting to %s:%d\n",inet_ntoa(*addr),port)); + DEBUG(1,("timeout connecting to %s:%d\n", sys_inet_ntoa(*addr),port)); close(res); return -1; } @@ -389,7 +390,7 @@ connect_again: if (ret < 0) { DEBUG(2,("error connecting to %s:%d (%s)\n", - inet_ntoa(*addr),port,strerror(errno))); + sys_inet_ntoa(*addr),port,strerror(errno))); close(res); return -1; } @@ -408,7 +409,7 @@ int open_udp_socket(const char *host, int port) int type = SOCK_DGRAM; struct sockaddr_in sock_out; int res; - struct in_addr addr; + struct ipv4_addr addr; TALLOC_CTX *mem_ctx; mem_ctx = talloc_init("open_udp_socket"); @@ -442,7 +443,7 @@ int open_udp_socket(const char *host, int port) matchname - determine if host name matches IP address. Used to confirm a hostname lookup to prevent spoof attacks ******************************************************************/ -static BOOL matchname(char *remotehost, struct in_addr addr) +static BOOL matchname(char *remotehost, struct ipv4_addr addr) { struct hostent *hp; int i; @@ -480,7 +481,7 @@ static BOOL matchname(char *remotehost, struct in_addr addr) */ DEBUG(0,("host name/address mismatch: %s != %s\n", - inet_ntoa(addr), hp->h_name)); + sys_inet_ntoa(addr), hp->h_name)); return False; } @@ -492,7 +493,7 @@ char *get_socket_name(TALLOC_CTX *mem_ctx, int fd, BOOL force_lookup) { char *name_buf; struct hostent *hp; - struct in_addr addr; + struct ipv4_addr addr; char *p; /* reverse lookups can be *very* expensive, and in many diff --git a/source4/lib/util_strlist.c b/source4/lib/util_strlist.c index 12fb0946e2..0b32955ac2 100644 --- a/source4/lib/util_strlist.c +++ b/source4/lib/util_strlist.c @@ -228,7 +228,7 @@ BOOL str_list_substitute(char **list, const char *pattern, const char *insert) * reallocated to new length **/ -char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) +char* ipstr_list_add(char** ipstr_list, const struct ipv4_addr *ip) { char* new_ipstr = NULL; @@ -237,10 +237,10 @@ char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) /* attempt to convert ip to a string and append colon separator to it */ if (*ipstr_list) { - asprintf(&new_ipstr, "%s%s%s", *ipstr_list, IPSTR_LIST_SEP,inet_ntoa(*ip)); + asprintf(&new_ipstr, "%s%s%s", *ipstr_list, IPSTR_LIST_SEP,sys_inet_ntoa(*ip)); SAFE_FREE(*ipstr_list); } else { - asprintf(&new_ipstr, "%s", inet_ntoa(*ip)); + asprintf(&new_ipstr, "%s", sys_inet_ntoa(*ip)); } *ipstr_list = new_ipstr; return *ipstr_list; @@ -256,7 +256,7 @@ char* ipstr_list_add(char** ipstr_list, const struct in_addr *ip) * @return pointer to allocated ip string **/ -char* ipstr_list_make(char** ipstr_list, const struct in_addr* ip_list, int ip_count) +char* ipstr_list_make(char** ipstr_list, const struct ipv4_addr* ip_list, int ip_count) { int i; @@ -283,7 +283,7 @@ char* ipstr_list_make(char** ipstr_list, const struct in_addr* ip_list, int ip_c * @return number of succesfully parsed addresses **/ -int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list) +int ipstr_list_parse(const char* ipstr_list, struct ipv4_addr** ip_list) { fstring token_str; int count; @@ -294,14 +294,14 @@ int ipstr_list_parse(const char* ipstr_list, struct in_addr** ip_list) next_token(&ipstr_list, token_str, IPSTR_LIST_SEP, FSTRING_LEN); count++) { - struct in_addr addr; + struct ipv4_addr addr; /* convert single token to ip address */ - if ( (addr.s_addr = inet_addr(token_str)) == INADDR_NONE ) + if ( (addr.s_addr = sys_inet_addr(token_str)) == INADDR_NONE ) break; /* prepare place for another in_addr structure */ - *ip_list = Realloc(*ip_list, (count + 1) * sizeof(struct in_addr)); + *ip_list = Realloc(*ip_list, (count + 1) * sizeof(struct ipv4_addr)); if (!*ip_list) return -1; (*ip_list)[count] = addr; diff --git a/source4/lib/wins_srv.c b/source4/lib/wins_srv.c index eb7f280e6f..d8be9e61d6 100644 --- a/source4/lib/wins_srv.c +++ b/source4/lib/wins_srv.c @@ -68,12 +68,12 @@ #define WINS_SRV_FMT "WINS_SRV_DEAD/%s,%s" /* wins_ip,src_ip */ -static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip) +static char *wins_srv_keystr(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr; - if (asprintf(&keystr, WINS_SRV_FMT, inet_ntoa(wins_ip), - inet_ntoa(src_ip)) == -1) { + if (asprintf(&keystr, WINS_SRV_FMT, sys_inet_ntoa(wins_ip), + sys_inet_ntoa(src_ip)) == -1) { DEBUG(0, ("wins_srv_is_dead: malloc error\n")); return NULL; } @@ -85,7 +85,7 @@ static char *wins_srv_keystr(struct in_addr wins_ip, struct in_addr src_ip) see if an ip is on the dead list */ -BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) +BOOL wins_srv_is_dead(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr = wins_srv_keystr(wins_ip, src_ip); BOOL result; @@ -95,7 +95,7 @@ BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) result = gencache_get(keystr, NULL, NULL); SAFE_FREE(keystr); - DEBUG(4, ("wins_srv_is_dead: %s is %s\n", inet_ntoa(wins_ip), + DEBUG(4, ("wins_srv_is_dead: %s is %s\n", sys_inet_ntoa(wins_ip), result ? "dead" : "alive")); return result; @@ -105,7 +105,7 @@ BOOL wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip) /* mark a wins server as being alive (for the moment) */ -void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip) +void wins_srv_alive(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr = wins_srv_keystr(wins_ip, src_ip); @@ -113,13 +113,13 @@ void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip) SAFE_FREE(keystr); DEBUG(4, ("wins_srv_alive: marking wins server %s alive\n", - inet_ntoa(wins_ip))); + sys_inet_ntoa(wins_ip))); } /* mark a wins server as temporarily dead */ -void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip) +void wins_srv_died(struct ipv4_addr wins_ip, struct ipv4_addr src_ip) { char *keystr; @@ -133,7 +133,7 @@ void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip) SAFE_FREE(keystr); DEBUG(4,("Marking wins server %s dead for %u seconds from source %s\n", - inet_ntoa(wins_ip), DEATH_TIME, inet_ntoa(src_ip))); + sys_inet_ntoa(wins_ip), DEATH_TIME, sys_inet_ntoa(src_ip))); } /* @@ -160,7 +160,7 @@ uint_t wins_srv_count(void) attached */ struct tagged_ip { fstring tag; - struct in_addr ip; + struct ipv4_addr ip; }; /* @@ -267,7 +267,7 @@ void wins_srv_tags_free(char **list) return the IP of the currently active wins server for the given tag, or the zero IP otherwise */ -struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) +struct ipv4_addr wins_srv_ip_tag(const char *tag, struct ipv4_addr src_ip) { const char **list; int i; @@ -276,13 +276,13 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) /* if we are a wins server then we always just talk to ourselves */ if (lp_wins_support()) { - extern struct in_addr loopback_ip; + extern struct ipv4_addr loopback_ip; return loopback_ip; } list = lp_wins_server_list(); if (!list || !list[0]) { - struct in_addr ip; + struct ipv4_addr ip; zero_ip(&ip); return ip; } @@ -297,11 +297,11 @@ struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip) } if (!wins_srv_is_dead(t_ip.ip, src_ip)) { char *src_name; - src_name = talloc_strdup(mem_ctx, inet_ntoa(src_ip)); + src_name = talloc_strdup(mem_ctx, sys_inet_ntoa(src_ip)); DEBUG(6,("Current wins server for tag '%s' with source %s is %s\n", tag, src_name, - inet_ntoa(t_ip.ip))); + sys_inet_ntoa(t_ip.ip))); goto exit; } } -- cgit