Moderator: rgerhards

#include <stdio.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
void main()
{
int iErr;
struct addrinfo *res;
struct addrinfo hints;
printf("trying with char service\n");
iErr = getaddrinfo("localhost", "syslog", NULL, &res);
if(iErr == 0) {
printf("success\n");
} else {
printf("could not get addrinfo for hostname (error %d): %s\n",
iErr, gai_strerror(iErr));
}
printf("trying with numerical service, no hints\n");
iErr = getaddrinfo("localhost", "514", NULL, &res);
if(iErr == 0) {
printf("success\n");
} else {
printf("could not get addrinfo for hostname (error %d): %s\n",
iErr, gai_strerror(iErr));
}
printf("trying with numerical service, and AI_NUMERICSERV hint\n");
memset(&hints, 0, sizeof(hints));
/* port must be numeric, because config file syntax requires this */
hints.ai_flags = AI_NUMERICSERV;
iErr = getaddrinfo("localhost", "514", &hints, &res);
if(iErr == 0) {
printf("success\n");
} else {
printf("could not get addrinfo for hostname (error %d): %s\n",
iErr, gai_strerror(iErr));
}
}
trying with char service
success
trying with numerical service, no hints
could not get addrinfo for hostname (error 9): servname not supported for ai_socktype
trying with numerical service, and AI_NUMERICSERV hint
could not get addrinfo for hostname (error 9): servname not supported for ai_socktype







Users browsing this forum: Yahoo [Bot] and 0 guests