From c6abd2055c5f7f99f8afa3a837ef6103adf66eb5 Mon Sep 17 00:00:00 2001 From: Ted Lemon Date: Thu, 20 Nov 1997 04:19:21 +0000 Subject: [PATCH] Compute network number and (if not offered by server) broadcast address for linux client script --- client/dhclient.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/client/dhclient.c b/client/dhclient.c index 3e71acfa..92f8fdd5 100644 --- a/client/dhclient.c +++ b/client/dhclient.c @@ -56,7 +56,7 @@ #ifndef lint static char copyright[] = -"$Id: dhclient.c,v 1.42 1997/10/20 22:00:17 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: dhclient.c,v 1.43 1997/11/20 04:19:21 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -1829,6 +1829,46 @@ void script_write_params (ip, prefix, lease) fprintf (scriptFile, "%sip_address=\"%s\"\n", prefix, piaddr (lease -> address)); fprintf (scriptFile, "export %sip_address\n", prefix); + + /* For the benefit of Linux (and operating systems which may + have similar needs), compute the network address based on + the supplied ip address and netmask, if provided. Also + compute the broadcast address (the host address all ones + broadcast address, not the host address all zeroes + broadcast address). */ + + if (lease -> options [DHO_SUBNET_MASK].len && + (lease -> options [DHO_SUBNET_MASK].len < + sizeof lease -> address.iabuf)) { + struct iaddr netmask, subnet, broadcast; + + memcpy (netmask.iabuf, + lease -> options [DHO_SUBNET_MASK].data, + lease -> options [DHO_SUBNET_MASK].len); + netmask.len = lease -> options [DHO_SUBNET_MASK].len; + + subnet = subnet_number (lease -> address, netmask); + if (subnet.len) { + fprintf (scriptFile, "%snetwork_number=\"%s\";\n", + prefix, piaddr (subnet)); + fprintf (scriptFile, "export %snetwork_number\n", + prefix); + + if (!lease -> options [DHO_BROADCAST_ADDRESS].len) { + broadcast = broadcast_addr (subnet, netmask); + if (broadcast.len) { + fprintf (scriptFile, + "%s%s=\"%s\";\n", prefix, + "broadcast_address", + piaddr (broadcast)); + fprintf (scriptFile, + "export %s%s\n", prefix, + "broadcast_address"); + } + } + } + } + if (lease -> filename) { fprintf (scriptFile, "%sfilename=\"%s\";\n", prefix, lease -> filename);