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

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

Advertisement

}
default:
exit(0);
}
}
/*
*
*
* This is an example program that demonstrates the use of
* datagram sockets as an BSD Sockets mechanism. This contains
* the client, and is intended to operate in conjunction with the
* server program found in serv.udp. Together, these two programs
* demonstrate many of the features of sockets, as well as good
* conventions for using these features.
*
* This program requests a service called "example".
* it to function, an entry for it needs to exist in the
* /etc/services file.
* any port number that is likely to be unused, such as 22375,
* for example.
The host on which the server will be runnin
* must also have the same entry (same port number) in its
* /etc/services file.
*
* The "example" service is an example of a simple name server
* application.
The host that is to provide this service is
* required to be in the /etc/hosts file. Also, the host providing
* this service presumably knows the internet addresses of many
* hosts which the local host does not.
* will request the internet address of a target host by name from
* the serving host.
* internet address as a response, and will return an address of
* all ones if it does not recognize the host name.
*
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <signal.h>
#include <netdb.h>
extern int errno;
int s;
struct hostent *hp;
struct servent *sp;
struct sockaddr_in myaddr_in;
struct sockaddr_in servaddr_in;/* for server socket addres */
Chapter 4
sendto (s, &reqaddr, sizeof(struct in_addr),
0, &clientaddr_in, addrlen);
/* Parent process comes here. */
C L I E N T . U D P
The port address for this service can be
The serving host will return the requested
/* socket descriptor */
/* pointer to info for nameserver host */
/* pointer to service information */
/* for local socket address */
Using Internet Datagram Sockets
Example Using Datagram Sockets
In order for
Therefore, this program
105

Advertisement

Table of Contents
loading

Table of Contents