TCP/IP Programming Manual
 /* Convert the server'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(serveraddr.sin_addr);
 printf("Response received from");
 if (hp != NULL)
 printf(" %s", hp->h_name);
 if (ap != NULL)
 printf(" (%s)", ap);
 printf(":\n %s\n", databuf);
 FILE_CLOSE_((short)s);
}
AF_INET Server Stub Routine
The next example shows a sample server program that you can build, compile, and run on your
system. The program receives requests from and sends responses to client programs on other
systems.
/*
 * AF_INET Server Stub Routine
 * *****************************************************************
 * * *
 * * Copyright (c) Hewlett-Packard Company, 2003 *
 * * *
 * * The software contained on this media is proprietary to *
 * * and embodies the confidential technology of Hewlett *
 * * Packard Corporation. Possession, use, duplication or *
 * * dissemination of the software and media is authorized only *
 * * pursuant to a valid written license from Hewlett Packard *
 * * Corporation. *
 * * *
 * * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure *
 * * by the U.S. Government is subject to restrictions as set *
 * * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, *
 * * or in FAR 52.227-19, as applicable. *
 * * *
 * *****************************************************************
 */
#include <systype.h>
#include <socket.h>
#include <errno.h>
#include <in.h>
#include <netdb.h>
#include <string.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <inet.h>
#include <cextdecs(FILE_CLOSE_)>
#define SERVER_PORT 7639
#define CLIENT_PORT 7739
#define MAXBUFSIZE 4096
int main (
 int argc,
 char **argv )
{
 int s;
 char databuf[MAXBUFSIZE];
210 Sample Programs










