krb5 commit: Replace casts with use of sa2sin and sa2sin6
Greg Hudson
ghudson at mit.edu
Fri Apr 14 12:14:34 EDT 2017
https://github.com/krb5/krb5/commit/d225fb9e9575e31712db9f23684d284282ff2668
commit d225fb9e9575e31712db9f23684d284282ff2668
Author: Robbie Harwood <rharwood at redhat.com>
Date: Fri Feb 17 17:16:19 2017 -0500
Replace casts with use of sa2sin and sa2sin6
src/lib/krb5/os/hostaddr.c | 4 ++--
src/lib/krb5/os/localaddr.c | 17 +++++++++--------
src/lib/rpc/pmap_rmt.c | 6 +++---
src/slave/kprop_util.c | 4 ++--
4 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/src/lib/krb5/os/hostaddr.c b/src/lib/krb5/os/hostaddr.c
index 22f6ad6..d7a4a76 100644
--- a/src/lib/krb5/os/hostaddr.c
+++ b/src/lib/krb5/os/hostaddr.c
@@ -83,12 +83,12 @@ k5_os_hostaddr(krb5_context context, const char *name,
switch (aip->ai_addr->sa_family) {
case AF_INET:
addrlen = sizeof (struct in_addr);
- ptr = &((struct sockaddr_in *)aip->ai_addr)->sin_addr;
+ ptr = &sa2sin(aip->ai_addr)->sin_addr;
atype = ADDRTYPE_INET;
break;
case AF_INET6:
addrlen = sizeof (struct in6_addr);
- ptr = &((struct sockaddr_in6 *)aip->ai_addr)->sin6_addr;
+ ptr = &sa2sin6(aip->ai_addr)->sin6_addr;
atype = ADDRTYPE_INET6;
break;
default:
diff --git a/src/lib/krb5/os/localaddr.c b/src/lib/krb5/os/localaddr.c
index 9f77652..21bc719 100644
--- a/src/lib/krb5/os/localaddr.c
+++ b/src/lib/krb5/os/localaddr.c
@@ -181,11 +181,11 @@ is_loopback_address(struct sockaddr *sa)
{
switch (sa->sa_family) {
case AF_INET: {
- struct sockaddr_in *s4 = (struct sockaddr_in *)sa;
+ struct sockaddr_in *s4 = sa2sin(sa);
return s4->sin_addr.s_addr == htonl(INADDR_LOOPBACK);
}
case AF_INET6: {
- struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)sa;
+ struct sockaddr_in6 *s6 = sa2sin6(sa);
return IN6_IS_ADDR_LOOPBACK(&s6->sin6_addr);
}
default:
@@ -239,16 +239,17 @@ printifaddr(struct ifaddrs *ifp)
#include <stdlib.h>
static int
-addr_eq (const struct sockaddr *s1, const struct sockaddr *s2)
+addr_eq (struct sockaddr *s1, struct sockaddr *s2)
{
if (s1->sa_family != s2->sa_family)
return 0;
-#define CMPTYPE(T,F) (!memcmp(&((const T*)s1)->F,&((const T*)s2)->F,sizeof(((const T*)s1)->F)))
switch (s1->sa_family) {
case AF_INET:
- return CMPTYPE (struct sockaddr_in, sin_addr);
+ return !memcmp(&sa2sin(s1)->sin_addr, &sa2sin(s2)->sin_addr,
+ sizeof(sa2sin(s1)->sin_addr));
case AF_INET6:
- return CMPTYPE (struct sockaddr_in6, sin6_addr);
+ return !memcmp(&sa2sin6(s1)->sin6_addr, &sa2sin6(s2)->sin6_addr,
+ sizeof(sa2sin6(s1)->sin6_addr));
default:
/* Err on side of duplicate listings. */
return 0;
@@ -1183,14 +1184,14 @@ add_addr (void *P_data, struct sockaddr *a)
#ifdef HAVE_NETINET_IN_H
case AF_INET:
address = make_addr (ADDRTYPE_INET, sizeof (struct in_addr),
- &((const struct sockaddr_in *) a)->sin_addr);
+ &sa2sin(a)->sin_addr);
if (address == NULL)
data->mem_err++;
break;
case AF_INET6:
{
- const struct sockaddr_in6 *in = (const struct sockaddr_in6 *) a;
+ const struct sockaddr_in6 *in = sa2sin6(a);
if (IN6_IS_ADDR_LINKLOCAL (&in->sin6_addr))
break;
diff --git a/src/lib/rpc/pmap_rmt.c b/src/lib/rpc/pmap_rmt.c
index cd0b309..4829e3f 100644
--- a/src/lib/rpc/pmap_rmt.c
+++ b/src/lib/rpc/pmap_rmt.c
@@ -60,6 +60,7 @@ static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
#include <arpa/inet.h>
#define MAX_BROADCAST_SIZE 1400
#include <port-sockets.h>
+#include "socket-utils.h"
static struct timeval timeout = { 3, 0 };
@@ -208,12 +209,11 @@ getbroadcastnets(
if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) {
addrs[i++].s_addr = INADDR_ANY;
} else {
- addrs[i++] = ((struct sockaddr_in*)
- &ifreq.ifr_addr)->sin_addr;
+ addrs[i++] = sa2sin(&ifreq.ifr_addr)->sin_addr;
}
#else /* 4.2 BSD */
struct sockaddr_in *sockin;
- sockin = (struct sockaddr_in *)&ifr->ifr_addr;
+ sockin = sa2sin(&ifr->ifr_addr);
addrs[i++] = inet_makeaddr(inet_netof
(sockin->sin_addr.s_addr), INADDR_ANY);
#endif
diff --git a/src/slave/kprop_util.c b/src/slave/kprop_util.c
index f182554..7e1ec22 100644
--- a/src/slave/kprop_util.c
+++ b/src/slave/kprop_util.c
@@ -45,12 +45,12 @@ sockaddr2krbaddr(krb5_context context, int family, struct sockaddr *sa,
addr.magic = KV5M_ADDRESS;
if (family == AF_INET) {
- struct sockaddr_in *sa4 = (struct sockaddr_in *) sa;
+ struct sockaddr_in *sa4 = sa2sin(sa);
addr.addrtype = ADDRTYPE_INET;
addr.length = sizeof(sa4->sin_addr);
addr.contents = (krb5_octet *) &sa4->sin_addr;
} else if (family == AF_INET6) {
- struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *) sa;
+ struct sockaddr_in6 *sa6 = sa2sin6(sa);
if (IN6_IS_ADDR_V4MAPPED(&sa6->sin6_addr)) {
addr.addrtype = ADDRTYPE_INET;
addr.contents = (krb5_octet *) &sa6->sin6_addr + 12;
More information about the cvs-krb5
mailing list