Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net add inet6_scopeid



details:   https://anonhg.NetBSD.org/src/rev/e17b3889e4d5
branches:  trunk
changeset: 790655:e17b3889e4d5
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Oct 19 00:08:34 2013 +0000

description:
add inet6_scopeid

diffstat:

 lib/libc/net/Makefile.inc    |   4 +-
 lib/libc/net/inet6_scopeid.c |  71 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 2 deletions(-)

diffs (93 lines):

diff -r f1f8a14dc3c6 -r e17b3889e4d5 lib/libc/net/Makefile.inc
--- a/lib/libc/net/Makefile.inc Sat Oct 19 00:06:50 2013 +0000
+++ b/lib/libc/net/Makefile.inc Sat Oct 19 00:08:34 2013 +0000
@@ -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 @@
 
 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
 
diff -r f1f8a14dc3c6 -r e17b3889e4d5 lib/libc/net/inet6_scopeid.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/net/inet6_scopeid.c      Sat Oct 19 00:08:34 2013 +0000
@@ -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
+}



Home | Main Index | Thread Index | Old Index