Unix SMB/Netbios implementation.
Version 1.9.
multiple interface handling
- Copyright (C) Andrew Tridgell 1992-1995
+ Copyright (C) Andrew Tridgell 1992-1997
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
extern int DEBUGLEVEL;
struct in_addr ipzero;
-struct in_addr ipgrp;
+struct in_addr wins_ip;
static struct in_addr default_ip;
static struct in_addr default_bcast;
static struct in_addr default_nmask;
static BOOL got_bcast=False;
static BOOL got_nmask=False;
-static struct interface {
- struct interface *next;
- struct in_addr ip;
- struct in_addr bcast;
- struct in_addr nmask;
-} *interfaces = NULL;
+struct interface *local_interfaces = NULL;
+
struct interface *last_iface;
/****************************************************************************
****************************************************************************/
static void default_netmask(struct in_addr *inm, struct in_addr *iad)
{
- unsigned long ad = ntohl(iad->s_addr);
- unsigned long nm;
+ uint32 ad = ntohl(iad->s_addr);
+ uint32 nm;
/*
** Guess a netmask based on the class of the IP address given.
*/
}
}
}
-#elif defined(__FreeBSD__) || defined(NETBSD)
+#elif defined(__FreeBSD__) || defined(NETBSD) || defined(AMIGA) || defined(_AIX41)
ifc.ifc_len = sizeof(buff);
ifc.ifc_buf = buff;
if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {
/* sanity check on the netmask */
{
- unsigned long nm = ntohl(if_nmask->s_addr);
+ uint32 nm = ntohl(if_nmask->s_addr);
if ((nm >> 24) != 0xFF) {
DEBUG(0,("Impossible netmask %s - using defaults\n",inet_ntoa(*if_nmask)));
default_netmask(if_nmask, if_ipaddr);
all MS operating systems do, we have to comply even if the unix
box is setup differently */
{
- unsigned long ad = ntohl(if_ipaddr->s_addr);
- unsigned long nm = ntohl(if_nmask->s_addr);
- unsigned long bc = (ad & nm) | (0xffffffff & ~nm);
+ uint32 ad = ntohl(if_ipaddr->s_addr);
+ uint32 nm = ntohl(if_nmask->s_addr);
+ uint32 bc = (ad & nm) | (0xffffffff & ~nm);
if_bcast->s_addr = htonl(bc);
}
-
/****************************************************************************
load a list of network interfaces
****************************************************************************/
-void load_interfaces(void)
+static void interpret_interfaces(char *s, struct interface **interfaces,
+ char *description)
{
- char *s = lp_interfaces();
char *ptr = s;
fstring token;
struct interface *iface;
struct in_addr ip;
ipzero = *interpret_addr2("0.0.0.0");
- ipgrp = *interpret_addr2("255.255.255.255");
+ wins_ip = *interpret_addr2("255.255.255.255");
while (next_token(&ptr,token,NULL)) {
/* parse it into an IP address/netmasklength pair */
/* maybe we already have it listed */
{
struct interface *i;
- for (i=interfaces;i;i=i->next)
+ for (i=(*interfaces);i;i=i->next)
if (ip_equal(ip,i->ip)) break;
if (i) continue;
}
iface->bcast.s_addr = iface->ip.s_addr | ~iface->nmask.s_addr;
iface->next = NULL;
- if (!interfaces) {
- interfaces = iface;
+ if (!(*interfaces)) {
+ (*interfaces) = iface;
} else {
last_iface->next = iface;
}
last_iface = iface;
- DEBUG(1,("Added interface ip=%s ",inet_ntoa(iface->ip)));
+ DEBUG(1,("Added %s ip=%s ",description,inet_ntoa(iface->ip)));
DEBUG(1,("bcast=%s ",inet_ntoa(iface->bcast)));
DEBUG(1,("nmask=%s\n",inet_ntoa(iface->nmask)));
}
- if (interfaces) return;
+ if (*interfaces) return;
/* setup a default interface */
iface = (struct interface *)malloc(sizeof(*iface));
DEBUG(2,("Warning: inconsistant interface %s\n",inet_ntoa(iface->ip)));
}
- interfaces = last_iface = iface;
+ iface->next = NULL;
+ (*interfaces) = last_iface = iface;
DEBUG(1,("Added interface ip=%s ",inet_ntoa(iface->ip)));
DEBUG(1,("bcast=%s ",inet_ntoa(iface->bcast)));
}
+/****************************************************************************
+load the remote and local interfaces
+****************************************************************************/
+void load_interfaces(void)
+{
+ /* add the machine's interfaces to local interface structure*/
+ interpret_interfaces(lp_interfaces(), &local_interfaces,"interface");
+}
+
+
/****************************************************************************
override the defaults
**************************************************************************/
BOOL ismyip(struct in_addr ip)
{
struct interface *i;
- for (i=interfaces;i;i=i->next)
+ for (i=local_interfaces;i;i=i->next)
if (ip_equal(i->ip,ip)) return True;
return False;
}
BOOL ismybcast(struct in_addr bcast)
{
struct interface *i;
- for (i=interfaces;i;i=i->next)
+ for (i=local_interfaces;i;i=i->next)
if (ip_equal(i->bcast,bcast)) return True;
return False;
}
int ret = 0;
struct interface *i;
- for (i=interfaces;i;i=i->next)
+ for (i=local_interfaces;i;i=i->next)
ret++;
return ret;
}
{
struct interface *i;
- for (i=interfaces;i && n;i=i->next)
+ for (i=local_interfaces;i && n;i=i->next)
n--;
if (i) return &i->ip;
static struct interface *iface_find(struct in_addr ip)
{
struct interface *i;
- if (zero_ip(ip)) return interfaces;
+ if (zero_ip(ip)) return local_interfaces;
- for (i=interfaces;i;i=i->next)
+ for (i=local_interfaces;i;i=i->next)
if (same_net(i->ip,ip,i->nmask)) return i;
- return interfaces;
+ return local_interfaces;
}
-
/* these 3 functions return the ip/bcast/nmask for the interface
most appropriate for the given ip address */
}
+