#pragma runopts(execops) /*** IBMCOPYR ********************************************************/ /* */ /* Copyright: */ /* Licensed Materials - Property of IBM */ /* This product contains "Restricted Materials of IBM" */ /* 5735-FAL (C) Copyright IBM Corp. 1991, 1997 */ /* All rights reserved. */ /* US Government Users Restricted Rights - */ /* Use, duplication or disclosure restricted by GSA ADP Schedule */ /* Contract with IBM Corp. */ /* See IBM Copyright Instructions. */ /* */ /* Status: */ /* Version 2, Release 4, Level 0 */ /* */ /*** IBMCOPYR ********************************************************/ /* */ /* To build POSIX version using OE socket library */ /* c89 //tcpc.c -o //tcpc -l //POSXSOCK -l //VMMTLIB */ /* */ /* To build TCP/IP socket library version */ /* global txtlib commtxt sceelked */ /* global loadlib sceerun */ /* cc tcpc */ /*********************************************************************/ static char ibmcopyr[] = "TCPC - Licensed Materials - Property of IBM. " "This module is \"Restricted Materials of IBM\" " "5735-FAL (C) Copyright IBM Corp. 1991. " "See IBM Copyright Instructions."; /* * Include Files. */ #ifdef __OPEN_VM #define _OE_SOCKETS #include #else #include #include #endif #include #include #include #include #include #include #ifdef _OE_SOCKETS #include #endif /* * Client Main. */ main(argc, argv) int argc; char **argv; { int ssss[2500]; unsigned short port; /* port client will connect to */ char buf[12]; /* data buffer for sending & receiving */ struct hostent *hostnm; /* server host name information */ struct sockaddr_in server; /* server address */ int s; /* client socket */ ssss[2500] = 0; /* * Check Arguments Passed. Should be hostname and port. */ if (argc != 3) { fprintf(stderr, "Usage: %s hostname port\n", argv[0]); exit(1); } /* * The host name is the first argument. Get the server address. */ printf("Host name = %s\n", argv[1]); hostnm = gethostbyname(argv[1]); if (hostnm == (struct hostent *) 0) { fprintf(stderr, "Gethostbyname failed\n"); exit(2); } /* * The port is the second argument. */ port = (unsigned short) atoi(argv[2]); /* * Put a message into the buffer. */ strcpy(buf, "the message"); /* * Put the server information into the server structure. * The port must be put into network byte order. */ server.sin_family = AF_INET; server.sin_port = htons(port); server.sin_addr.s_addr = *((unsigned long *)hostnm->h_addr); /* * Get a stream socket. */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { tcperror("Socket()"); exit(errno); /* Sample showing use of errno */ } /* * Connect to the server. */ if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) { tcperror("Connect()"); exit(4); } if (send(s, buf, sizeof(buf), 0) < 0) { tcperror("Send()"); exit(5); } /* * The server sends back the same message. Receive it into the * buffer. */ if (recv(s, buf, sizeof(buf), 0) < 0) { tcperror("Recv()"); exit(6); } /* * Close the socket. */ close(s); printf("Client Ended Successfully\n"); exit(0); }