summaryrefslogtreecommitdiff
path: root/sbin/isakmpd
diff options
context:
space:
mode:
authorHakan Olsson <ho@cvs.openbsd.org>2001-10-26 13:29:27 +0000
committerHakan Olsson <ho@cvs.openbsd.org>2001-10-26 13:29:27 +0000
commit3280c63ccb946ae977d0b44793122c781361c11b (patch)
tree997375769da49213a937eeb057adcc824b34ebe0 /sbin/isakmpd
parent53ad6c2a25ef0c135d429a16bb3f7ddf0527fbb0 (diff)
Change to use sysdep_sa_len() function.
Diffstat (limited to 'sbin/isakmpd')
-rw-r--r--sbin/isakmpd/cookie.c6
-rw-r--r--sbin/isakmpd/if.c8
-rw-r--r--sbin/isakmpd/ipsec.c30
-rw-r--r--sbin/isakmpd/message.c4
-rw-r--r--sbin/isakmpd/pf_key_v2.c60
-rw-r--r--sbin/isakmpd/sa.c14
-rw-r--r--sbin/isakmpd/udp.c41
-rw-r--r--sbin/isakmpd/util.c28
8 files changed, 93 insertions, 98 deletions
diff --git a/sbin/isakmpd/cookie.c b/sbin/isakmpd/cookie.c
index 27b1bbe5947..f13672e4be4 100644
--- a/sbin/isakmpd/cookie.c
+++ b/sbin/isakmpd/cookie.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cookie.c,v 1.9 2001/06/29 18:52:16 ho Exp $ */
+/* $OpenBSD: cookie.c,v 1.10 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: cookie.c,v 1.21 1999/08/05 15:00:04 niklas Exp $ */
/*
@@ -67,9 +67,9 @@ cookie_gen (struct transport *t, struct exchange *exchange, u_int8_t *buf,
hash->Init (hash->ctx);
(*t->vtbl->get_dst) (t, &name);
- hash->Update (hash->ctx, (u_int8_t *)name, name->sa_len);
+ hash->Update (hash->ctx, (u_int8_t *)name, sysdep_sa_len (name));
(*t->vtbl->get_src) (t, &name);
- hash->Update (hash->ctx, (u_int8_t *)name, name->sa_len);
+ hash->Update (hash->ctx, (u_int8_t *)name, sysdep_sa_len (name));
if (exchange->initiator == 0)
hash->Update (hash->ctx, exchange->cookies + ISAKMP_HDR_ICOOKIE_OFF,
ISAKMP_HDR_ICOOKIE_LEN);
diff --git a/sbin/isakmpd/if.c b/sbin/isakmpd/if.c
index ca1e6a8ac05..354ba983356 100644
--- a/sbin/isakmpd/if.c
+++ b/sbin/isakmpd/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.9 2001/08/13 14:33:35 itojun Exp $ */
+/* $OpenBSD: if.c,v 1.10 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: if.c,v 1.12 1999/10/01 13:45:20 niklas Exp $ */
/*
@@ -147,12 +147,8 @@ if_map (void (*func) (char *, struct sockaddr *, void *), void *arg)
{
ifrp = (struct ifreq *)p;
(*func) (ifrp->ifr_name, &ifrp->ifr_addr, arg);
-#ifdef USE_OLD_SOCKADDR
- len = sizeof ifrp->ifr_name + sizeof ifrp->ifr_addr;
-#else
len = sizeof ifrp->ifr_name
- + MAX (ifrp->ifr_addr.sa_len, sizeof ifrp->ifr_addr);
-#endif
+ + MAX (sysdep_sa_len (&ifrp->ifr_addr), sizeof ifrp->ifr_addr);
}
free (ifc.ifc_buf);
return 0;
diff --git a/sbin/isakmpd/ipsec.c b/sbin/isakmpd/ipsec.c
index 72c9b7dffd7..695bf107227 100644
--- a/sbin/isakmpd/ipsec.c
+++ b/sbin/isakmpd/ipsec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ipsec.c,v 1.59 2001/10/26 12:03:07 ho Exp $ */
+/* $OpenBSD: ipsec.c,v 1.60 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: ipsec.c,v 1.143 2000/12/11 23:57:42 niklas Exp $ */
/*
@@ -427,14 +427,18 @@ ipsec_set_network (u_int8_t *src_id, u_int8_t *dst_id, struct ipsec_sa *isa)
if (!isa->src_net)
return -1;
isa->src_net->sa_family = AF_INET;
+#ifndef USE_OLD_SOCKADDR
isa->src_net->sa_len = sizeof (struct sockaddr_in);
+#endif
isa->src_mask =
(struct sockaddr *)calloc (1, sizeof (struct sockaddr_in));
if (!isa->src_mask)
return -1;
isa->src_mask->sa_family = AF_INET;
+#ifndef USE_OLD_SOCKADDR
isa->src_mask->sa_len = sizeof (struct sockaddr_in);
+#endif
break;
case IPSEC_ID_IPV6_ADDR:
@@ -444,14 +448,18 @@ ipsec_set_network (u_int8_t *src_id, u_int8_t *dst_id, struct ipsec_sa *isa)
if (!isa->src_net)
return -1;
isa->src_net->sa_family = AF_INET6;
+#ifndef USE_OLD_SOCKADDR
isa->src_net->sa_len = sizeof (struct sockaddr_in6);
+#endif
isa->src_mask =
(struct sockaddr *)calloc (1, sizeof (struct sockaddr_in6));
if (!isa->src_mask)
return -1;
isa->src_mask->sa_family = AF_INET6;
+#ifndef USE_OLD_SOCKADDR
isa->src_mask->sa_len = sizeof (struct sockaddr_in6);
+#endif
break;
}
@@ -491,14 +499,18 @@ ipsec_set_network (u_int8_t *src_id, u_int8_t *dst_id, struct ipsec_sa *isa)
if (!isa->dst_net)
return -1;
isa->dst_net->sa_family = AF_INET;
+#ifndef USE_OLD_SOCKADDR
isa->dst_net->sa_len = sizeof (struct sockaddr_in);
+#endif
isa->dst_mask =
(struct sockaddr *)calloc (1, sizeof (struct sockaddr_in));
if (!isa->dst_mask)
return -1;
isa->dst_mask->sa_family = AF_INET;
+#ifndef USE_OLD_SOCKADDR
isa->dst_mask->sa_len = sizeof (struct sockaddr_in);
+#endif
break;
case IPSEC_ID_IPV6_ADDR:
@@ -508,14 +520,18 @@ ipsec_set_network (u_int8_t *src_id, u_int8_t *dst_id, struct ipsec_sa *isa)
if (!isa->dst_net)
return -1;
isa->dst_net->sa_family = AF_INET6;
+#ifndef USE_OLD_SOCKADDR
isa->dst_net->sa_len = sizeof (struct sockaddr_in6);
+#endif
isa->dst_mask =
(struct sockaddr *)calloc (1, sizeof (struct sockaddr_in6));
if (!isa->dst_mask)
return -1;
isa->dst_mask->sa_family = AF_INET6;
+#ifndef USE_OLD_SOCKADDR
isa->dst_mask->sa_len = sizeof (struct sockaddr_in6);
+#endif
break;
}
@@ -1624,7 +1640,7 @@ ipsec_handle_leftover_payload (struct message *msg, u_int8_t type,
* non-ready SAs will disappear too.
*/
msg->transport->vtbl->get_dst (msg->transport, &dst);
- while ((sa = sa_lookup_by_peer (dst, dst->sa_len)) != 0)
+ while ((sa = sa_lookup_by_peer (dst, sysdep_sa_len (dst))) != 0)
{
/*
* Don't delete the current SA -- we received the notification
@@ -2122,15 +2138,15 @@ ipsec_add_contact (struct message *msg)
contacts = new_contacts;
}
msg->transport->vtbl->get_dst (msg->transport, &dst);
- addr = malloc (dst->sa_len);
+ addr = malloc (sysdep_sa_len (dst));
if (!addr)
{
- log_error ("ipsec_add_contact: malloc (%d) failed", dst->sa_len);
+ log_error ("ipsec_add_contact: malloc (%d) failed", sysdep_sa_len (dst));
return -1;
}
- memcpy (addr, dst, dst->sa_len);
+ memcpy (addr, dst, sysdep_sa_len (dst));
contacts[contact_cnt].addr = addr;
- contacts[contact_cnt++].len = dst->sa_len;
+ contacts[contact_cnt++].len = sysdep_sa_len (dst);
/*
* XXX There are better algorithms for already mostly-sorted data like
@@ -2147,7 +2163,7 @@ ipsec_contacted (struct message *msg)
struct contact contact;
msg->transport->vtbl->get_dst (msg->transport, &contact.addr);
- contact.len = contact.addr->sa_len;
+ contact.len = sysdep_sa_len (contact.addr);
return contacts
? (bsearch (&contact, contacts, contact_cnt, sizeof *contacts, addr_cmp)
!= 0)
diff --git a/sbin/isakmpd/message.c b/sbin/isakmpd/message.c
index 0cca25ee124..633977427c6 100644
--- a/sbin/isakmpd/message.c
+++ b/sbin/isakmpd/message.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: message.c,v 1.46 2001/10/26 11:37:16 ho Exp $ */
+/* $OpenBSD: message.c,v 1.47 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: message.c,v 1.156 2000/10/10 12:36:39 provos Exp $ */
/*
@@ -1382,7 +1382,7 @@ message_send_delete (struct sa *sa)
struct sockaddr *dst;
sa->transport->vtbl->get_dst (sa->transport, &dst);
- isakmp_sa = sa_isakmp_lookup_by_peer (dst, dst->sa_len);
+ isakmp_sa = sa_isakmp_lookup_by_peer (dst, sysdep_sa_len (dst));
if (!isakmp_sa)
{
/*
diff --git a/sbin/isakmpd/pf_key_v2.c b/sbin/isakmpd/pf_key_v2.c
index 9d867604b31..534a123cdde 100644
--- a/sbin/isakmpd/pf_key_v2.c
+++ b/sbin/isakmpd/pf_key_v2.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_key_v2.c,v 1.90 2001/10/12 15:47:49 ho Exp $ */
+/* $OpenBSD: pf_key_v2.c,v 1.91 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: pf_key_v2.c,v 1.79 2000/12/12 00:33:19 niklas Exp $ */
/*
@@ -161,11 +161,11 @@ pf_key_v2_register_sa_seq (u_int8_t *spi, size_t sz, u_int8_t proto,
node->spi = malloc (sz);
if (!node->spi)
goto cleanup;
- node->dst = malloc (dst->sa_len);
+ node->dst = malloc (sysdep_sa_len (dst));
if (!node->spi)
goto cleanup;
- memcpy (node->dst, dst, dst->sa_len);
- node->dstlen = dst->sa_len;
+ memcpy (node->dst, dst, sysdep_sa_len (dst));
+ node->dstlen = sysdep_sa_len (dst);
memcpy (node->spi, spi, sz);
node->sz = sz;
node->proto = proto;
@@ -191,8 +191,8 @@ pf_key_v2_seq_by_sa (u_int8_t *spi, size_t sz, u_int8_t proto,
node = TAILQ_NEXT (node, link))
if (node->proto == proto
&& node->sz == sz && memcmp (node->spi, spi, sz) == 0
- && node->dstlen == dst->sa_len
- && memcmp (node->dst, dst, dst->sa_len) == 0)
+ && node->dstlen == sysdep_sa_len (dst)
+ && memcmp (node->dst, dst, sysdep_sa_len (dst)) == 0)
return node->seq;
return 0;
}
@@ -681,7 +681,7 @@ pf_key_v2_get_spi (size_t *sz, u_int8_t proto, struct sockaddr *src,
#endif
/* Setup the ADDRESS extensions. */
- len = sizeof (struct sadb_address) + PF_KEY_V2_ROUND (src->sa_len);
+ len = sizeof (struct sadb_address) + PF_KEY_V2_ROUND (sysdep_sa_len (src));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -692,7 +692,7 @@ pf_key_v2_get_spi (size_t *sz, u_int8_t proto, struct sockaddr *src,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, src, src->sa_len);
+ memcpy (addr + 1, src, sysdep_sa_len (src));
switch (((struct sockaddr *)(addr + 1))->sa_family)
{
case AF_INET:
@@ -707,7 +707,7 @@ pf_key_v2_get_spi (size_t *sz, u_int8_t proto, struct sockaddr *src,
goto cleanup;
addr = 0;
- len = sizeof (struct sadb_address) + PF_KEY_V2_ROUND (dst->sa_len);
+ len = sizeof (struct sadb_address) + PF_KEY_V2_ROUND (sysdep_sa_len (dst));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -718,7 +718,7 @@ pf_key_v2_get_spi (size_t *sz, u_int8_t proto, struct sockaddr *src,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, dst, dst->sa_len);
+ memcpy (addr + 1, dst, sysdep_sa_len (dst));
switch (((struct sockaddr *)(addr + 1))->sa_family)
{
case AF_INET:
@@ -775,7 +775,7 @@ pf_key_v2_get_spi (size_t *sz, u_int8_t proto, struct sockaddr *src,
memcpy (spi, &sa->sadb_sa_spi, *sz);
#ifdef KAME
- if (!pf_key_v2_register_sa_seq (spi, *sz, proto, dst, dst->sa_len,
+ if (!pf_key_v2_register_sa_seq (spi, *sz, proto, dst, sysdep_sa_len (dst),
((struct sadb_msg *)(TAILQ_FIRST (ret)->seg))
->sadb_msg_seq))
goto cleanup;
@@ -1012,7 +1012,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
msg.sadb_msg_seq
= (incoming ? pf_key_v2_seq_by_sa (proto->spi[incoming],
sizeof ssa.sadb_sa_spi, proto->proto,
- dst, dst->sa_len)
+ dst, sysdep_sa_len (dst))
: 0);
#else
msg.sadb_msg_seq = sa->seq;
@@ -1107,7 +1107,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
sa->transport->vtbl->get_dst (sa->transport, &src);
else
sa->transport->vtbl->get_src (sa->transport, &src);
- len = sizeof *addr + PF_KEY_V2_ROUND (src->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (src));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1118,7 +1118,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, src, src->sa_len);
+ memcpy (addr + 1, src, sysdep_sa_len (src));
switch (((struct sockaddr *)(addr + 1))->sa_family)
{
case AF_INET:
@@ -1133,7 +1133,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
goto cleanup;
addr = 0;
- len = sizeof *addr + PF_KEY_V2_ROUND (dst->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (dst));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1144,7 +1144,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, dst, dst->sa_len);
+ memcpy (addr + 1, dst, sysdep_sa_len (dst));
switch (((struct sockaddr *)(addr + 1))->sa_family)
{
case AF_INET:
@@ -1163,7 +1163,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
/* XXX I am not sure about what to do here just yet. */
if (iproto->encap_mode == IPSEC_ENCAP_TUNNEL)
{
- len = sizeof *addr + PF_KEY_V2_ROUND (dst->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (dst));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1174,7 +1174,7 @@ pf_key_v2_set_spi (struct sa *sa, struct proto *proto, int incoming,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, dst, dst->sa_len);
+ memcpy (addr + 1, dst, sysdep_sa_len (dst));
switch (((struct sockaddr *)(addr + 1))->sa_family)
{
case AF_INET:
@@ -1706,7 +1706,7 @@ pf_key_v2_flow (struct sockaddr *laddr, struct sockaddr *lmask,
/*
* Setup the ADDRESS extensions.
*/
- len = sizeof *addr + PF_KEY_V2_ROUND (src->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (src));
#ifndef SADB_X_EXT_FLOW_TYPE
if (!delete || ingress)
#else
@@ -1730,7 +1730,7 @@ pf_key_v2_flow (struct sockaddr *laddr, struct sockaddr *lmask,
addr = 0;
}
- len = sizeof *addr + PF_KEY_V2_ROUND (laddr->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (laddr));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1881,7 +1881,7 @@ pf_key_v2_flow (struct sockaddr *laddr, struct sockaddr *lmask,
/*
* Setup the ADDRESS extensions.
*/
- len = sizeof *addr + PF_KEY_V2_ROUND (src->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (src));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1908,7 +1908,7 @@ pf_key_v2_flow (struct sockaddr *laddr, struct sockaddr *lmask,
goto cleanup;
addr = 0;
- len = sizeof *addr + PF_KEY_V2_ROUND (raddr->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (raddr));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -1937,7 +1937,7 @@ pf_key_v2_flow (struct sockaddr *laddr, struct sockaddr *lmask,
/* Setup the POLICY extension. */
len = sizeof *policy + sizeof *ipsecrequest +
- 2 * PF_KEY_V2_ROUND (src->sa_len);
+ 2 * PF_KEY_V2_ROUND (sysdep_sa_len (src));
policy_buf = (u_int8_t *)calloc (1, len);
if (!policy_buf)
{
@@ -2517,7 +2517,7 @@ pf_key_v2_delete_spi (struct sa *sa, struct proto *proto, int incoming)
sa->transport->vtbl->get_dst (sa->transport, &saddr);
else
sa->transport->vtbl->get_src (sa->transport, &saddr);
- len = sizeof *addr + PF_KEY_V2_ROUND (saddr->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (saddr));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -2528,7 +2528,7 @@ pf_key_v2_delete_spi (struct sa *sa, struct proto *proto, int incoming)
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, saddr, saddr->sa_len);
+ memcpy (addr + 1, saddr, sysdep_sa_len (saddr));
switch (saddr->sa_family)
{
case AF_INET:
@@ -2547,7 +2547,7 @@ pf_key_v2_delete_spi (struct sa *sa, struct proto *proto, int incoming)
sa->transport->vtbl->get_src (sa->transport, &saddr);
else
sa->transport->vtbl->get_dst (sa->transport, &saddr);
- len = sizeof *addr + PF_KEY_V2_ROUND (saddr->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (saddr));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -2558,7 +2558,7 @@ pf_key_v2_delete_spi (struct sa *sa, struct proto *proto, int incoming)
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, saddr, saddr->sa_len);
+ memcpy (addr + 1, saddr, sysdep_sa_len (saddr));
switch (saddr->sa_family)
{
case AF_INET:
@@ -3985,7 +3985,7 @@ pf_key_v2_group_spis (struct sa *sa, struct proto *proto1,
sa->transport->vtbl->get_src (sa->transport, &saddr);
else
sa->transport->vtbl->get_dst (sa->transport, &saddr);
- len = sizeof *addr + PF_KEY_V2_ROUND (saddr->sa_len);
+ len = sizeof *addr + PF_KEY_V2_ROUND (sysdep_sa_len (saddr));
addr = calloc (1, len);
if (!addr)
goto cleanup;
@@ -3996,7 +3996,7 @@ pf_key_v2_group_spis (struct sa *sa, struct proto *proto1,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, saddr, saddr->sa_len);
+ memcpy (addr + 1, saddr, sysdep_sa_len (saddr));
((struct sockaddr_in *)(addr + 1))->sin_port = 0;
if (pf_key_v2_msg_add (grpspis, (struct sadb_ext *)addr,
PF_KEY_V2_NODE_MALLOCED) == -1)
@@ -4013,7 +4013,7 @@ pf_key_v2_group_spis (struct sa *sa, struct proto *proto1,
addr->sadb_address_prefixlen = 0;
#endif
addr->sadb_address_reserved = 0;
- memcpy (addr + 1, saddr, saddr->sa_len);
+ memcpy (addr + 1, saddr, sysdep_sa_len (saddr));
((struct sockaddr_in *)(addr + 1))->sin_port = 0;
if (pf_key_v2_msg_add (grpspis, (struct sadb_ext *)addr,
PF_KEY_V2_NODE_MALLOCED) == -1)
diff --git a/sbin/isakmpd/sa.c b/sbin/isakmpd/sa.c
index 66b4ed1bc02..1e834268480 100644
--- a/sbin/isakmpd/sa.c
+++ b/sbin/isakmpd/sa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sa.c,v 1.48 2001/08/15 13:06:53 ho Exp $ */
+/* $OpenBSD: sa.c,v 1.49 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: sa.c,v 1.112 2000/12/12 00:22:52 niklas Exp $ */
/*
@@ -60,10 +60,6 @@
#include "policy.h"
#include "key.h"
-#ifndef SA_LEN
-#define SA_LEN(x) (x)->sa_len
-#endif
-
/* Initial number of bits from the cookies used as hash. */
#define INITIAL_BUCKET_BITS 6
@@ -206,8 +202,8 @@ sa_check_peer (struct sa *sa, void *v_addr)
return 0;
sa->transport->vtbl->get_dst (sa->transport, &dst);
- return dst->sa_len == addr->len
- && memcmp (dst, addr->addr, dst->sa_len) == 0;
+ return sysdep_sa_len (dst) == addr->len
+ && memcmp (dst, addr->addr, sysdep_sa_len (dst)) == 0;
}
struct dst_isakmpspi_arg {
@@ -231,8 +227,8 @@ isakmp_sa_check (struct sa *sa, void *v_arg)
/* verify address is either src or dst for this sa */
sa->transport->vtbl->get_dst (sa->transport, &dst);
sa->transport->vtbl->get_src (sa->transport, &src);
- if (memcmp (src, arg->dst, SA_LEN(src)) &&
- memcmp (dst, arg->dst, SA_LEN(dst)))
+ if (memcmp (src, arg->dst, sysdep_sa_len (src)) &&
+ memcmp (dst, arg->dst, sysdep_sa_len (dst)))
return 0;
/* match icookie+rcookie against spi */
diff --git a/sbin/isakmpd/udp.c b/sbin/isakmpd/udp.c
index 446f677f207..30611d4fa8a 100644
--- a/sbin/isakmpd/udp.c
+++ b/sbin/isakmpd/udp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp.c,v 1.52 2001/10/09 14:53:05 ho Exp $ */
+/* $OpenBSD: udp.c,v 1.53 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: udp.c,v 1.57 2001/01/26 10:09:57 niklas Exp $ */
/*
@@ -125,8 +125,8 @@ udp_listen_lookup (struct sockaddr *addr)
struct udp_transport *u;
for (u = LIST_FIRST (&udp_listen_list); u; u = LIST_NEXT (u, link))
- if (u->src->sa_len == addr->sa_len
- && memcmp (u->src, addr, addr->sa_len) == 0)
+ if (sysdep_sa_len (u->src) == sysdep_sa_len (addr)
+ && memcmp (u->src, addr, sysdep_sa_len (addr)) == 0)
return u;
return 0;
}
@@ -189,7 +189,7 @@ udp_make (struct sockaddr *laddr)
t->transport.vtbl = &udp_transport_vtbl;
t->src = laddr;
- if (bind (s, t->src, t->src->sa_len))
+ if (bind (s, t->src, sysdep_sa_len (t->src)))
{
char *tstr;
if (sockaddr2text (t->src, &tstr, 0))
@@ -237,24 +237,24 @@ udp_clone (struct udp_transport *u, struct sockaddr *raddr)
memcpy (u2, u, sizeof *u);
- u2->src = malloc (u->src->sa_len);
+ u2->src = malloc (sysdep_sa_len (u->src));
if (!u2->src)
{
- log_error ("udp_clone: malloc (%d) failed", u->src->sa_len);
+ log_error ("udp_clone: malloc (%d) failed", sysdep_sa_len (u->src));
free (t);
return 0;
}
- memcpy (u2->src, u->src, u->src->sa_len);
+ memcpy (u2->src, u->src, sysdep_sa_len (u->src));
- u2->dst = malloc (raddr->sa_len);
+ u2->dst = malloc (sysdep_sa_len (raddr));
if (!u2->dst)
{
- log_error ("udp_clone: malloc (%d) failed", raddr->sa_len);
+ log_error ("udp_clone: malloc (%d) failed", sysdep_sa_len (raddr));
free (u2->src);
free (t);
return 0;
}
- memcpy (u2->dst, raddr, raddr->sa_len);
+ memcpy (u2->dst, raddr, sysdep_sa_len (raddr));
t->flags &= ~TRANSPORT_LISTEN;
@@ -272,12 +272,12 @@ udp_clone (struct udp_transport *u, struct sockaddr *raddr)
static struct transport *
udp_bind (const struct sockaddr *addr)
{
- struct sockaddr *src = malloc (addr->sa_len);
+ struct sockaddr *src = malloc (sysdep_sa_len ((struct sockaddr *)addr));
if (!src)
return 0;
- memcpy (src, addr, addr->sa_len);
+ memcpy (src, addr, sysdep_sa_len ((struct sockaddr *)addr));
return udp_make (src);
}
@@ -303,16 +303,11 @@ udp_bind_if (char *ifname, struct sockaddr *if_addr, void *arg)
/*
* Well, UDP is an internet protocol after all so drop other ifreqs.
*/
-#ifdef USE_OLD_SOCKADDR
- if (if_addr->sa_family != AF_INET && if_addr->sa_family != AF_INET6)
- return;
-#else
if ((if_addr->sa_family != AF_INET
- || if_addr->sa_len != sizeof (struct sockaddr_in))
+ || sysdep_sa_len (if_addr) != sizeof (struct sockaddr_in))
&& (if_addr->sa_family != AF_INET6
- || if_addr->sa_len != sizeof (struct sockaddr_in6)))
+ || sysdep_sa_len (if_addr) != sizeof (struct sockaddr_in6)))
return;
-#endif
/*
* These special addresses are not useable as they have special meaning
@@ -412,7 +407,7 @@ udp_bind_if (char *ifname, struct sockaddr *if_addr, void *arg)
}
/* If found, take the easy way out. */
- if (memcmp (addr, if_addr, addr->sa_len) == 0)
+ if (memcmp (addr, if_addr, sysdep_sa_len (addr)) == 0)
{
free (addr);
break;
@@ -775,7 +770,7 @@ udp_send_message (struct message *msg)
* given, or else EISCONN will occur.
*/
m.msg_name = (caddr_t)u->dst;
- m.msg_namelen = u->dst->sa_len;
+ m.msg_namelen = sysdep_sa_len (u->dst);
m.msg_iov = msg->iov;
m.msg_iovlen = msg->iovlen;
m.msg_control = 0;
@@ -819,7 +814,7 @@ udp_decode_ids (struct transport *t)
#ifdef HAVE_GETNAMEINFO
if (getnameinfo (((struct udp_transport *)t)->src,
- ((struct udp_transport *)t)->src->sa_len,
+ sysdep_sa_len (((struct udp_transport *)t)->src),
idsrc, sizeof idsrc, NULL, 0, NI_NUMERICHOST) != 0)
{
log_print ("udp_decode_ids: getnameinfo () failed for 'src'");
@@ -827,7 +822,7 @@ udp_decode_ids (struct transport *t)
}
if (getnameinfo (((struct udp_transport *)t)->dst,
- ((struct udp_transport *)t)->dst->sa_len,
+ sysdep_sa_len (((struct udp_transport *)t)->dst),
iddst, sizeof iddst, NULL, 0, NI_NUMERICHOST) != 0)
{
log_print ("udp_decode_ids: getnameinfo () failed for 'dst'");
diff --git a/sbin/isakmpd/util.c b/sbin/isakmpd/util.c
index 27d1d8491c2..b8465d19bf8 100644
--- a/sbin/isakmpd/util.c
+++ b/sbin/isakmpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.22 2001/10/26 12:03:07 ho Exp $ */
+/* $OpenBSD: util.c,v 1.23 2001/10/26 13:29:26 ho Exp $ */
/* $EOM: util.c,v 1.23 2000/11/23 12:22:08 niklas Exp $ */
/*
@@ -263,11 +263,11 @@ text2sockaddr (char *address, char *port, struct sockaddr **sa)
if (getaddrinfo (address, port, &hints, &ai))
return -1;
- *sa = malloc (ai->ai_addr->sa_len);
+ *sa = malloc (sysdep_sa_len (ai->ai_addr));
if (!sa)
return -1;
- memcpy (*sa, ai->ai_addr, ai->ai_addr->sa_len);
+ memcpy (*sa, ai->ai_addr, sysdep_sa_len (ai->ai_addr));
freeaddrinfo (ai);
return 0;
#else
@@ -282,7 +282,9 @@ text2sockaddr (char *address, char *port, struct sockaddr **sa)
if (!*sa)
return -1;
+#ifndef USE_OLD_SOCKADDR
(*sa)->sa_len = sz;
+#endif
(*sa)->sa_family = af;
if (inet_pton (af, address, sockaddr_addrdata (*sa)) != 1)
{
@@ -324,7 +326,7 @@ sockaddr2text (struct sockaddr *sa, char **address, int zflag)
int i, j;
#ifdef HAVE_GETNAMEINFO
- if (getnameinfo (sa, sa->sa_len, buf, sizeof buf, 0, 0,
+ if (getnameinfo (sa, sysdep_sa_len (sa), buf, sizeof buf, 0, 0,
allow_name_lookups ? 0 : NI_NUMERICHOST))
return -1;
#else
@@ -455,23 +457,13 @@ util_ntoa (char **buf, int af, u_int8_t *addr)
struct sockaddr_storage from;
struct sockaddr *sfrom = (struct sockaddr *)&from;
socklen_t fromlen = sizeof from;
- u_int32_t ip4_buf;
memset (&from, 0, fromlen);
sfrom->sa_family = af;
- switch (af)
- {
- case AF_INET:
- sfrom->sa_len = sizeof (struct sockaddr_in);
- memcpy (&ip4_buf, addr, sizeof (struct in_addr));
- ((struct sockaddr_in *)sfrom)->sin_addr.s_addr = ip4_buf;
- break;
-
- case AF_INET6:
- sfrom->sa_len = sizeof (struct sockaddr_in6);
- memcpy (sockaddr_addrdata (sfrom), addr, sizeof (struct in6_addr));
- break;
- }
+#ifndef USE_OLD_SOCKADDR
+ sfrom->sa_len = sysdep_sa_len (sfrom);
+#endif
+ memcpy (sockaddr_addrdata (sfrom), addr, sockaddr_addrlen (sfrom));
if (sockaddr2text (sfrom, buf, 0))
{