From: Ted Lemon Date: Wed, 5 Jan 2000 18:01:15 +0000 (+0000) Subject: struct hardware conversion. X-Git-Tag: V3-BETA-2-PATCH-1~478 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31730f17c7c148790e4de85fee74a1d4ec9d4c45;p=thirdparty%2Fdhcp.git struct hardware conversion. --- diff --git a/client/dhclient.c b/client/dhclient.c index d56e43876..bcd3729c4 100644 --- a/client/dhclient.c +++ b/client/dhclient.c @@ -18,11 +18,18 @@ * * 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 diff --git a/common/bpf.c b/common/bpf.c index 39ea44768..d29af00c1 100644 --- a/common/bpf.c +++ b/common/bpf.c @@ -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 : "")); diff --git a/common/ethernet.c b/common/ethernet.c index 1a1162b7c..b48bb470a 100644 --- a/common/ethernet.c +++ b/common/ethernet.c @@ -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 */