Stealth Mode script
[tomato.git] / release / src / router / miniupnpd / testgetroute.c
blobbd8132420917ec20c1f41d7ee494347b9b7db78c
1 /* $Id: testgetroute.c,v 1.2 2012/06/23 23:32:32 nanard Exp $ */
2 /* MiniUPnP project
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2012 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
8 #include <stdio.h>
9 #include <string.h>
10 #include <syslog.h>
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
16 #include "getroute.h"
17 #include "upnputils.h"
19 #ifndef LOG_PERROR
20 /* solaris does not define LOG_PERROR */
21 #define LOG_PERROR 0
22 #endif
24 int
25 main(int argc, char ** argv)
27 struct sockaddr_in dst4;
28 struct sockaddr_in6 dst6;
29 struct sockaddr * dst;
30 void * src;
31 size_t src_len;
32 int r;
34 memset(&dst4, 0, sizeof(dst4));
35 memset(&dst6, 0, sizeof(dst6));
36 dst = NULL;
37 if(argc < 2) {
38 fprintf(stderr, "usage: %s <ip address>\n", argv[0]);
39 fprintf(stderr, "both v4 and v6 IP addresses are supported.\n");
40 return 1;
42 openlog("testgetroute", LOG_CONS|LOG_PERROR, LOG_USER);
43 r = inet_pton (AF_INET, argv[1], &dst4.sin_addr);
44 if(r < 0) {
45 syslog(LOG_ERR, "inet_pton(AF_INET, %s) : %m", argv[1]);
46 return 2;
48 if (r == 0) {
49 r = inet_pton (AF_INET6, argv[1], &dst6.sin6_addr);
50 if(r < 0) {
51 syslog(LOG_ERR, "inet_pton(AF_INET6, %s) : %m", argv[1]);
52 return 2;
54 if(r > 0) {
55 dst6.sin6_family = AF_INET6;
56 dst = (struct sockaddr *)&dst6;
57 src = &dst6.sin6_addr;
58 src_len = sizeof(dst6.sin6_addr);
60 } else {
61 dst4.sin_family = AF_INET;
62 dst = (struct sockaddr *)&dst4;
63 src = &dst4.sin_addr;
64 src_len = sizeof(dst4.sin_addr);
67 if (dst) {
68 r = get_src_for_route_to (dst, src, &src_len);
69 syslog(LOG_DEBUG, "get_src_for_route_to() returned %d", r);
70 if(r >= 0) {
71 char src_str[128];
72 sockaddr_to_string(dst, src_str, sizeof(src_str));
73 syslog(LOG_DEBUG, "src=%s", src_str);
76 return 0;