-/* $OpenBSD: bpf.c,v 1.31 2013/12/12 00:22:06 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.32 2014/04/17 09:59:30 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
}
ssize_t
-send_packet(struct in_addr from, struct sockaddr_in *to,
- struct ether_addr *hto)
+send_packet(struct in_addr from, struct in_addr to)
{
+ struct sockaddr_in dest;
struct ether_header eh;
struct ip ip;
struct udphdr udp;
ssize_t result;
int iovcnt = 0, len;
- if (to->sin_addr.s_addr == INADDR_BROADCAST) {
- assemble_eh_header(&eh, hto);
+ memset(&dest, 0, sizeof(dest));
+ dest.sin_family = AF_INET;
+ dest.sin_port = htons(REMOTE_PORT);
+ dest.sin_addr.s_addr = to.s_addr;
+
+ if (to.s_addr == INADDR_BROADCAST) {
+ assemble_eh_header(&eh);
iov[0].iov_base = &eh;
iov[0].iov_len = sizeof(eh);
iovcnt++;
ip.ip_p = IPPROTO_UDP;
ip.ip_sum = 0;
ip.ip_src.s_addr = from.s_addr;
- ip.ip_dst.s_addr = to->sin_addr.s_addr;
+ ip.ip_dst.s_addr = to.s_addr;
ip.ip_sum = wrapsum(checksum((unsigned char *)&ip, sizeof(ip), 0));
iov[iovcnt].iov_base = &ip;
iov[iovcnt].iov_len = sizeof(ip);
iovcnt++;
udp.uh_sport = htons(LOCAL_PORT);
- udp.uh_dport = to->sin_port;
+ udp.uh_dport = htons(REMOTE_PORT);
udp.uh_ulen = htons(sizeof(udp) + len);
udp.uh_sum = 0;
udp.uh_sum = wrapsum(checksum((unsigned char *)&udp, sizeof(udp),
iov[iovcnt].iov_len = len;
iovcnt++;
- if (to->sin_addr.s_addr == INADDR_BROADCAST) {
+ if (to.s_addr == INADDR_BROADCAST) {
result = writev(ifi->wfdesc, iov, iovcnt);
} else {
memset(&msg, 0, sizeof(msg));
- msg.msg_name = (struct sockaddr *)to;
- msg.msg_namelen = sizeof(*to);
+ msg.msg_name = (struct sockaddr *)&dest;
+ msg.msg_namelen = sizeof(to);
msg.msg_iov = iov;
msg.msg_iovlen = iovcnt;
result = sendmsg(ifi->ufdesc, &msg, 0);
-/* $OpenBSD: dhclient.c,v 1.295 2014/04/16 18:46:41 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.296 2014/04/17 09:59:30 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
struct in_addr deleting;
struct in_addr adding;
-struct in_addr inaddr_any;
-struct sockaddr_in sockaddr_broadcast;
+const struct in_addr inaddr_any = { INADDR_ANY };
struct interface_info *ifi;
struct client_state *client;
tzset();
- memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
- sockaddr_broadcast.sin_family = AF_INET;
- sockaddr_broadcast.sin_port = htons(REMOTE_PORT);
- sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
- sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast);
- inaddr_any.s_addr = INADDR_ANY;
-
/* Put us into the correct rdomain */
ifi->rdomain = get_rdomain(ifi->name);
if (setrtable(ifi->rdomain) == -1)
client->bootrequest_packet.secs = htons(65535);
client->secs = client->bootrequest_packet.secs;
- note("DHCPDISCOVER on %s to %s port %hu interval %lld",
- ifi->name, inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port),
+ note("DHCPDISCOVER on %s - interval %lld", ifi->name,
(long long)client->interval);
- send_packet(inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet(inaddr_any, inaddr_any);
set_timeout_interval(client->interval, send_discover);
}
destination.sin_addr.s_addr = INADDR_BROADCAST;
else
destination.sin_addr.s_addr = client->destination.s_addr;
- destination.sin_port = htons(REMOTE_PORT);
- destination.sin_family = AF_INET;
- destination.sin_len = sizeof(destination);
if (client->state != S_REQUESTING)
from.s_addr = client->active->address.s_addr;
note("DHCPREQUEST on %s to %s port %hu", ifi->name,
inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
- send_packet(from, &destination, NULL);
+ send_packet(from, destination.sin_addr);
set_timeout_interval(client->interval, send_request);
}
void
send_decline(void)
{
- note("DHCPDECLINE on %s to %s port %hu", ifi->name,
- inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port));
+ note("DHCPDECLINE on %s", ifi->name);
- send_packet(inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet(inaddr_any, inaddr_any);
}
void
-/* $OpenBSD: dhcpd.h,v 1.136 2014/02/09 20:45:56 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.137 2014/04/17 09:59:30 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
/* bpf.c */
void if_register_send(void);
void if_register_receive(void);
-ssize_t send_packet(struct in_addr, struct sockaddr_in *, struct ether_addr *);
+ssize_t send_packet(struct in_addr, struct in_addr);
ssize_t receive_packet(struct sockaddr_in *, struct ether_addr *);
/* dispatch.c */
void routehandler(void);
/* packet.c */
-void assemble_eh_header(struct ether_header *, struct ether_addr *);
+void assemble_eh_header(struct ether_header *);
ssize_t decode_hw_header(unsigned char *, int, struct ether_addr *);
ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
int);
-/* $OpenBSD: packet.c,v 1.25 2014/01/20 09:16:36 deraadt Exp $ */
+/* $OpenBSD: packet.c,v 1.26 2014/04/17 09:59:30 krw Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
}
void
-assemble_eh_header(struct ether_header *eh, struct ether_addr *to)
+assemble_eh_header(struct ether_header *eh)
{
- if (to != NULL)
- memcpy(eh->ether_dhost, to->ether_addr_octet,
- sizeof(eh->ether_dhost));
- else
- memset(eh->ether_dhost, 0xff, sizeof(eh->ether_dhost));
+ memset(eh->ether_dhost, 0xff, sizeof(eh->ether_dhost));
memcpy(eh->ether_shost, ifi->hw_address.ether_addr_octet,
sizeof(eh->ether_shost));