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

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

Advertisement

Programming Hints
Adding a Server Process to the Internet Daemon
* BUFFERSIZE - 1 bytes are read so that
* room is left at the end of the buffer
* for a null character.
*/
cc = recvfrom(0, buffer, BUFFERSIZE - 1, 0 &clientaddr_in,
if ( cc == -1) exit(1);
/* Make sure the message received in
* null terminated.
*/
buffer[cc]='\0';
/* Treat the message as a string containing
* a hostname.
* in /etc/hosts.
*/
hp = gethostbyname (buffer);
if (hp == NULL) {
reqaddr.s_addr = ADDRNOTFOUND;
} else {
reqaddr.s_addr =
}
/* send the response back to the requesting client.
* address is sent in network byte order.
* all errors are ignored.
* will retry if it does not receive
* the response.
*/
sendto (0, &reqaddr, sizeof(struct in_addr), 0,
exit(0);
}
172
Search for the name
/* Name was not found.
* special value signifying the error.
/*
/* Copy address of host into the
* return buffer.
/*
((struct in_addr *)(hp->h_addr))->s_addr;
The client
&clientaddr_in, addrlen);
&addrlen);
Return a
The
Note that
Chapter 8

Advertisement

Table of Contents
loading

Table of Contents