rip6query.c (04e8772051398d25637351f794866c6084a47229) | rip6query.c (2b39a7c8ef19ea8d5721b74c932e7c931ef5bfff) |
---|---|
1/* 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. | 1/* 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. | 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. |
16 * | 16 * |
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- 6 unchanged lines hidden (view full) --- 31 32#include <stdio.h> 33 34#include <unistd.h> 35#include <stdlib.h> 36#include <string.h> 37#include <ctype.h> 38#include <signal.h> | 17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT --- 6 unchanged lines hidden (view full) --- 31 32#include <stdio.h> 33 34#include <unistd.h> 35#include <stdlib.h> 36#include <string.h> 37#include <ctype.h> 38#include <signal.h> |
39#include <errno.h> |
|
39#include <err.h> 40 41#include <sys/types.h> 42#include <sys/socket.h> 43#include <net/if.h> | 40#include <err.h> 41 42#include <sys/types.h> 43#include <sys/socket.h> 44#include <net/if.h> |
45#if defined(__FreeBSD__) && __FreeBSD__ >= 3 |
|
44#include <net/if_var.h> | 46#include <net/if_var.h> |
47#endif /* __FreeBSD__ >= 3 */ |
|
45#include <netinet/in.h> 46#include <netinet/in_var.h> 47#include <arpa/inet.h> 48#include <netdb.h> 49 50#include "route6d.h" 51 52/* wrapper for KAME-special getnameinfo() */ 53#ifndef NI_WITHSCOPEID | 48#include <netinet/in.h> 49#include <netinet/in_var.h> 50#include <arpa/inet.h> 51#include <netdb.h> 52 53#include "route6d.h" 54 55/* wrapper for KAME-special getnameinfo() */ 56#ifndef NI_WITHSCOPEID |
54#define NI_WITHSCOPEID 0 | 57#define NI_WITHSCOPEID 0 |
55#endif 56 57int s; | 58#endif 59 60int s; |
58extern int errno; | |
59struct sockaddr_in6 sin6; 60struct rip6 *ripbuf; 61 62#define RIPSIZE(n) (sizeof(struct rip6) + (n-1) * sizeof(struct netinfo6)) 63 64int main __P((int, char **)); 65static void usage __P((void)); 66static const char *sa_n2a __P((struct sockaddr *)); 67static const char *inet6_n2a __P((struct in6_addr *)); 68 69int 70main(argc, argv) 71 int argc; 72 char **argv; 73{ 74 struct netinfo6 *np; 75 struct sockaddr_in6 fsock; 76 int i, n, len, flen; 77 int c; | 61struct sockaddr_in6 sin6; 62struct rip6 *ripbuf; 63 64#define RIPSIZE(n) (sizeof(struct rip6) + (n-1) * sizeof(struct netinfo6)) 65 66int main __P((int, char **)); 67static void usage __P((void)); 68static const char *sa_n2a __P((struct sockaddr *)); 69static const char *inet6_n2a __P((struct in6_addr *)); 70 71int 72main(argc, argv) 73 int argc; 74 char **argv; 75{ 76 struct netinfo6 *np; 77 struct sockaddr_in6 fsock; 78 int i, n, len, flen; 79 int c; |
78 extern char *optarg; 79 extern int optind; | |
80 int ifidx = -1; 81 int error; 82 char pbuf[10]; 83 struct addrinfo hints, *res; 84 85 while ((c = getopt(argc, argv, "I:")) != EOF) { 86 switch (c) { 87 case 'I': --- 21 unchanged lines hidden (view full) --- 109 err(1, "socket"); 110 /*NOTREACHED*/ 111 } 112 113 /* getaddrinfo is preferred for addr@ifname syntax */ 114 snprintf(pbuf, sizeof(pbuf), "%d", RIP6_PORT); 115 memset(&hints, 0, sizeof(hints)); 116 hints.ai_family = AF_INET6; | 80 int ifidx = -1; 81 int error; 82 char pbuf[10]; 83 struct addrinfo hints, *res; 84 85 while ((c = getopt(argc, argv, "I:")) != EOF) { 86 switch (c) { 87 case 'I': --- 21 unchanged lines hidden (view full) --- 109 err(1, "socket"); 110 /*NOTREACHED*/ 111 } 112 113 /* getaddrinfo is preferred for addr@ifname syntax */ 114 snprintf(pbuf, sizeof(pbuf), "%d", RIP6_PORT); 115 memset(&hints, 0, sizeof(hints)); 116 hints.ai_family = AF_INET6; |
117 hints.ai_socktype = SOCK_STREAM; | 117 hints.ai_socktype = SOCK_DGRAM; |
118 error = getaddrinfo(argv[0], pbuf, &hints, &res); 119 if (error) { | 118 error = getaddrinfo(argv[0], pbuf, &hints, &res); 119 if (error) { |
120 fprintf(stderr, "rip6query: %s: %s\n", argv[0], 121 gai_strerror(error)); 122 if (error == EAI_SYSTEM) 123 errx(1, "%s", strerror(errno)); 124 exit(1); | 120 errx(1, "%s: %s", argv[0], gai_strerror(error)); |
125 /*NOTREACHED*/ 126 } 127 if (res->ai_next) { 128 errx(1, "%s: %s", argv[0], "resolved to multiple addrs"); 129 /*NOTREACHED*/ 130 } 131 if (sizeof(sin6) != res->ai_addrlen) { 132 errx(1, "%s: %s", argv[0], "invalid addrlen"); --- 51 unchanged lines hidden (view full) --- 184 fprintf(stderr, "Usage: rip6query [-I iface] address\n"); 185} 186 187/* getnameinfo() is preferred as we may be able to show ifindex as ifname */ 188static const char * 189sa_n2a(sa) 190 struct sockaddr *sa; 191{ | 121 /*NOTREACHED*/ 122 } 123 if (res->ai_next) { 124 errx(1, "%s: %s", argv[0], "resolved to multiple addrs"); 125 /*NOTREACHED*/ 126 } 127 if (sizeof(sin6) != res->ai_addrlen) { 128 errx(1, "%s: %s", argv[0], "invalid addrlen"); --- 51 unchanged lines hidden (view full) --- 180 fprintf(stderr, "Usage: rip6query [-I iface] address\n"); 181} 182 183/* getnameinfo() is preferred as we may be able to show ifindex as ifname */ 184static const char * 185sa_n2a(sa) 186 struct sockaddr *sa; 187{ |
192 static char buf[BUFSIZ]; | 188 static char buf[NI_MAXHOST]; |
193 194 if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), 195 NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) != 0) { 196 snprintf(buf, sizeof(buf), "%s", "(invalid)"); 197 } 198 return buf; 199} 200 201static const char * 202inet6_n2a(addr) 203 struct in6_addr *addr; 204{ | 189 190 if (getnameinfo(sa, sa->sa_len, buf, sizeof(buf), 191 NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) != 0) { 192 snprintf(buf, sizeof(buf), "%s", "(invalid)"); 193 } 194 return buf; 195} 196 197static const char * 198inet6_n2a(addr) 199 struct in6_addr *addr; 200{ |
205 static char buf[BUFSIZ]; | 201 static char buf[NI_MAXHOST]; |
206 207 return inet_ntop(AF_INET6, addr, buf, sizeof(buf)); 208} | 202 203 return inet_ntop(AF_INET6, addr, buf, sizeof(buf)); 204} |