Annotation of embedaddon/miniupnpd/testgetroute.c, revision 1.1
1.1 ! misho 1: /* $Id: testgetroute.c,v 1.5 2013/02/06 12:07:36 nanard Exp $ */
! 2: /* MiniUPnP project
! 3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
! 4: * (c) 2006-2013 Thomas Bernard
! 5: * This software is subject to the conditions detailed
! 6: * in the LICENCE file provided within the distribution */
! 7:
! 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>
! 15:
! 16: #include "getroute.h"
! 17: #include "upnputils.h"
! 18: #include "upnpglobalvars.h"
! 19:
! 20: #ifndef LOG_PERROR
! 21: /* solaris does not define LOG_PERROR */
! 22: #define LOG_PERROR 0
! 23: #endif
! 24:
! 25: struct lan_addr_list lan_addrs;
! 26:
! 27: int
! 28: main(int argc, char ** argv)
! 29: {
! 30: struct sockaddr_in dst4;
! 31: struct sockaddr_in6 dst6;
! 32: struct sockaddr * dst;
! 33: void * src;
! 34: size_t src_len;
! 35: int r;
! 36: int index = -1;
! 37:
! 38: memset(&dst4, 0, sizeof(dst4));
! 39: memset(&dst6, 0, sizeof(dst6));
! 40: dst = NULL;
! 41: if(argc < 2) {
! 42: fprintf(stderr, "usage: %s <ip address>\n", argv[0]);
! 43: fprintf(stderr, "both v4 and v6 IP addresses are supported.\n");
! 44: return 1;
! 45: }
! 46: openlog("testgetroute", LOG_CONS|LOG_PERROR, LOG_USER);
! 47: r = inet_pton (AF_INET, argv[1], &dst4.sin_addr);
! 48: if(r < 0) {
! 49: syslog(LOG_ERR, "inet_pton(AF_INET, %s) : %m", argv[1]);
! 50: closelog();
! 51: return 2;
! 52: }
! 53: if (r == 0) {
! 54: r = inet_pton (AF_INET6, argv[1], &dst6.sin6_addr);
! 55: if(r < 0) {
! 56: syslog(LOG_ERR, "inet_pton(AF_INET6, %s) : %m", argv[1]);
! 57: closelog();
! 58: return 2;
! 59: } else if(r > 0) {
! 60: dst6.sin6_family = AF_INET6;
! 61: dst = (struct sockaddr *)&dst6;
! 62: src = &dst6.sin6_addr;
! 63: src_len = sizeof(dst6.sin6_addr);
! 64: } else {
! 65: /* r == 0 */
! 66: syslog(LOG_ERR, "%s is not a correct IPv4 or IPv6 address", argv[1]);
! 67: closelog();
! 68: return 1;
! 69: }
! 70: } else {
! 71: dst4.sin_family = AF_INET;
! 72: dst = (struct sockaddr *)&dst4;
! 73: src = &dst4.sin_addr;
! 74: src_len = sizeof(dst4.sin_addr);
! 75: }
! 76:
! 77: if (dst) {
! 78: syslog(LOG_DEBUG, "calling get_src_for_route_to(%p, %p, %p(%u), %p)",
! 79: dst, src, &src_len, (unsigned)src_len, &index);
! 80: r = get_src_for_route_to (dst, src, &src_len, &index);
! 81: syslog(LOG_DEBUG, "get_src_for_route_to() returned %d", r);
! 82: if(r >= 0) {
! 83: char src_str[128];
! 84: sockaddr_to_string(dst, src_str, sizeof(src_str));
! 85: syslog(LOG_DEBUG, "src=%s", src_str);
! 86: syslog(LOG_DEBUG, "index=%d", index);
! 87: }
! 88: }
! 89: closelog();
! 90: return 0;
! 91: }
! 92:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>