📄 inet6.c
字号:
/* * Copyright (c) 2004 Ying Ge, Communication Research Center Canada. * * Copyright (c) 2002, 2003 Maoyu Wang, Communication Research Center Canada. * * By Ying Ge: * 1. Change the OLSR packet format and message processing procedure based * on the OLSR RFC. * 2. Add support of multiple interfaces to OLSR, including MID message * creating and processing procedure as specified in the OLSR RFC. * 3. Add QoS Support to OLSR * * By Maoyu Wang: * 1. Ported OLSR from IPv4 to IPv6. * 2. Added the Host and Network Association (HNA) functionality into OLSR. * 3. Added the default gateway functionality into OLSR by extending the HNA * message usage. The default gateway functionality supported the mobility * by cooperating with Mobile IPv6 for a mobile node as well as supported * Internet access for MANET nodes. * * DISTRIBUTED WITH NO WARRANTY, EXPRESS OR IMPLIED. * See the GNU Library General Public License (file COPYING in the distribution) * for conditions of use and redistribution *//* * lib/inet6.c This file contains an implementation of the "INET6" * support functions for the net-tools. * (most of it copied from lib/inet.c 1.26). * * Version: $Id: inet6.c,v 1.10 2000/10/28 11:04:00 pb Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation * * Modified: *960808 {0.01} Frank Strauss : adapted for IPv6 support *980701 {0.02} Arnaldo C. Melo: GNU gettext instead of catgets *990824 Bernd Eckenfels: clear members for selecting v6 address * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software * Foundation; either version 2 of the License, or (at * your option) any later version. * * 2002-April_26 Modified by Maoyu Wang for porting olsr from IPV4 to IPV6 */ #include "config.h"#ifdef IPV6#include <asm/types.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <arpa/nameser.h>#include <ctype.h>#include <errno.h>#include <netdb.h>#include <resolv.h>#include <stdlib.h>#include <string.h>#include <stdio.h>#include <unistd.h>#include "version.h"#include "net-support.h"#include "pathnames.h"#include "intl.h"#include "util.h"extern int h_errno; /* some netdb.h versions don't export this */static int inet6_resolve(char *name, struct sockaddr_in6 *sin6){ struct addrinfo req, *ai; int s; memset (&req, '0', sizeof (req)); req.ai_family = AF_INET6; if ((s = getaddrinfo(name, NULL, &req, &ai))) { fprintf(stderr, "getaddrinfo: %s: %d\n", name, s); return -1; } memcpy(sin6, ai->ai_addr, sizeof(struct sockaddr_in6)); freeaddrinfo(ai); return (0);}#ifndef IN6_IS_ADDR_UNSPECIFIED#define IN6_IS_ADDR_UNSPECIFIED(a) \ (((__u32 *) (a))[0] == 0 && ((__u32 *) (a))[1] == 0 && \ ((__u32 *) (a))[2] == 0 && ((__u32 *) (a))[3] == 0)#endifstatic int inet6_rresolve(char *name, struct sockaddr_in6 *sin6, int numeric){ int s; /* Grmpf. -FvK */ if (sin6->sin6_family != AF_INET6) {#ifdef DEBUG fprintf(stderr, _("rresolve: unsupport address family %d !\n"), sin6->sin6_family);#endif errno = EAFNOSUPPORT; return (-1); } if (numeric & 0x7FFF) { inet_ntop(AF_INET6, &sin6->sin6_addr, name, 80); return (0); } if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { if (numeric & 0x8000) strcpy(name, "default"); else strcpy(name, "*"); return (0); } if ((s = getnameinfo((struct sockaddr *) sin6, sizeof(struct sockaddr_in6), name, 255 /* !! */ , NULL, 0, 0))) { fputs("getnameinfo failed\n", stderr); return -1; } return (0);}void inet6_reserror(char *text){ herror(text);}/* Display an Internet socket address. */void inet6_print(struct in6_addr * ptr){ char name[80]; inet_ntop(AF_INET6, (struct in6_addr *) ptr, name, 80); printf return;}/* Display an Internet socket address. *//* dirty! struct sockaddr usually doesn't suffer for inet6 addresses, fst. */char inet6_sprint(struct sockaddr *sap, int numeric){ static char buff[128]; if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return safe_strncpy(buff, _("[NONE SET]"), sizeof(buff)); if (inet6_rresolve(buff, (struct sockaddr_in6 *) sap, numeric) != 0) return safe_strncpy(buff, _("[UNKNOWN]"), sizeof(buff)); return (buff);}/*int inet6_getsock(char *bufp, struct sockaddr *sap){ struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)sap; sin6->sin6_family = AF_INET6; sin6->sin6_port = 0; if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) return (-1); return 0; }*/int inet6_input(char *bufp, struct sockaddr *sap){ struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)sap; sin6->sin6_family = AF_INET6; sin6->sin6_port = 0; if (inet_pton(AF_INET6, bufp, sin6->sin6_addr.s6_addr) <= 0) return (-1); return 0; }#endif /* HAVE_AFINET6 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -