/*
*******************************************************************************
*
* tcp_client.c --
* program to send packets to a server (default port 2000)
*
*******************************************************************************
*/
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/socket.h>
#include <string.h>
#include <arpa/inet.h>
/*
* Initialize the socket address info struct.
*/
struct sockaddr_in sock_in, temp, from_addr;
int from_len;
#define PORT 2000
extern int errno;
main(argc, argv)
int argc;
char **argv;
{
struct timeval timeout;
register int n;
u_short len;
char *cp;
int i, j, retry, resplen, done = 0;
int dsmask, flags, sockFD, port_num = PORT;
char buf[100],answer[4048];
char hostname[100];
struct hostent *h_name;
struct servent *s_name;
int numTimeOuts = 0;
sockFD = -1;
strcpy(hostname, "spock.ee.iastate.edu");
opterr = 0;
printf("argc = %u\n", argc);
for (i=0 ; i<argc; i++)
printf("argv[%u] = %s\n", i, argv[i]);
while ((i = getopt(argc, argv, "hpft")) != -1)
{
printf("argument = %c\n", i);
switch (i)
{
case 'h':
strcpy(hostname, argv[optind]);
printf("Got hostname = %s\n", hostname);
break;
case 't':
// this is a test flag to show how the flags work
// this will print out the parms
printf("%s\n", argv[optind]);
break;
case 'p':
// add code for the p flag set
port_num = atoi(argv[optind]);
printf("Got portnum = %u\n", port_num);
break;
case 'f':
// add code for the f flag set
printf("Got to 'f' flag\n");
break;
case '?':
default:
printf("Got to DEFAULT case.\n");
done = 1;
break;
}
printf("done with switch\n");
if (done) printf("done\n");
if (done) break;
}
printf("out of switch, i=%i\n", i);
strcpy(buf,"hello there\n");
h_name = gethostbyname(hostname);
sock_in.sin_family = AF_INET;
.
.
.