From d75b175cf9a41e744c4f6445667e4ade72d42ac6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Oct 2007 18:23:22 +0000 Subject: r25508: Reformatting. Jeremy. (This used to be commit b412ba6fb3e526f5cd83e6cabd952ad7c303c346) --- source3/lib/interface.c | 124 +++++++++++++++++++++++++++--------------------- 1 file changed, 69 insertions(+), 55 deletions(-) (limited to 'source3') diff --git a/source3/lib/interface.c b/source3/lib/interface.c index c187583923..5982d82e47 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -1,18 +1,18 @@ -/* +/* 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 3 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, see . */ @@ -32,8 +32,9 @@ static struct interface *local_interfaces; #define MKNETADDR(_IP, _NM) (_IP & _NM) /**************************************************************************** -Try and find an interface that matches an ip. If we cannot, return NULL - **************************************************************************/ + 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; @@ -47,10 +48,10 @@ static struct interface *iface_find(struct in_addr ip, BOOL CheckMask) return NULL; } - /**************************************************************************** -add an interface to the linked list of interfaces + Add an interface to the linked list of interfaces. ****************************************************************************/ + static void add_interface(struct in_addr ip, struct in_addr nmask) { struct interface *iface; @@ -61,14 +62,15 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) #if !defined(__s390__) if (ip_equal(nmask, allones_ip)) { - DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip))); + DEBUG(3,("not adding non-broadcast interface %s\n", + inet_ntoa(ip))); return; } #endif iface = SMB_MALLOC_P(struct interface); if (!iface) return; - + ZERO_STRUCTPN(iface); iface->ip = ip; @@ -79,22 +81,21 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) 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))); + DEBUG(2,("nmask=%s\n",inet_ntoa(iface->nmask))); } - - /**************************************************************************** -interpret a single element from a interfaces= config line + Interpret a single element from a interfaces= config line. -This handles the following different forms: + This handles the following different forms: -1) wildcard interface name -2) DNS name -3) IP/masklen -4) ip/mask -5) bcast/mask + 1) wildcard interface name + 2) DNS name + 3) IP/masklen + 4) ip/mask + 5) bcast/mask ****************************************************************************/ + static void interpret_interface(char *token) { struct in_addr ip, nmask; @@ -119,11 +120,11 @@ static void interpret_interface(char *token) if (!p) { ip = *interpret_addr2(token); for (i=0;i 0) { - probed_ifaces = (struct iface_struct *)memdup(ifaces, sizeof(ifaces[0])*total_probed); + probed_ifaces = (struct iface_struct *)memdup(ifaces, + sizeof(ifaces[0])*total_probed); if (!probed_ifaces) { DEBUG(0,("ERROR: memdup failed\n")); exit(1); } } - /* if we don't have a interfaces line then use all broadcast capable + /* 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")); + DEBUG(0,("ERROR: Could not determine network " + "interfaces, you must use a interfaces config line\n")); exit(1); } for (i=0;inext) { - if((from.s_addr & i->nmask.s_addr) == + if((from.s_addr & i->nmask.s_addr) == (i->ip.s_addr & i->nmask.s_addr)) return True; } @@ -288,8 +298,9 @@ BOOL is_local_net(struct in_addr from) } /**************************************************************************** - how many interfaces do we have - **************************************************************************/ + How many interfaces do we have +**************************************************************************/ + int iface_count(void) { int ret = 0; @@ -301,12 +312,13 @@ int iface_count(void) } /**************************************************************************** - return the Nth interface - **************************************************************************/ + Return the Nth interface. +**************************************************************************/ + struct interface *get_interface(int n) -{ +{ struct interface *i; - + for (i=local_interfaces;i && n;i=i->next) n--; @@ -315,12 +327,13 @@ struct interface *get_interface(int n) } /**************************************************************************** - return IP of the Nth interface - **************************************************************************/ + 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--; @@ -329,12 +342,13 @@ struct in_addr *iface_n_ip(int n) } /**************************************************************************** - return bcast of the Nth interface - **************************************************************************/ + 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--; @@ -342,7 +356,6 @@ struct in_addr *iface_n_bcast(int n) 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 @@ -357,6 +370,7 @@ struct in_addr *iface_ip(struct in_addr 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; -- cgit