HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual page 106

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Using Internet Datagram Sockets
Example Using Datagram Sockets
struct in_addr reqaddr;
#define ADDRNOTFOUND 0xffffffff /* value returned for unknown host */
#define RETRIES 5 /* # of times to retry before giving up */
/*
*
*
*
This routine is the signal handler for the alarm signal.
*
It simply re-installs itself as the handler and returns.
*/
handler()
{
signal(SIGALRM, handler);
}
/*
*
*
* This routine is the client which requests service from
* the remote "example server".
* remote nameserver requesting the internet address corresponding
* to a given hostname. The server will look up the name, and
* return its internet address. The returned address will be
* written to stdout.
*
* The name of the system to which the requests will be sent is
* given as the first parameter to the command.
* parameter should be the name of the target host for which the
* internet address is sought.
*/
main(argc, argv)
int argc;
char *argv[];
{
int i;
int retry = RETRIES;
char *inet_ntoa();
if (argc != 3) {
fprintf(stderr, "Usage:
exit(1);
}
/* clear out address structures */
memset ((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
memset ((char *)&servaddr_in, 0, sizeof(struct sockaddr_in));
/* Set up the server address. */
servaddr_in.sin_family = AF_INET;
/* Get the host info for the server's hostname that the
* user passed in.
*/
hp = gethostbyname (argv[1]);
if (hp == NULL) {
fprintf(stderr, "%s: %s not found in /etc/hosts\n",
106
/* for returned internet address */
H A N D L E R
M A I N
It will send a message to the
%s <nameserver> <target>\n",
argv[0]);
argv[0], argv[1]);
The second
/* holds the retry count */
Chapter 4

Advertisement

Table of Contents
loading

Table of Contents