1 /* $Id: testgetroute.c,v 1.6 2015/11/16 19:20:21 nanard Exp $ */
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2015 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
17 #include "upnputils.h"
18 #include "upnpglobalvars.h"
21 /* solaris does not define LOG_PERROR */
25 struct lan_addr_list lan_addrs
;
28 main(int argc
, char ** argv
)
30 struct sockaddr_in dst4
;
31 struct sockaddr_in6 dst6
;
32 struct sockaddr
* dst
;
38 memset(&dst4
, 0, sizeof(dst4
));
39 memset(&dst6
, 0, sizeof(dst6
));
42 fprintf(stderr
, "usage: %s <ip address>\n", argv
[0]);
43 fprintf(stderr
, "both v4 and v6 IP addresses are supported.\n");
46 openlog("testgetroute", LOG_CONS
|LOG_PERROR
, LOG_USER
);
47 r
= inet_pton (AF_INET
, argv
[1], &dst4
.sin_addr
);
49 syslog(LOG_ERR
, "inet_pton(AF_INET, %s) : %m", argv
[1]);
54 r
= inet_pton (AF_INET6
, argv
[1], &dst6
.sin6_addr
);
56 syslog(LOG_ERR
, "inet_pton(AF_INET6, %s) : %m", argv
[1]);
60 dst6
.sin6_family
= AF_INET6
;
61 dst
= (struct sockaddr
*)&dst6
;
62 src
= &dst6
.sin6_addr
;
63 src_len
= sizeof(dst6
.sin6_addr
);
66 syslog(LOG_ERR
, "%s is not a correct IPv4 or IPv6 address", argv
[1]);
71 dst4
.sin_family
= AF_INET
;
72 dst
= (struct sockaddr
*)&dst4
;
74 src_len
= sizeof(dst4
.sin_addr
);
78 syslog(LOG_DEBUG
, "calling get_src_for_route_to(%p, NULL, NULL, %p)",
80 r
= get_src_for_route_to (dst
, NULL
, NULL
, &index
);
81 syslog(LOG_DEBUG
, "get_src_for_route_to() returned %d", r
);
83 syslog(LOG_DEBUG
, "index=%d", index
);
85 syslog(LOG_DEBUG
, "calling get_src_for_route_to(%p, %p, %p(%u), %p)",
86 dst
, src
, &src_len
, (unsigned)src_len
, &index
);
87 r
= get_src_for_route_to (dst
, src
, &src_len
, &index
);
88 syslog(LOG_DEBUG
, "get_src_for_route_to() returned %d", r
);
91 sockaddr_to_string(dst
, src_str
, sizeof(src_str
));
92 syslog(LOG_DEBUG
, "src=%s", src_str
);
93 syslog(LOG_DEBUG
, "index=%d", index
);