#include "includes.h"
-extern struct in_addr loopback_ip;
extern int global_nmb_port;
/* This is the broadcast subnets database. */
nmb_sock = -1;
dgram_sock = -1;
} else {
+ struct sockaddr_storage ss;
+
+ in_addr_to_sockaddr_storage(&ss, myip);
+
/*
* Attempt to open the sockets on port 137/138 for this interface
* and bind them.
* Fail the subnet creation if this fails.
*/
- if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) {
+ if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, &ss,true)) == -1) {
if( DEBUGLVL( 0 ) ) {
Debug1( "nmbd_subnetdb:make_subnet()\n" );
Debug1( " Failed to open nmb socket on interface %s ", inet_ntoa(myip) );
return NULL;
}
- if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) {
+ if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, &ss, true)) == -1) {
if( DEBUGLVL( 0 ) ) {
Debug1( "nmbd_subnetdb:make_subnet()\n" );
Debug1( " Failed to open dgram socket on interface %s ", inet_ntoa(myip) );
Create a normal subnet
**************************************************************************/
-struct subnet_record *make_normal_subnet(struct interface *iface)
+struct subnet_record *make_normal_subnet(const struct interface *iface)
{
+
struct subnet_record *subrec;
+ const struct in_addr *pip = &((const struct sockaddr_in *)&iface->ip)->sin_addr;
+ const struct in_addr *pbcast = &((const struct sockaddr_in *)&iface->bcast)->sin_addr;
+ const struct in_addr *pnmask = &((const struct sockaddr_in *)&iface->netmask)->sin_addr;
- subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET,
- iface->ip, iface->bcast, iface->nmask);
+ subrec = make_subnet(inet_ntoa(*pip), NORMAL_SUBNET,
+ *pip, *pbcast, *pnmask);
if (subrec) {
add_subnet(subrec);
}
Create subnet entries.
**************************************************************************/
-BOOL create_subnets(void)
-{
- int num_interfaces = iface_count();
+bool create_subnets(void)
+{
+ /* We only count IPv4 interfaces whilst we're waiting. */
+ int num_interfaces = iface_count_v4();
int i;
struct in_addr unicast_ip, ipzero;
- if(num_interfaces == 0) {
- void (*saved_handler)(int);
+ try_interfaces_again:
+ if (iface_count_v4() == 0) {
DEBUG(0,("create_subnets: No local interfaces !\n"));
DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n"));
+ }
+
+ /* We only count IPv4 interfaces here. */
+ while (iface_count_v4() == 0) {
+ void (*saved_handler)(int);
- /*
+ /*
* Whilst we're waiting for an interface, allow SIGTERM to
* cause us to exit.
*/
saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );
- while (iface_count() == 0) {
- sleep(5);
- load_interfaces();
- }
+ sleep(5);
+ load_interfaces();
- /*
+ /*
* We got an interface, restore our normal term handler.
*/
CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
}
+ /*
+ * Here we count v4 and v6 - we know there's at least one
+ * IPv4 interface and we filter on it below.
+ */
num_interfaces = iface_count();
- /*
+ /*
* Create subnets from all the local interfaces and thread them onto
- * the linked list.
+ * the linked list.
*/
for (i = 0 ; i < num_interfaces; i++) {
- struct interface *iface = get_interface(i);
+ const struct interface *iface = get_interface(i);
if (!iface) {
DEBUG(2,("create_subnets: can't get interface %d.\n", i ));
continue;
}
+ /* Ensure we're only dealing with IPv4 here. */
+ if (iface->ip.ss_family != AF_INET) {
+ DEBUG(2,("create_subnets: "
+ "ignoring non IPv4 interface.\n"));
+ continue;
+ }
+
/*
* We don't want to add a loopback interface, in case
* someone has added 127.0.0.1 for smbd, nmbd needs to
* ignore it here. JRA.
*/
- if (ip_equal(iface->ip, loopback_ip)) {
+ if (is_loopback_addr(&iface->ip)) {
DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
continue;
}
/* We must have at least one subnet. */
if (subnetlist == NULL) {
- DEBUG(0,("create_subnets: unable to create any subnet from "
- "given interfaces. nmbd is terminating\n"));
- return False;
+ void (*saved_handler)(int);
+
+ DEBUG(0,("create_subnets: Unable to create any subnet from "
+ "given interfaces. Is your interface line in "
+ "smb.conf correct ?\n"));
+
+ saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );
+
+ sleep(5);
+ load_interfaces();
+
+ CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
+ goto try_interfaces_again;
}
if (lp_we_are_a_wins_server()) {
- /* Pick the first interface ip address as the WINS server ip. */
- struct in_addr *nip = iface_n_ip(0);
+ /* Pick the first interface IPv4 address as the WINS server ip. */
+ const struct in_addr *nip = first_ipv4_iface();
if (!nip) {
return False;
/* note that we do not set the wins server IP here. We just
set it at zero and let the wins registration code cope
with getting the IPs right for each packet */
- zero_ip(&unicast_ip);
+ zero_ip_v4(&unicast_ip);
}
/*
unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET,
unicast_ip, unicast_ip, unicast_ip);
- zero_ip(&ipzero);
+ zero_ip_v4(&ipzero);
remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
REMOTE_BROADCAST_SUBNET,
Function to tell us if we can use the unicast subnet.
******************************************************************/
-BOOL we_are_a_wins_client(void)
+bool we_are_a_wins_client(void)
{
if (wins_srv_count() > 0) {
return True;