]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
struct hardware conversion.
authorTed Lemon <source@isc.org>
Wed, 5 Jan 2000 18:01:15 +0000 (18:01 +0000)
committerTed Lemon <source@isc.org>
Wed, 5 Jan 2000 18:01:15 +0000 (18:01 +0000)
client/dhclient.c
common/bpf.c
common/ethernet.c

index d56e4387614b4b362999edba5dc7a34157c7b4cb..bcd3729c45b452289c7568d09c7ac851d094a48b 100644 (file)
  *
  * Support and other services are available for ISC products - see
  * http://www.isc.org for more information.
+ *
+ * This code was originally written by Ted Lemon.  Elliot Poger wrote
+ * a state machine to fully implement the client side of the DHCP
+ * protocol.  Ted Lemon then added the configuration file, stuffed the
+ * state machine into its own data structure so there could be more
+ * than one, and added the client scripting code to produce the first
+ * ISC release (2.0b1pl0) of the client.
  */
 
 #ifndef lint
 static char ocopyright[] =
-"$Id: dhclient.c,v 1.90 1999/11/20 18:36:03 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: dhclient.c,v 1.91 2000/01/05 17:55:31 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -283,8 +290,8 @@ int main (argc, argv, envp)
        for (ip = interfaces; ip; ip = ip -> next) {
                int junk;
                memcpy (&junk,
-                       &ip -> hw_address.haddr [ip -> hw_address.hlen -
-                                                sizeof seed], sizeof seed);
+                       &ip -> hw_address.hbuf [ip -> hw_address.hlen -
+                                              sizeof seed], sizeof seed);
                seed += junk;
        }
        srandom (seed + cur_time);
@@ -540,9 +547,9 @@ void dhcpack (packet)
                        break;
        }
        if (!client ||
-           (packet -> interface -> hw_address.hlen !=
+           (packet -> interface -> hw_address.hlen - 1 !=
             packet -> raw -> hlen) ||
-           (memcmp (packet -> interface -> hw_address.haddr,
+           (memcmp (&packet -> interface -> hw_address.hbuf [1],
                     packet -> raw -> chaddr, packet -> raw -> hlen))) {
 #if defined (DEBUG)
                log_debug ("DHCPACK in wrong transaction.");
@@ -875,9 +882,9 @@ void dhcpoffer (packet)
           has an unrecognizable transaction id, then just drop it. */
        if (!client ||
            client -> state != S_SELECTING ||
-           (packet -> interface -> hw_address.hlen !=
+           (packet -> interface -> hw_address.hlen - 1 !=
             packet -> raw -> hlen) ||
-           (memcmp (packet -> interface -> hw_address.haddr,
+           (memcmp (&packet -> interface -> hw_address.hbuf [1],
                     packet -> raw -> chaddr, packet -> raw -> hlen))) {
 #if defined (DEBUG)
                log_debug ("%s in wrong transaction.", name);
@@ -1059,9 +1066,9 @@ void dhcpnak (packet)
        /* If we're not receptive to an offer right now, or if the offer
           has an unrecognizable transaction id, then just drop it. */
        if (!client ||
-           (packet -> interface -> hw_address.hlen !=
+           (packet -> interface -> hw_address.hlen - 1 !=
             packet -> raw -> hlen) ||
-           (memcmp (packet -> interface -> hw_address.haddr,
+           (memcmp (&packet -> interface -> hw_address.hbuf [1],
                     packet -> raw -> chaddr, packet -> raw -> hlen))) {
 #if defined (DEBUG)
                log_debug ("DHCPNAK in wrong transaction.");
@@ -1605,8 +1612,8 @@ void make_discover (client, lease)
                client -> packet_length = BOOTP_MIN_LEN;
 
        client -> packet.op = BOOTREQUEST;
-       client -> packet.htype = client -> interface -> hw_address.htype;
-       client -> packet.hlen = client -> interface -> hw_address.hlen;
+       client -> packet.htype = client -> interface -> hw_address.hbuf [0];
+       client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
        client -> packet.hops = 0;
        client -> packet.xid = random ();
        client -> packet.secs = 0; /* filled in by send_discover. */
@@ -1623,9 +1630,10 @@ void make_discover (client, lease)
        memset (&(client -> packet.siaddr),
                0, sizeof client -> packet.siaddr);
        client -> packet.giaddr = giaddr;
-       memcpy (client -> packet.chaddr,
-               client -> interface -> hw_address.haddr,
-               client -> interface -> hw_address.hlen);
+       if (client -> interface -> hw_address.hlen > 0)
+           memcpy (client -> packet.chaddr,
+                   &client -> interface -> hw_address.hbuf [1],
+                   (unsigned)(client -> interface -> hw_address.hlen - 1));
 
 #ifdef DEBUG_PACKET
        dump_packet (sendpkt);
@@ -1672,8 +1680,8 @@ void make_request (client, lease)
                client -> packet_length = BOOTP_MIN_LEN;
 
        client -> packet.op = BOOTREQUEST;
-       client -> packet.htype = client -> interface -> hw_address.htype;
-       client -> packet.hlen = client -> interface -> hw_address.hlen;
+       client -> packet.htype = client -> interface -> hw_address.hbuf [0];
+       client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
        client -> packet.hops = 0;
        client -> packet.xid = client -> xid;
        client -> packet.secs = 0; /* Filled in by send_request. */
@@ -1700,9 +1708,10 @@ void make_request (client, lease)
        memset (&client -> packet.siaddr, 0,
                sizeof client -> packet.siaddr);
        client -> packet.giaddr = giaddr;
-       memcpy (client -> packet.chaddr,
-               client -> interface -> hw_address.haddr,
-               client -> interface -> hw_address.hlen);
+       if (client -> interface -> hw_address.hlen > 0)
+           memcpy (client -> packet.chaddr,
+                   &client -> interface -> hw_address.hbuf [1],
+                   (unsigned)(client -> interface -> hw_address.hlen - 1));
 
 #ifdef DEBUG_PACKET
        dump_packet (sendpkt);
@@ -1737,8 +1746,8 @@ void make_decline (client, lease)
        option_state_dereference (&options, "make_decline");
 
        client -> packet.op = BOOTREQUEST;
-       client -> packet.htype = client -> interface -> hw_address.htype;
-       client -> packet.hlen = client -> interface -> hw_address.hlen;
+       client -> packet.htype = client -> interface -> hw_address.hbuf [0];
+       client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
        client -> packet.hops = 0;
        client -> packet.xid = client -> xid;
        client -> packet.secs = 0; /* Filled in by send_request. */
@@ -1756,7 +1765,7 @@ void make_decline (client, lease)
                sizeof client -> packet.siaddr);
        client -> packet.giaddr = giaddr;
        memcpy (client -> packet.chaddr,
-               client -> interface -> hw_address.haddr,
+               &client -> interface -> hw_address.hbuf [1],
                client -> interface -> hw_address.hlen);
 
 #ifdef DEBUG_PACKET
@@ -1794,8 +1803,8 @@ void make_release (client, lease)
        option_state_dereference (&options, "make_decline");
 
        client -> packet.op = BOOTREQUEST;
-       client -> packet.htype = client -> interface -> hw_address.htype;
-       client -> packet.hlen = client -> interface -> hw_address.hlen;
+       client -> packet.htype = client -> interface -> hw_address.hbuf [0];
+       client -> packet.hlen = client -> interface -> hw_address.hlen - 1;
        client -> packet.hops = 0;
        client -> packet.xid = random ();
        client -> packet.secs = 0;
@@ -1808,7 +1817,7 @@ void make_release (client, lease)
                sizeof client -> packet.siaddr);
        client -> packet.giaddr = giaddr;
        memcpy (client -> packet.chaddr,
-               client -> interface -> hw_address.haddr,
+               &client -> interface -> hw_address.hbuf [0],
                client -> interface -> hw_address.hlen);
 
 #ifdef DEBUG_PACKET
index 39ea44768b6d4f67a0722e9eefed2b36b46f28a5..d29af00c1e0ddcfcfd97da00a68f431962e128ed 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: bpf.c,v 1.31 1999/10/12 16:00:26 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: bpf.c,v 1.32 2000/01/05 17:57:30 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -123,9 +123,9 @@ void if_register_send (info)
        if (!quiet_interface_discovery)
                log_info ("Sending on   BPF/%s/%s%s%s",
                      info -> name,
-                     print_hw_addr (info -> hw_address.htype,
-                                    info -> hw_address.hlen,
-                                    info -> hw_address.haddr),
+                     print_hw_addr (info -> hw_address.hbuf [0],
+                                    info -> hw_address.hlen - 1,
+                                    &info -> hw_address.hbuf [1]),
                      (info -> shared_network ? "/" : ""),
                      (info -> shared_network ?
                       info -> shared_network -> name : ""));
@@ -246,9 +246,9 @@ void if_register_receive (info)
        if (!quiet_interface_discovery)
                log_info ("Listening on BPF/%s/%s%s%s",
                      info -> name,
-                     print_hw_addr (info -> hw_address.htype,
-                                    info -> hw_address.hlen,
-                                    info -> hw_address.haddr),
+                     print_hw_addr (info -> hw_address.hbuf [0],
+                                    info -> hw_address.hlen - 1,
+                                    &info -> hw_address.hbuf [1]),
                      (info -> shared_network ? "/" : ""),
                      (info -> shared_network ?
                       info -> shared_network -> name : ""));
index 1a1162b7c8dbbbc0ec1922e3ce7e82e83d17243e..b48bb470afadcfeceefac3b97cdefd5c228669d5 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: ethernet.c,v 1.3 1999/11/11 16:10:57 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: ethernet.c,v 1.4 2000/01/05 18:01:15 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -43,12 +43,13 @@ void assemble_ethernet_header (interface, buf, bufix, to)
 {
        struct ether_header eh;
 
-       if (to && to -> hlen == 6) /* XXX */
-               memcpy (eh.ether_dhost, to -> haddr, sizeof eh.ether_dhost);
+       if (to && to -> hlen == 7) /* XXX */
+               memcpy (eh.ether_dhost, &to -> hbuf [1],
+                       sizeof eh.ether_dhost);
        else
                memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost));
-       if (interface -> hw_address.hlen == sizeof (eh.ether_shost))
-               memcpy (eh.ether_shost, interface -> hw_address.haddr,
+       if (interface -> hw_address.hlen - 1 == sizeof (eh.ether_shost))
+               memcpy (eh.ether_shost, &interface -> hw_address.hbuf [1],
                        sizeof (eh.ether_shost));
        else
                memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost));
@@ -81,10 +82,10 @@ ssize_t decode_ethernet_header (interface, buf, bufix, from)
   if (ntohs (eh.ether_type) != ETHERTYPE_IP)
          return -1;
 #endif
-  memcpy (from -> haddr, eh.ether_shost, sizeof (eh.ether_shost));
-  from -> htype = ARPHRD_ETHER;
-  from -> hlen = sizeof eh.ether_shost;
+  memcpy (&from -> hbuf [1], eh.ether_shost, sizeof (eh.ether_shost));
+  from -> hbuf [0] = ARPHRD_ETHER;
+  from -> hlen = (sizeof eh.ether_shost) + 1;
 
-  return sizeof eh;
+  return ETHER_HEADER_SIZE;
 }
 #endif /* PACKET_DECODING */