Created
May 2, 2013 17:14
-
-
Save kimor79/5503747 to your computer and use it in GitHub Desktop.
Testing apr methods and IP. Compiled on FreeBSD 9.0-RELEASE with: cc -I /usr/local/include/ -I /usr/local/include/apr-1/ -L /usr/local/lib -lapr-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdio.h" | |
#include "stdlib.h" | |
#include "apr.h" | |
#include "apr_network_io.h" | |
#include "apr_strings.h" | |
#include "apr_tables.h" | |
int main(void) { | |
apr_file_t *err; | |
char *ipstr; | |
char hostname[APRMAXHOSTLEN + 1]; | |
apr_file_t *out; | |
apr_pool_t *p; | |
apr_status_t rv; | |
apr_sockaddr_t *sockaddr; | |
apr_initialize(); | |
// atexit(apr_terminate()); | |
apr_pool_create(&p, NULL); | |
apr_file_open_stderr(&err, p); | |
apr_file_open_stdout(&out, p); | |
if((rv = apr_gethostname(hostname, APRMAXHOSTLEN, p)) != APR_SUCCESS) { | |
apr_file_printf(err, "Unable to determine hostname"); | |
apr_pool_destroy(p); | |
return EXIT_FAILURE; | |
} | |
if((rv = apr_sockaddr_info_get(&sockaddr, hostname, APR_UNSPEC, 0, | |
APR_IPV4_ADDR_OK, p)) != APR_SUCCESS) { | |
apr_file_printf(err, "Unable to determine IP"); | |
apr_pool_destroy(p); | |
return EXIT_FAILURE; | |
} | |
apr_sockaddr_ip_get(&ipstr, sockaddr); | |
apr_file_printf(out, "IP: %s\n", ipstr); | |
apr_pool_destroy(p); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment