MPS
MPS
MPS
int err;
if ((err = getaddrinfo(NULL, port, &hints, &ai))) {
freeaddrinfo(ai);
fprintf(stderr, "%s\n", gai_strerror(err));
return 1; // Could not determine address
}
// Turn our client address into a hostname and print out both
// the address and hostname as well as the port number
char hostname[NI_MAXHOST];
int error = getnameinfo((struct sockaddr*)&fromAddr, fromAddrSize,
hostname, NI_MAXHOST, NULL, 0, 0);
if (error) {
fprintf(stderr, "Error getting hostname: %s\n",
gai_strerror(error));
} else {
printf("Accepted connection from %s (%s), port %d\n",
inet_ntoa(fromAddr.sin_addr), hostname,
ntohs(fromAddr.sin_port));
}
return 0;
}