1 /* $Id: testgetroute.c,v 1.2 2012/06/23 23:32:32 nanard Exp $ */
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 */
11 #include <sys/types.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
17 #include "upnputils.h"
20 /* solaris does not define LOG_PERROR */
25 main(int argc
, char ** argv
)
27 struct sockaddr_in dst4
;
28 struct sockaddr_in6 dst6
;
29 struct sockaddr
* dst
;
34 memset(&dst4
, 0, sizeof(dst4
));
35 memset(&dst6
, 0, sizeof(dst6
));
38 fprintf(stderr
, "usage: %s <ip address>\n", argv
[0]);
39 fprintf(stderr
, "both v4 and v6 IP addresses are supported.\n");
42 openlog("testgetroute", LOG_CONS
|LOG_PERROR
, LOG_USER
);
43 r
= inet_pton (AF_INET
, argv
[1], &dst4
.sin_addr
);
45 syslog(LOG_ERR
, "inet_pton(AF_INET, %s) : %m", argv
[1]);
49 r
= inet_pton (AF_INET6
, argv
[1], &dst6
.sin6_addr
);
51 syslog(LOG_ERR
, "inet_pton(AF_INET6, %s) : %m", argv
[1]);
55 dst6
.sin6_family
= AF_INET6
;
56 dst
= (struct sockaddr
*)&dst6
;
57 src
= &dst6
.sin6_addr
;
58 src_len
= sizeof(dst6
.sin6_addr
);
61 dst4
.sin_family
= AF_INET
;
62 dst
= (struct sockaddr
*)&dst4
;
64 src_len
= sizeof(dst4
.sin_addr
);
68 r
= get_src_for_route_to (dst
, src
, &src_len
);
69 syslog(LOG_DEBUG
, "get_src_for_route_to() returned %d", r
);
72 sockaddr_to_string(dst
, src_str
, sizeof(src_str
));
73 syslog(LOG_DEBUG
, "src=%s", src_str
);