TCP/IP Programming Manual

hp = gethostbyaddr((char *)&clientaddr.sin_addr.s_addr,
sizeof(clientaddr.sin_addr.s_addr), AF_INET);
/* Convert the client's 32-bit IPv4 address to a dot-formatted
Internet address text string. A call to inet_ntoa expects an
IPv4 address as input. */
ap = inet_ntoa(clientaddr.sin_addr);
port = ntohs(clientaddr.sin_port);
printf("Request received from");
if (hp != NULL) printf(" %s", hp->h_name);
if (ap != NULL) printf(" (%s)", ap);
printf(" port %d\n\"%s\"\n", port, databuf);
/* Send a response to the client. */
if (send_nw2(new_s, response, (int)strlen(response), 0, tag2) < 0) {
perror("send_nw2");
FILE_CLOSE_((short)new_s);
continue;
}
if( fe = IOCheck( -1 ) ) {
FILE_CLOSE_((short)new_s);
continue;
}
} /* while */
}/*
C TCP Client Program
The following client program on one NonStop system sends data from its memory to the server on
another NonStop system, where the two hosts are connected over a network or an internetwork:
To compile the program in native mode, run this command:
> nmc/in <input file name>,out <list file name>/<object file
name>;symbols,runnable,extensions,ssv0 "subvolume name",ssv1
"$system.system",ssv2
"$system.zsysdefs",ssv3 "$system.ztcpip"
NOTE: Before running the client program, create a send file with object code 000.
To run the client program:
> run <objectfile name> <send file name> <host port #> <process name>
Sample Program
#pragma nolist
#include <cextdecs(FILE_CLOSE_,read)>
#include <unistd.h>
#include <param.h>
#include <socket.h>
#include <in.h>
#include <netdb.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <memory.h>
#include <errno.h>
#define INET_ERROR 4294967295 /* inet_addr returns 0xffffffffl upon error */
#pragma list
/*
* Usage: CLIENT send_file host port# proc_name nbufs bufsize
*/
main (argc, argv)
int argc;
char *argv[];
{
Programs Using AF_INET Sockets 215