Module Name: src Committed By: christos Date: Sat Oct 19 00:08:34 UTC 2013
Modified Files: src/lib/libc/net: Makefile.inc Added Files: src/lib/libc/net: inet6_scopeid.c Log Message: add inet6_scopeid To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/lib/libc/net/Makefile.inc cvs rdiff -u -r0 -r1.1 src/lib/libc/net/inet6_scopeid.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/net/Makefile.inc diff -u src/lib/libc/net/Makefile.inc:1.83 src/lib/libc/net/Makefile.inc:1.84 --- src/lib/libc/net/Makefile.inc:1.83 Fri Mar 1 13:25:16 2013 +++ src/lib/libc/net/Makefile.inc Fri Oct 18 20:08:34 2013 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.83 2013/03/01 18:25:16 joerg Exp $ +# $NetBSD: Makefile.inc,v 1.84 2013/10/19 00:08:34 christos Exp $ # @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # net sources @@ -24,7 +24,7 @@ COPTS.hesiod.c+= ${${ACTIVE_CC} == "gcc" SRCS+= getaddrinfo.c getnameinfo.c .if (${USE_INET6} != "no") -SRCS+= ip6opt.c rthdr.c vars6.c +SRCS+= ip6opt.c rthdr.c vars6.c inet6_scopeid.c .endif SRCS+= if_indextoname.c if_nameindex.c if_nametoindex.c Added files: Index: src/lib/libc/net/inet6_scopeid.c diff -u /dev/null src/lib/libc/net/inet6_scopeid.c:1.1 --- /dev/null Fri Oct 18 20:08:34 2013 +++ src/lib/libc/net/inet6_scopeid.c Fri Oct 18 20:08:34 2013 @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 2003 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: inet6_scopeid.c,v 1.1 2013/10/19 00:08:34 christos Exp $"); + +#include <sys/endian.h> +#include <string.h> +#include <stdint.h> +#include <netinet/in.h> +#include <netinet6/in6.h> + +/* KAME idiosyncrasy */ +void +inet6_getscopeid(struct sockaddr_in6 *sin6, int flags) +{ +#if defined(__KAME__) + if ((IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) && (flags & 1)) || + (IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr) && (flags & 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] = sin6->sin6_addr.s6_addr[3] = 0; + } +#endif +} + +void +inet6_putscopeid(struct sockaddr_in6 *sin6, int flags) +{ +#if defined(__KAME__) + if ((IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) && (flags & 1)) || + (IN6_IS_ADDR_MC_LINKLOCAL(&sin6->sin6_addr) && (flags & 2))) { + uint16_t scope = htons(sin6->sin6_scope_id); + memcpy(&sin6->sin6_addr.s6_addr[2], &scope, sizeof(scope)); + sin6->sin6_scope_id = 0; + } +#endif +}