-/* $OpenBSD: ask_nbrs2.c,v 1.5 2015/12/07 19:17:18 mmcc Exp $ */
+/* $OpenBSD: ask_nbrs2.c,v 1.6 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
int ret = 0;
log_debug("send_ask_nbrs2: interface %s addr %s",
dst.sin_len = sizeof(struct sockaddr_in);
dst.sin_addr.s_addr = addr.s_addr;
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
-/* $OpenBSD: dvmrpe.h,v 1.7 2021/01/19 12:23:30 claudio Exp $ */
+/* $OpenBSD: dvmrpe.h,v 1.8 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
/* packet.c */
int gen_dvmrp_hdr(struct ibuf *, struct iface *, u_int8_t);
-int send_packet(struct iface *, void *, size_t, struct sockaddr_in *);
+int send_packet(struct iface *, struct ibuf *,
+ struct sockaddr_in *);
void recv_packet(int, short, void *);
/* probe.c */
-/* $OpenBSD: graft.c,v 1.5 2015/12/07 19:17:18 mmcc Exp $ */
+/* $OpenBSD: graft.c,v 1.6 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
int ret = 0;
log_debug("send_graft: interface %s addr %s",
dst.sin_len = sizeof(struct sockaddr_in);
dst.sin_addr.s_addr = addr.s_addr;
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
-/* $OpenBSD: graft_ack.c,v 1.5 2015/12/07 19:17:18 mmcc Exp $ */
+/* $OpenBSD: graft_ack.c,v 1.6 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
int ret = 0;
log_debug("send_graft_ack: interface %s addr %s",
dst.sin_len = sizeof(struct sockaddr_in);
dst.sin_addr.s_addr = addr.s_addr;
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
-/* $OpenBSD: igmp.c,v 1.4 2015/12/07 19:14:49 mmcc Exp $ */
+/* $OpenBSD: igmp.c,v 1.5 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
igmp_hdr.max_resp_time = iface->last_member_query_interval;
}
- /* update chksum */
- igmp_hdr.chksum = in_cksum(&igmp_hdr, sizeof(igmp_hdr));
-
ibuf_add(buf, &igmp_hdr, sizeof(igmp_hdr));
/* set destination address */
dst.sin_len = sizeof(struct sockaddr_in);
inet_aton(AllSystems, &dst.sin_addr);
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
}
-/* $OpenBSD: nbrs2.c,v 1.4 2015/05/05 01:26:37 jsg Exp $ */
+/* $OpenBSD: nbrs2.c,v 1.5 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
int ret = 0;
log_debug("send_nbrs2: interface %s addr %s",
dst.sin_len = sizeof(struct sockaddr_in);
dst.sin_addr.s_addr = addr.s_addr;
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
-/* $OpenBSD: packet.c,v 1.7 2021/01/19 16:02:56 claudio Exp $ */
+/* $OpenBSD: packet.c,v 1.8 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org>
#include <errno.h>
#include <event.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* send and receive packets */
int
-send_packet(struct iface *iface, void *pkt, size_t len, struct sockaddr_in *dst)
+send_packet(struct iface *iface, struct ibuf *pkt, struct sockaddr_in *dst)
{
+ u_int16_t chksum;
+
if (iface->passive) {
log_warnx("send_packet: cannot send packet on passive "
"interface %s", iface->name);
return (-1);
}
- if (sendto(iface->fd, pkt, len, 0,
+ /* update chksum */
+ chksum = in_cksum(ibuf_data(pkt), ibuf_size(pkt));
+ if (ibuf_set(pkt, offsetof(struct dvmrp_hdr, chksum),
+ &chksum, sizeof(chksum)) == -1) {
+ log_warn("send_packet: failed to update checksum");
+ return (-1);
+ }
+
+ if (sendto(iface->fd, ibuf_data(pkt), ibuf_size(pkt), 0,
(struct sockaddr *)dst, sizeof(*dst)) == -1 ) {
log_warn("send_packet: error sending packet on interface %s",
iface->name);
-/* $OpenBSD: probe.c,v 1.4 2015/05/05 01:26:37 jsg Exp $ */
+/* $OpenBSD: probe.c,v 1.5 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
struct nbr *nbr;
int ret = 0;
dst.sin_len = sizeof(struct sockaddr_in);
inet_aton(AllDVMRPRouters, &dst.sin_addr);
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
-/* $OpenBSD: prune.c,v 1.6 2015/12/07 19:14:49 mmcc Exp $ */
+/* $OpenBSD: prune.c,v 1.7 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
struct prune_hdr prune;
int ret = 0;
ibuf_add(buf, &prune, sizeof(prune));
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(nbr->iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(nbr->iface, buf, &dst);
ibuf_free(buf);
return (ret);
-/* $OpenBSD: report.c,v 1.11 2015/12/07 18:59:31 mmcc Exp $ */
+/* $OpenBSD: report.c,v 1.12 2023/06/26 10:08:56 claudio Exp $ */
/*
* Copyright (c) 2005, 2006 Esben Norby <norby@openbsd.org>
{
struct sockaddr_in dst;
struct ibuf *buf;
- struct dvmrp_hdr *dvmrp_hdr;
int ret = 0;
log_debug("send_report: interface %s addr %s",
dst.sin_len = sizeof(struct sockaddr_in);
dst.sin_addr.s_addr = addr.s_addr;
- /* update chksum */
- dvmrp_hdr = ibuf_seek(buf, 0, sizeof(*dvmrp_hdr));
- dvmrp_hdr->chksum = in_cksum(buf->buf, buf->wpos);
-
- ret = send_packet(iface, buf->buf, buf->wpos, &dst);
+ ret = send_packet(iface, buf, &dst);
ibuf_free(buf);
return (ret);
fail:
prefixlen = 0;
while (((le = TAILQ_FIRST(rr_list)) != NULL) &&
- (buf->wpos < 1000)) {
+ (ibuf_size(buf) < 1000)) {
/* netmask */
netmask = le->re->mask.s_addr;
if (prefixlen != mask2prefixlen(netmask)) {
rr_list_remove(le->re);
free(le);
}
- send_report(iface, addr, buf->buf, buf->wpos);
+ send_report(iface, addr, ibuf_data(buf), ibuf_size(buf));
ibuf_free(buf);
}
}