avoid pointer gymnastics

This commit is contained in:
christos 2013-10-18 21:01:00 +00:00
parent 6e28978d84
commit 77f96119f9

View File

@ -1,4 +1,4 @@
/* $NetBSD: route.c,v 1.140 2013/03/01 18:25:17 joerg Exp $ */
/* $NetBSD: route.c,v 1.141 2013/10/18 21:01:00 christos Exp $ */
/*
* Copyright (c) 1983, 1989, 1991, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1991, 1993\
#if 0
static char sccsid[] = "@(#)route.c 8.6 (Berkeley) 4/28/95";
#else
__RCSID("$NetBSD: route.c,v 1.140 2013/03/01 18:25:17 joerg Exp $");
__RCSID("$NetBSD: route.c,v 1.141 2013/10/18 21:01:00 christos Exp $");
#endif
#endif /* not lint */
@ -543,8 +543,10 @@ routename(const struct sockaddr *sa, struct sockaddr *nm, int flags)
(IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
sin6.sin6_scope_id == 0) {
sin6.sin6_scope_id =
ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
uint16_t scope;
memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
sizeof(scope));
sin6.sin6_scope_id = ntohs(scope);
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
}
@ -710,8 +712,10 @@ netname(const struct sockaddr *sa, struct sockaddr *nm)
(IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr) ||
IN6_IS_ADDR_MC_LINKLOCAL(&sin6.sin6_addr)) &&
sin6.sin6_scope_id == 0) {
sin6.sin6_scope_id =
ntohs(*(u_int16_t *)&sin6.sin6_addr.s6_addr[2]);
uint16_t scope;
memcpy(&scope, &sin6.sin6_addr.s6_addr[2],
sizeof(scope));
sin6.sin6_scope_id = ntohs(scope);
sin6.sin6_addr.s6_addr[2] = 0;
sin6.sin6_addr.s6_addr[3] = 0;
}
@ -1259,8 +1263,10 @@ getaddr(int which, const char *s, struct hostent **hpp, struct sou *soup)
if ((IN6_IS_ADDR_LINKLOCAL(&su->sin6.sin6_addr) ||
IN6_IS_ADDR_MC_LINKLOCAL(&su->sin6.sin6_addr)) &&
su->sin6.sin6_scope_id) {
*(u_int16_t *)&su->sin6.sin6_addr.s6_addr[2] =
htons(su->sin6.sin6_scope_id);
uint16_t scope;
scope = htons(su->sin6.sin6_scope_id);
memcpy(&su->sin6.sin6_addr.s6_addr[2], &scope,
sizeof(scope));
su->sin6.sin6_scope_id = 0;
}
#endif