aboutsummaryrefslogtreecommitdiff
path: root/contrib/isc-dhcp/client/dhclient.c
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>1999-05-02 09:03:51 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>1999-05-02 09:03:51 +0000
commitf96b6240a8bcccf45bd5180f78bf9512c3339a18 (patch)
tree75c1496cd45733a402c0090488b97a6f92f09d2f /contrib/isc-dhcp/client/dhclient.c
parentcb1dd5d1b3d7429a2e45c616552023c5729be0c5 (diff)
downloadsrc-f96b6240a8bcccf45bd5180f78bf9512c3339a18.tar.gz
src-f96b6240a8bcccf45bd5180f78bf9512c3339a18.zip
Virgin import of ISC-DHCP v2.0b1pl27
Notes
Notes: svn path=/vendor/isc-dhcp/dist/; revision=46275
Diffstat (limited to 'contrib/isc-dhcp/client/dhclient.c')
-rw-r--r--contrib/isc-dhcp/client/dhclient.c127
1 files changed, 85 insertions, 42 deletions
diff --git a/contrib/isc-dhcp/client/dhclient.c b/contrib/isc-dhcp/client/dhclient.c
index 4d33f413e5d4..9ac4aea17a8d 100644
--- a/contrib/isc-dhcp/client/dhclient.c
+++ b/contrib/isc-dhcp/client/dhclient.c
@@ -56,7 +56,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhclient.c,v 1.44.2.25 1999/03/05 16:13:54 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.44.2.37 1999/04/24 16:55:19 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -92,11 +92,11 @@ int save_scripts;
static char copyright[] =
"Copyright 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.";
static char arr [] = "All rights reserved.";
-static char message [] = "Internet Software Consortium DHCP Client V2.0b1pl18";
-static char contrib [] = "\nPlease contribute if you find this software useful.";
-static char url [] = "For info, please visit http://www.isc.org/dhcp-contrib.html\n";
+static char message [] = "Internet Software Consortium DHCP Client V2.0b1pl27";
+static char contrib [] = "Please contribute if you find this software useful.";
+static char url [] = "For info, please visit http://www.isc.org/dhcp-contrib.html";
-static void usage PROTO ((void));
+static void usage PROTO ((char *));
int main (argc, argv, envp)
int argc;
@@ -107,12 +107,20 @@ int main (argc, argv, envp)
struct interface_info *ip;
int seed;
int quiet = 0;
+ char *s;
+ s = strchr (argv [0], '/');
+ if (!s)
+ s = argv [0];
+ else
+ s++;
+
+ /* Initially, log errors to stderr as well as to syslogd. */
#ifdef SYSLOG_4_2
- openlog ("dhclient", LOG_NDELAY);
- log_priority = LOG_DAEMON;
+ openlog (s, LOG_NDELAY);
+ log_priority = DHCPD_LOG_FACILITY;
#else
- openlog ("dhclient", LOG_NDELAY, LOG_DAEMON);
+ openlog (s, LOG_NDELAY, DHCPD_LOG_FACILITY);
#endif
#if !(defined (DEBUG) || defined (SYSLOG_4_2) || defined (__CYGWIN32__))
@@ -122,7 +130,7 @@ int main (argc, argv, envp)
for (i = 1; i < argc; i++) {
if (!strcmp (argv [i], "-p")) {
if (++i == argc)
- usage ();
+ usage (s);
local_port = htons (atoi (argv [i]));
debug ("binding to user-specified port %d",
ntohs (local_port));
@@ -130,15 +138,19 @@ int main (argc, argv, envp)
no_daemon = 1;
} else if (!strcmp (argv [i], "-D")) {
save_scripts = 1;
+ } else if (!strcmp (argv [i], "-pf")) {
+ if (++i == argc)
+ usage (s);
+ path_dhclient_pid = argv [i];
} else if (!strcmp (argv [i], "-lf")) {
if (++i == argc)
- usage ();
+ usage (s);
path_dhclient_db = argv [i];
} else if (!strcmp (argv [i], "-q")) {
quiet = 1;
quiet_interface_discovery = 1;
} else if (argv [i][0] == '-') {
- usage ();
+ usage (s);
} else {
struct interface_info *tmp =
((struct interface_info *)
@@ -159,8 +171,10 @@ int main (argc, argv, envp)
note (message);
note (copyright);
note (arr);
+ note ("");
note (contrib);
note (url);
+ note ("");
}
/* Default to the DHCP/BOOTP port. */
@@ -266,9 +280,19 @@ int main (argc, argv, envp)
return 0;
}
-static void usage ()
+static void usage (appname)
+ char *appname;
{
- error ("Usage: dhclient [-c] [-p <port>] [-lf lease-file] [interface]");
+ note (message);
+ note (copyright);
+ note (arr);
+ note ("");
+ note (contrib);
+ note (url);
+ note ("");
+
+ warn ("Usage: %s [-c] [-p <port>] [-lf lease-file]", appname);
+ error (" [-pf pidfile] [interface]");
}
void cleanup ()
@@ -460,7 +484,6 @@ void dhcpack (packet)
{
struct interface_info *ip = packet -> interface;
struct client_lease *lease;
- int i;
/* If we're not receptive to an offer right now, or if the offer
has an unrecognizable transaction id, then just drop it. */
@@ -469,7 +492,9 @@ void dhcpack (packet)
packet -> raw -> hlen) ||
(memcmp (packet -> interface -> hw_address.haddr,
packet -> raw -> chaddr, packet -> raw -> hlen))) {
+#if defined (DEBUG)
debug ("DHCPACK in wrong transaction.");
+#endif
return;
}
@@ -477,7 +502,9 @@ void dhcpack (packet)
ip -> client -> state != S_REQUESTING &&
ip -> client -> state != S_RENEWING &&
ip -> client -> state != S_REBINDING) {
+#if defined (DEBUG)
debug ("DHCPACK in wrong state.");
+#endif
return;
}
@@ -700,7 +727,6 @@ void dhcpoffer (packet)
int arp_timeout_needed, stop_selecting;
char *name = (packet -> options [DHO_DHCP_MESSAGE_TYPE].len
? "DHCPOFFER" : "BOOTREPLY");
- struct iaddrlist *ap;
#ifdef DEBUG_PACKET
dump_packet (packet);
@@ -714,7 +740,9 @@ void dhcpoffer (packet)
packet -> raw -> hlen) ||
(memcmp (packet -> interface -> hw_address.haddr,
packet -> raw -> chaddr, packet -> raw -> hlen))) {
+#if defined (DEBUG)
debug ("%s in wrong transaction.", name);
+#endif
return;
}
@@ -917,7 +945,9 @@ void dhcpnak (packet)
packet -> raw -> hlen) ||
(memcmp (packet -> interface -> hw_address.haddr,
packet -> raw -> chaddr, packet -> raw -> hlen))) {
+#if defined (DEBUG)
debug ("DHCPNAK in wrong transaction.");
+#endif
return;
}
@@ -925,7 +955,9 @@ void dhcpnak (packet)
ip -> client -> state != S_REQUESTING &&
ip -> client -> state != S_RENEWING &&
ip -> client -> state != S_REBINDING) {
+#if defined (DEBUG)
debug ("DHCPNAK in wrong state.");
+#endif
return;
}
@@ -1033,10 +1065,11 @@ void send_discover (ipp)
ip -> client -> config -> timeout) - cur_time + 1;
/* Record the number of seconds since we started sending. */
- if (interval < 255)
- ip -> client -> packet.secs = interval;
+ if (interval < 65536)
+ ip -> client -> packet.secs = htons (interval);
else
- ip -> client -> packet.secs = 255;
+ ip -> client -> packet.secs = htons (65535);
+ ip -> client -> secs = ip -> client -> packet.secs;
note ("DHCPDISCOVER on %s to %s port %d interval %ld",
ip -> name,
@@ -1276,10 +1309,14 @@ void send_request (ipp)
from.s_addr = INADDR_ANY;
/* Record the number of seconds since we started sending. */
- if (interval < 255)
- ip -> client -> packet.secs = interval;
- else
- ip -> client -> packet.secs = 255;
+ if (ip -> client -> state == S_REQUESTING)
+ ip -> client -> packet.secs = ip -> client -> secs;
+ else {
+ if (interval < 65536)
+ ip -> client -> packet.secs = htons (interval);
+ else
+ ip -> client -> packet.secs = htons (65535);
+ }
note ("DHCPREQUEST on %s to %s port %d", ip -> name,
inet_ntoa (destination.sin_addr),
@@ -1347,7 +1384,6 @@ void make_discover (ip, lease)
struct interface_info *ip;
struct client_lease *lease;
{
- struct dhcp_packet *raw;
unsigned char discover = DHCPDISCOVER;
int i;
@@ -1409,8 +1445,8 @@ void make_discover (ip, lease)
/* Set up the option buffer... */
ip -> client -> packet_length =
- cons_options ((struct packet *)0, &ip -> client -> packet,
- options, 0, 0, 0);
+ cons_options ((struct packet *)0, &ip -> client -> packet, 0,
+ options, 0, 0, 0, (u_int8_t *)0, 0);
if (ip -> client -> packet_length < BOOTP_MIN_LEN)
ip -> client -> packet_length = BOOTP_MIN_LEN;
@@ -1420,7 +1456,12 @@ void make_discover (ip, lease)
ip -> client -> packet.hops = 0;
ip -> client -> packet.xid = random ();
ip -> client -> packet.secs = 0; /* filled in by send_discover. */
- ip -> client -> packet.flags = htons (BOOTP_BROADCAST); /* XXX */
+
+ if (can_receive_unicast_unconfigured (ip))
+ ip -> client -> packet.flags = 0;
+ else
+ ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
+
memset (&(ip -> client -> packet.ciaddr),
0, sizeof ip -> client -> packet.ciaddr);
memset (&(ip -> client -> packet.yiaddr),
@@ -1516,8 +1557,8 @@ void make_request (ip, lease)
/* Set up the option buffer... */
ip -> client -> packet_length =
- cons_options ((struct packet *)0, &ip -> client -> packet,
- options, 0, 0, 0);
+ cons_options ((struct packet *)0, &ip -> client -> packet, 0,
+ options, 0, 0, 0, (u_int8_t *)0, 0);
if (ip -> client -> packet_length < BOOTP_MIN_LEN)
ip -> client -> packet_length = BOOTP_MIN_LEN;
@@ -1539,7 +1580,10 @@ void make_request (ip, lease)
} else {
memset (&ip -> client -> packet.ciaddr, 0,
sizeof ip -> client -> packet.ciaddr);
- ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
+ if (can_receive_unicast_unconfigured (ip))
+ ip -> client -> packet.flags = 0;
+ else
+ ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
}
memset (&ip -> client -> packet.yiaddr, 0,
@@ -1617,8 +1661,8 @@ void make_decline (ip, lease)
/* Set up the option buffer... */
ip -> client -> packet_length =
- cons_options ((struct packet *)0, &ip -> client -> packet,
- options, 0, 0, 0);
+ cons_options ((struct packet *)0, &ip -> client -> packet, 0,
+ options, 0, 0, 0, (u_int8_t *)0, 0);
if (ip -> client -> packet_length < BOOTP_MIN_LEN)
ip -> client -> packet_length = BOOTP_MIN_LEN;
@@ -1628,7 +1672,7 @@ void make_decline (ip, lease)
ip -> client -> packet.hops = 0;
ip -> client -> packet.xid = ip -> client -> xid;
ip -> client -> packet.secs = 0; /* Filled in by send_request. */
- ip -> client -> packet.flags = htons (BOOTP_BROADCAST);
+ ip -> client -> packet.flags = 0;
/* ciaddr must always be zero. */
memset (&ip -> client -> packet.ciaddr, 0,
@@ -1657,7 +1701,6 @@ void make_release (ip, lease)
struct tree_cache *options [256];
struct tree_cache message_type_tree;
- struct tree_cache requested_address_tree;
struct tree_cache server_id_tree;
memset (options, 0, sizeof options);
@@ -1683,8 +1726,8 @@ void make_release (ip, lease)
/* Set up the option buffer... */
ip -> client -> packet_length =
- cons_options ((struct packet *)0, &ip -> client -> packet,
- options, 0, 0, 0);
+ cons_options ((struct packet *)0, &ip -> client -> packet, 0,
+ options, 0, 0, 0, (u_int8_t *)0, 0);
if (ip -> client -> packet_length < BOOTP_MIN_LEN)
ip -> client -> packet_length = BOOTP_MIN_LEN;
@@ -1695,8 +1738,9 @@ void make_release (ip, lease)
ip -> client -> packet.xid = random ();
ip -> client -> packet.secs = 0;
ip -> client -> packet.flags = 0;
- memcpy (&ip -> client -> packet.ciaddr,
- lease -> address.iabuf, lease -> address.len);
+
+ memset (&ip -> client -> packet.ciaddr, 0,
+ sizeof ip -> client -> packet.ciaddr);
memset (&ip -> client -> packet.yiaddr, 0,
sizeof ip -> client -> packet.yiaddr);
memset (&ip -> client -> packet.siaddr, 0,
@@ -1992,20 +2036,19 @@ void script_write_params (ip, prefix, lease)
lease -> options [i].len);
if (len > sizeof dbuf) {
warn ("no space to %s %s",
- "prepend option",
+ "append option",
dhcp_options [i].name);
goto supersede;
}
dp = dbuf;
memcpy (dp,
+ lease -> options [i].data,
+ lease -> options [i].len);
+ memcpy (dp + lease -> options [i].len,
ip -> client ->
config -> defaults [i].data,
ip -> client ->
config -> defaults [i].len);
- memcpy (dp + ip -> client ->
- config -> defaults [i].len,
- lease -> options [i].data,
- lease -> options [i].len);
}
} else {
dp = ip -> client ->