/*
*******************************************************************************
*
*
client.c --
*
Routine to send datagram packets to a server
*
default port is 2000 and default server is spock
*
*******************************************************************************
*/
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#define
HOST
"spock.ee.iastate.edu"
#define PORT
2000
struct
sockaddr_in sock_in, temp, from_addr;
int
from_len;
extern
int
errno;
main(argc, argv)
int
argc;
char
**argv;
{
struct
timeval
timeout;
register
int
n;
u_short
len;
char
*cp;
int
i, retry, resplen, done =
0
;
int
dsmask, flags, sockFD;
char
buf[
100
],answer[
4048
];
struct
hostent
*h_name;
struct
servent
*s_name;
char
hostname[
100
];
int
numTimeOuts
=
0
;
sockFD = -
1
;
opterr =
0
;
strcpy(hostname, HOST);
while
((i = getopt(argc, argv,
"pft"
)) != -
1
)
{
switch
(i)
{
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
break
;
case
'h'
:
// copy parm to host name
strcpy(hostname, argv[optind]);
break
;
This
preview
has intentionally blurred sections.
Sign up to view the full version.
case
'?'
:
default
:
done =
1
;
break
;
}
if
(done)
break
;
}
This is the end of the preview.
Sign up
to
access the rest of the document.
- Spring '08
- Staff
- Flag, rintf, bind error errno
-
Click to edit the document details