minor modifications to linux/getroute.c and testgetroute.c

This commit is contained in:
Thomas Bernard 2012-10-23 14:35:50 +02:00
parent 9473a32ab9
commit f365c3a9ea
3 changed files with 20 additions and 6 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.318 2012/10/04 22:11:55 nanard Exp $
$Id: Changelog.txt,v 1.319 2012/10/23 12:24:31 nanard Exp $
2012/10/23:
minor modifications to linux/getroute.c and testgetroute.c
2012/10/04:
updated DEFAULTCONNECTIONSERVICE_MAGICALVALUE for IGDv2

View File

@ -1,4 +1,4 @@
/* $Id: getroute.c,v 1.2 2012/06/23 23:34:42 nanard Exp $ */
/* $Id: getroute.c,v 1.3 2012/10/23 12:24:33 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -76,6 +76,10 @@ get_src_for_route_to(const struct sockaddr * dst,
}
fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (fd < 0) {
syslog(LOG_ERR, "socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE) : %m");
return -1;
}
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
@ -87,7 +91,7 @@ get_src_for_route_to(const struct sockaddr * dst,
if (status < 0) {
syslog(LOG_ERR, "sendmsg(rtnetlink) : %m");
return -1;
goto error;
}
memset(&req, 0, sizeof(req));

View File

@ -1,4 +1,4 @@
/* $Id: testgetroute.c,v 1.2 2012/06/23 23:32:32 nanard Exp $ */
/* $Id: testgetroute.c,v 1.3 2012/10/23 12:24:33 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2012 Thomas Bernard
@ -43,19 +43,25 @@ main(int argc, char ** argv)
r = inet_pton (AF_INET, argv[1], &dst4.sin_addr);
if(r < 0) {
syslog(LOG_ERR, "inet_pton(AF_INET, %s) : %m", argv[1]);
closelog();
return 2;
}
if (r == 0) {
r = inet_pton (AF_INET6, argv[1], &dst6.sin6_addr);
if(r < 0) {
syslog(LOG_ERR, "inet_pton(AF_INET6, %s) : %m", argv[1]);
closelog();
return 2;
}
if(r > 0) {
} else if(r > 0) {
dst6.sin6_family = AF_INET6;
dst = (struct sockaddr *)&dst6;
src = &dst6.sin6_addr;
src_len = sizeof(dst6.sin6_addr);
} else {
/* r == 0 */
syslog(LOG_ERR, "%s is not a correct IPv4 or IPv6 address", argv[1]);
closelog();
return 1;
}
} else {
dst4.sin_family = AF_INET;
@ -73,6 +79,7 @@ main(int argc, char ** argv)
syslog(LOG_DEBUG, "src=%s", src_str);
}
}
closelog();
return 0;
}