TCP/IP Programming Manual
short IOCheck ( long TOVal ) {
/* use a single AWAITIOX() check for all I/O in this pgm
return value is FE;
sets global tagBack & socket that completed;
don't care about buf addr but do want count */
short error;
_cc_status CC;
completedSocket = -1;
CC = AWAITIOX( &completedSocket,,&dcount,&tagBack,TOVal );
/* ignoring possible _status_gt condition */
if( _status_lt( CC ) ) {
FILE_GETINFO_( completedSocket,&error );
return error;
}
else return 0;
}
int main (int argc,char **argv ) {
int s;
char databuf[MAXBUFSIZE];
int new_s;
u_short port;
struct hostent *hp;
const char *ap;
short fe;
long tag = 44; /* for nowait I/O ID */
long tag2 = 45; /* " " */
long acceptWait = -1;/* how long to wait for connections */
long timeout = 500; /* read t/o of 5 secs */
/* Declares sockaddr_in structures. The use of this type of
structure implies communication using the IPv4 protocol. */
struct sockaddr_in serveraddr;
struct sockaddr_in clientaddr;
int clientaddrlen;
char response[MAXBUFSIZE] = " This is the server's response";
/* Create an AF_INET socket.
FLAGS argument does not indicate open nowait (octal 200) ,
but does indicate 2 outstanding I/Os max.
SETMODE 30 included in the call */
if ((s = socket_nw(AF_INET, SOCK_STREAM, 0, 2, 0)) < 0) {
perror("socket");
exit (0);
}
/* Clear the server address and set up server variables. The socket
address is a 32-bit Internet address and a 16-bit port number on
which it is listening.*/
bzero((char *) &serveraddr, sizeof(struct sockaddr_in));
serveraddr.sin_family = AF_INET;
/* Set the server address to the IPv4 wild card address
INADDR_ANY. This signifies any attached network interface on
the system. */
serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
serveraddr.sin_port = htons(SERVER_PORT);
/* Bind the server's address to the AF_INET socket. */
if (bind_nw(s, (struct sockaddr *)&serveraddr, sizeof(serveraddr), tag)<0){
perror("bind");
exit(2);
}
if( fe = IOCheck( -1 ) ) {
printf( "AWAITIO error %d from bind_nw\n",fe );
exit(2);
}
Programs Using AF_INET Sockets 213










