BSD Sockets Interface Programmer's Guide

108 Chapter 4
Using Internet Datagram Sockets
Example Using Datagram Sockets
if (recv (s, &reqaddr, sizeof(struct in_addr), 0) == -1) {
if (errno == EINTR) {
/* Alarm went off & aborted the receive.
* Need to retry the request if we have
* not already exceeded the retry limit.
*/
if (—retry) {
goto again;
} else {
printf(”Unable to get response from”);
printf(” %s after %d attempts.\n”,
argv[1], RETRIES);
exit(1);
}
} else {
perror(argv[0]);
fprintf(stderr, ”%s: unable to receive response\n”,
argv[0]);
exit(1);
}
}
alarm(0);
/* Print out response. */
if (reqaddr.s_addr == ADDRNOTFOUND) {
printf(”Host %s unknown by nameserver %s.\n”, argv[2],
argv[1]);
exit(1);
} else {
printf(”Address for %s is %s.\n”, argv[2],
inet_ntoa(reqaddr));
}
}