miniupnp/miniupnpd/testgetifaddr.c

34 lines
957 B
C
Raw Normal View History

/* $Id: testgetifaddr.c,v 1.6 2013/03/23 10:46:55 nanard Exp $ */
2011-09-28 19:13:20 +00:00
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2013 Thomas Bernard
2011-09-28 19:13:20 +00:00
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#include <stdio.h>
#include <syslog.h>
#include <netinet/in.h>
2011-09-28 19:13:20 +00:00
#include "getifaddr.h"
2012-05-24 17:37:42 +00:00
#if defined(__sun)
/* solaris 10 does not define LOG_PERROR */
#define LOG_PERROR 0
#endif
2011-09-28 19:13:20 +00:00
int main(int argc, char * * argv) {
char str_addr[64];
struct in_addr addr;
struct in_addr mask;
2011-09-28 19:13:20 +00:00
if(argc < 2) {
fprintf(stderr, "Usage:\t%s interface_name\n", argv[0]);
return 1;
}
2012-05-24 17:37:42 +00:00
2011-09-28 19:13:20 +00:00
openlog("testgetifaddr", LOG_CONS|LOG_PERROR, LOG_USER);
if(getifaddr(argv[1], str_addr, sizeof(str_addr), &addr, &mask) < 0) {
2011-09-28 19:13:20 +00:00
fprintf(stderr, "Cannot get address for interface %s.\n", argv[1]);
return 1;
}
printf("Interface %s has IP address %s.\n", argv[1], str_addr);
2011-09-28 19:13:20 +00:00
return 0;
}