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

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

Advertisement

exit (0);
}
/*
*
*
*
This is a variation of the example program called serv.udp.
*
This one performs the same function, except that it is
*
designed to be called from /etc/inetd. This version does
*
not contain a daemon loop, and does not wait for requests
*
to arrive on a socket. /etc/inetd does these functions. The
*
server simply assumes the socket to receive the message
*
from and send the response to is file descriptor 0 when
*
the program is started.
*
request is already ready to be received from the socket.
*
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>
#include <netdb.h>
#define BUFFERSIZE
int cc;
char buffer[BUFFERSIZE];
struct hostent *hp;
struct sockaddr_in clientaddr_in;/* for client's socket address */
struct in_addr reqaddr;
#define ADDRNOTFOUND
/*
*
*
*
This routine receives the request and returns an answer.
*
Each request consists of a host name for which the
*
requester desires to know the internet address. The
*
server will look up the name in its /etc/hosts file,
*
and return the internet address to the client. An
*
a internet address value of all ones will be returned
*
if the host name is not found.
*
*/
main()
{
int
addrlen;
/* clear out address structure */
memset ((char *)&clientaddr_in, 0, sizeof(struct sockaddr_in));
/* Note that addrlen is passed as a pointer
* so that the recvfrom call can return the
* size of the returned address.
*/
addrlen = sizeof(struct sockaddr_in);
/* This call will
* return the address of the client,
* and a buffer containing its request.
Chapter 8
Adding a Server Process to the Internet Daemon
S E R V E R . U D P
It also assumes that the client's
1024
/* max size of packets to be received */
/* contains the number of bytes read */
/* buffer for packets to be read into */
/* pointer to info for requested host */
/* for requested host's address */
0xffffffff
/* return address for unfound
host */
M A I N
Programming Hints
171

Advertisement

Table of Contents
loading

Table of Contents