summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorHenning Brauer <henning@cvs.openbsd.org>2004-02-25 14:22:13 +0000
committerHenning Brauer <henning@cvs.openbsd.org>2004-02-25 14:22:13 +0000
commit048ca19a4cc9b79ca1672bb4e8f738411534b01a (patch)
treee1933fa84e268374d9c26574994c41a9914629a9 /sbin/dhclient
parent123d8dc46878d0a2ccfe9d5713870a5a51ffea43 (diff)
doesn't quite make sense to have a wrapper to a wrapper to the incredible
amount of ~ 20 lines of code in their own file... and another one bites the dust
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/Makefile8
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/ethernet.c88
-rw-r--r--sbin/dhclient/packet.c62
4 files changed, 41 insertions, 121 deletions
diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile
index abf1242f7d3..9bb9c8347ee 100644
--- a/sbin/dhclient/Makefile
+++ b/sbin/dhclient/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.7 2004/02/24 16:37:19 henning Exp $
+# $OpenBSD: Makefile,v 1.8 2004/02/25 14:22:12 henning Exp $
#
# Copyright (c) 1996, 1997 The Internet Software Consortium.
# All rights reserved.
@@ -32,10 +32,8 @@
.include <bsd.own.mk>
-SRCS= dhclient.c clparse.c \
- alloc.c dispatch.c hash.c bpf.c options.c \
- tree.c conflex.c errwarn.c inet.c packet.c convert.c \
- ethernet.c tables.c parse.c
+SRCS= dhclient.c clparse.c alloc.c dispatch.c hash.c bpf.c options.c \
+ tree.c conflex.c errwarn.c inet.c packet.c convert.c tables.c parse.c
PROG= dhclient
MAN= dhclient.8 dhclient.conf.5 dhclient.leases.5 dhclient-script.8
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 9202afdcfb2..68fba116ea8 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.18 2004/02/24 17:26:43 henning Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.19 2004/02/25 14:22:12 henning Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -425,8 +425,6 @@ void dhcp(struct packet *);
void cleanup(void);
/* packet.c */
-u_int32_t checksum(unsigned char *, unsigned, u_int32_t);
-u_int32_t wrapsum(u_int32_t);
void assemble_hw_header(struct interface_info *, unsigned char *,
int *, struct hardware *);
void assemble_udp_ip_header(struct interface_info *, unsigned char *,
diff --git a/sbin/dhclient/ethernet.c b/sbin/dhclient/ethernet.c
deleted file mode 100644
index d15b9c8b92b..00000000000
--- a/sbin/dhclient/ethernet.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/* $OpenBSD: ethernet.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */
-
-/* Packet assembly code, originally contributed by Archie Cobbs. */
-
-/*
- * Copyright (c) 1995, 1996 The Internet Software Consortium.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of The Internet Software Consortium nor the names
- * of its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
- * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * This software has been written for the Internet Software Consortium
- * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
- * Enterprises. To learn more about the Internet Software Consortium,
- * see ``http://www.vix.com/isc''. To learn more about Vixie
- * Enterprises, see ``http://www.vix.com''.
- */
-
-#include "dhcpd.h"
-
-#include <netinet/if_ether.h>
-#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof(u_int16_t))
-
-/* Assemble a hardware header... */
-/* XXX: currently only supports ethernet; doesn't check for other types. */
-
-void
-assemble_ethernet_header(struct interface_info *interface, unsigned char *buf,
- int *bufix, struct hardware *to)
-{
- struct ether_header eh;
-
- if (to != NULL && to->hlen == 6) /* XXX */
- memcpy(eh.ether_dhost, to->haddr, 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,
- sizeof(eh.ether_shost));
- else
- memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost));
-
- eh.ether_type = htons(ETHERTYPE_IP);
-
- memcpy(&buf[*bufix], &eh, ETHER_HEADER_SIZE);
- *bufix += ETHER_HEADER_SIZE;
-}
-
-/* Decode a hardware header... */
-
-ssize_t
-decode_ethernet_header(struct interface_info *interface, unsigned char *buf,
- int bufix, struct hardware *from)
-{
- struct ether_header eh;
-
- memcpy(&eh, buf + bufix, ETHER_HEADER_SIZE);
-
- memcpy(from->haddr, eh.ether_shost, sizeof(eh.ether_shost));
- from->htype = ARPHRD_ETHER;
- from->hlen = sizeof(eh.ether_shost);
-
- return (sizeof(eh));
-}
diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c
index 7a188d4ff4d..a54e2831897 100644
--- a/sbin/dhclient/packet.c
+++ b/sbin/dhclient/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.7 2004/02/24 13:36:13 henning Exp $ */
+/* $OpenBSD: packet.c,v 1.8 2004/02/25 14:22:12 henning Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
@@ -45,10 +45,18 @@
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/udp.h>
+#include <netinet/if_ether.h>
+
+#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof(u_int16_t))
+
+u_int32_t checksum(unsigned char *, unsigned, u_int32_t);
+u_int32_t wrapsum(u_int32_t);
+
+void assemble_ethernet_header(struct interface_info *, unsigned char *,
+ int *, struct hardware *);
+ssize_t decode_ethernet_header(struct interface_info *, unsigned char *,
+ int bufix, struct hardware *);
-/*
- * Compute the easy part of the checksum on a range of bytes.
- */
u_int32_t
checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)
{
@@ -75,9 +83,6 @@ checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)
return (sum);
}
-/*
- * Finish computing the sum, and then put it into network byte order.
- */
u_int32_t
wrapsum(u_int32_t sum)
{
@@ -85,21 +90,28 @@ wrapsum(u_int32_t sum)
return (htons(sum));
}
-/*
- * Assemble a hardware header...
- *
- * XXX currently only supports ethernet; doesn't check for other types.
- */
void
assemble_hw_header(struct interface_info *interface, unsigned char *buf,
int *bufix, struct hardware *to)
{
- assemble_ethernet_header(interface, buf, bufix, to);
+ struct ether_header eh;
+
+ if (to != NULL && to->hlen == 6) /* XXX */
+ memcpy(eh.ether_dhost, to->haddr, 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,
+ sizeof(eh.ether_shost));
+ else
+ memset(eh.ether_shost, 0x00, sizeof(eh.ether_shost));
+
+ eh.ether_type = htons(ETHERTYPE_IP);
+
+ memcpy(&buf[*bufix], &eh, ETHER_HEADER_SIZE);
+ *bufix += ETHER_HEADER_SIZE;
}
-/*
- * UDP header and IP header assembled together for convenience.
- */
void
assemble_udp_ip_header(struct interface_info *interface, unsigned char *buf,
int *bufix, u_int32_t from, u_int32_t to, unsigned int port,
@@ -108,7 +120,6 @@ assemble_udp_ip_header(struct interface_info *interface, unsigned char *buf,
struct ip ip;
struct udphdr udp;
- /* Fill out the IP header */
ip.ip_v = 4;
ip.ip_hl = 5;
ip.ip_tos = IPTOS_LOWDELAY;
@@ -125,7 +136,6 @@ assemble_udp_ip_header(struct interface_info *interface, unsigned char *buf,
memcpy(&buf[*bufix], &ip, sizeof(ip));
*bufix += sizeof(ip);
- /* Fill out the UDP header */
udp.uh_sport = htons(LOCAL_PORT); /* XXX */
udp.uh_dport = port; /* XXX */
udp.uh_ulen = htons(sizeof(udp) + len);
@@ -140,19 +150,21 @@ assemble_udp_ip_header(struct interface_info *interface, unsigned char *buf,
*bufix += sizeof(udp);
}
-/*
- * Decode a hardware header...
- */
ssize_t
decode_hw_header(struct interface_info *interface, unsigned char *buf,
int bufix, struct hardware *from)
{
- return (decode_ethernet_header(interface, buf, bufix, from));
+ struct ether_header eh;
+
+ memcpy(&eh, buf + bufix, ETHER_HEADER_SIZE);
+
+ memcpy(from->haddr, eh.ether_shost, sizeof(eh.ether_shost));
+ from->htype = ARPHRD_ETHER;
+ from->hlen = sizeof(eh.ether_shost);
+
+ return (sizeof(eh));
}
-/*
- * UDP header and IP header decoded together for convenience.
- */
ssize_t
decode_udp_ip_header(struct interface_info *interface, unsigned char *buf,
int bufix, struct sockaddr_in *from, unsigned char *data, int buflen)