Пример #1
0
int main(int argc, char **argv)
{
    int sockfd;
    struct sockaddr_in servaddr;

    //tcpcli <ipaddress> <data>
    if(argc!=3)
        return -1;

    sockfd=socket(AF_INET,SOCK_STREAM,0);
    if(sockfd==-1)
    {
       printf("socket established error: %s\n",(char*)strerror(errno)); 
    }

    bzero(&servaddr,sizeof(servaddr));
    servaddr.sin_family=AF_INET;
    servaddr.sin_port=htons(SERVER_PORT);
    inet_pton(AF_INET,argv[1],&servaddr.sin_addr);
    
    printf("client try to connect\n");
    int conRes=connect(sockfd,(struct sockaddr *)&servaddr,sizeof(servaddr));
    if(conRes==-1)
    {    
            perror("connect");
           printf("connect error: %s\n",strerror(errno));
    }

    str_cli(argv[2],sockfd);

    exit(0);
}
Пример #2
0
int main(int argc, char **argv)
{
	int sockfd;
	struct sockaddr_in servaddr;


	if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){
		perror("socket");
		exit(EXIT_FAILURE);
	}

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(CLI_PORT);
	if(inet_pton(AF_INET, argv[1], &servaddr.sin_addr) < 0){
		perror("inet_pton");
		exit(EXIT_FAILURE);
	}

	if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0){
		perror("connect");
		exit(EXIT_FAILURE);
	}

	str_cli(stdin, sockfd);

	exit(EXIT_SUCCESS);
}
Пример #3
0
int main (int argc, char **argv)
{
int sockfd;
struct sockaddr_in servaddr;
if (argc != 2)
{
perror ("usage: tcpcli <IPaddress>");
exit (0);
}
sockfd = socket (AF_INET, SOCK_STREAM, 0);
if ( sockfd < 0)
{
perror ("socket error");
exit (0);
}
bzero (&servaddr, sizeof (servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons (SERV_PORT);
inet_pton (AF_INET, argv[1], &servaddr.sin_addr);
if (connect (sockfd, (SA *) &servaddr, sizeof (servaddr)) < 0)
{
perror ("connect error");
exit (0);
}
str_cli (stdin, sockfd);
exit (0);
}
Пример #4
0
int main()
{
  int sockfd;
  char c, rc;
  struct sockaddr_in server;


  server.sin_family = AF_INET;
  server.sin_port = htons(55910);
  // convert and store the server's IP address
  server.sin_addr.s_addr = inet_addr(IPADDR);
  
  // set up the transport end point
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
      perror("socket call failed");
      exit(-1);
    }   // end if

  // connect the socket to the server's address
  if (connect(sockfd, (struct sockaddr *)&server, SIZE) == -1)
    {
      perror("connect call failed");
      exit(-1);
    }   // end if

  str_cli("Hello World!\n", sockfd);		/* do it all */

}  // end main
Пример #5
0
/* gcc tcpcli_select00.c strcli_select01.c error.c-o cli00 */
int main(int argc, char **argv)
{
    int                 n, sockfd;
    struct sockaddr_in  servaddr;

    if (argc != 2) {
        err_quit("usage: tcpcli <IPaddress>");
    }

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        err_sys("socket error");
    }
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(SERV_PORT);
    if ((n = inet_pton(AF_INET, argv[1], &servaddr.sin_addr)) < 0) {
        err_sys("inet_pton error for %s", argv[1]); /* error set */
    } else if (n == 0) {
        err_quit("inet_pton error for %s", argv[1]);
    }
    if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
        err_sys("connect error, errno = %d", errno);
    }
    str_cli(stdin, sockfd); /* do it all */
    exit(0);
}
Пример #6
0
int main(int argc,char** argv){
	if(argc!=2){
		printf("usage:a.out <IPaddress>\n");
		exit(0);
	}
	int sockfd;
	struct sockaddr_in servaddr;
	bzero(&servaddr,sizeof(servaddr));
	servaddr.sin_family=AF_INET;
	servaddr.sin_port=htons(5566);
	if(inet_pton(AF_INET,argv[1],&servaddr.sin_addr)<=0){
		printf("inet_pton error for %s",argv[1]);
		exit(0);
	}
	if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
		printf("socket error\n");
		exit(0);
	}
	if((connect(sockfd,(struct sockaddr*)&servaddr,sizeof(servaddr)))<0){
		printf("connect error\n");
		exit(0);
	}
	str_cli(stdin,sockfd);
	exit(0);
}
Пример #7
0
int main(int argc, char const *argv[])
{
	int sockfd, n;
	struct sockaddr_in servaddr;

	if(argc != 2)
		err("usage: tcpcli <ipaddress>");

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if(sockfd < 0)
		err("socket error");

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(SERV_PORT)

	n = inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
	if(n < 0 || n == 0)
		err("inet pton error");

	if(connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
		err("connect error");


	str_cli(stdin, sockfd);


	return 0;
}
Пример #8
0
int main(int argc, char** argv) {
    
    struct rlimit limit;

    getrlimit (RLIMIT_STACK, &limit);
    printf ("\nStack Limit = %ld and %ld max\n", limit.rlim_cur, limit.rlim_max);
  
	int			sockfd;
	struct sockaddr_in	servaddr;

	if (argc != 2)
		err_quit("usage: tcpcli <IPaddress>");

	sockfd = Socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons( SERV_PORT);
	Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

	Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));

	str_cli( stdin, sockfd);		/* do it all */

        close( sockfd);

	exit(0);
}
Пример #9
0
int main(int argc,char **argv)
{
	int sockfd;
	struct sockaddr_in servaddr;
	
	if(argc != 2)
	{
		printf("usage : a.out <IP address>\n");
		exit(1);
	}
	//create a socket for ipv4 
	sockfd = socket(AF_INET,SOCK_STREAM,0);
	//clear the servaddr to 0
	bzero(&servaddr,sizeof(servaddr));
	//set the AF_INET
	servaddr.sin_family = AF_INET;
	//set the server port
	servaddr.sin_port = htons(SERV_PORT);
	//convert the ip to number
	inet_pton(AF_INET,argv[1],&servaddr.sin_addr);
	//construct the connection
	connect(sockfd,(SA*)&servaddr,sizeof(servaddr));
	str_cli(stdin,sockfd);
	

	return 0;
}
Пример #10
0
int main() {
    int sockfd;
    struct sockaddr_in servaddr;

    if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
        printf("socket error.\n");
    }

    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(5001);
    if ( inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr) < 0) {
        printf("error!\n");
        exit(0);
    }

    if( connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0) {
        printf("connect error!\n");
        exit(0);
    }

    str_cli(stdin, sockfd);

    return 0;
}
Пример #11
0
int
main(int argc, char **argv)
{
	int					sockfd;
	struct sockaddr_un	servaddr;

	if((sockfd = socket(AF_LOCAL, SOCK_STREAM, 0)) < 0)
	{
		perror("socket");
		return -1;
	}

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sun_family = AF_LOCAL;
	strcpy(servaddr.sun_path, UNIXSTR_PATH);

	if(connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
	{
		perror("socket");
		return -1;
	}

	str_cli(stdin, sockfd);		/* do it all */
	exit(0);
}
Пример #12
0
int
main(int argc, char **argv)
{
	int					sockfd;
	struct linger		ling;
	struct sockaddr_in	servaddr;

	if (argc != 2)
		err_quit("usage: tcpcli <IPaddress>");

	sockfd = Socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(SERV_PORT);
	Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

	Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));

	str_cli(stdin, sockfd);		/* do it all */

	ling.l_onoff = 1;
	ling.l_linger = 0;
	Setsockopt(sockfd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));

	exit(0);
}
Пример #13
0
int main(int argc, char *argv[])
{
    int sockfd;
    struct sockaddr_in servaddr;

    if (argc != 2) 
        handle_err("usage: client <IP address>");

    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd == -1)
        handle_err("socket error");

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(SERV_PORT);
    if (inet_aton(argv[1], &servaddr.sin_addr) == 0)
        handle_err("error IP address");

    // if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
    //     handle_err("connecting error");
    // }

    // printf("Finish connecting\n");

    str_cli(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));

    close(sockfd);
    exit(EXIT_SUCCESS);
}
Пример #14
0
int
main(int argc, char **argv)
{
    int i, sockfd[5];
    struct sockaddr_in servaddr;

    if(argc != 2)
        err_quit("usage: tcpcli <IPaddress>");

    for(i = 0; i< 5; i++) {

        sockfd[i] = Socket(AF_INET, SOCK_STREAM, 0);

        bzero(&servaddr, sizeof(servaddr));
        servaddr.sin_family = AF_INET;
        servaddr.sin_port = htons(SERV_PORT);
        Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

        Connect(sockfd[i], (SA *)&servaddr, sizeof(servaddr));
    }

    str_cli(stdin, sockfd[0]);

    exit(0);
}
Пример #15
0
int main(int argc, char **argv)
{
  int sockfd;
  struct sockaddr_in servaddr;

  if (argc != 2)
  {
    printf("usage: tcpcli <IPaddress>");
    exit(1);
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
  {
    perror("sock create error");
    exit(1);
  }

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(5011);
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
   
  if (connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0)
  {
    perror("connect error");
    exit(1);
  }

  str_cli(stdin, sockfd);		/* do it all */

  exit(0);
}
Пример #16
0
int beginclient()
{
    pthread_mutex_destroy(&g_commandmutex);
    g_commandmutex=PTHREAD_MUTEX_INITIALIZER;
    struct sockaddr_in servaddr; /*declare server address*/

    if((sockfd=socket(AF_INET, SOCK_STREAM,0)) < 0)
        printf("socket error\n");

    /*create an Internet(AF_INET) stream(SOCK_STREAM) socket*/
    bzero(&servaddr,sizeof(servaddr)); /*reset address to zero*/
    servaddr.sin_family=AF_INET; /*IPv4*/
    servaddr.sin_port=htons(5566); /*Port: 12346*/

    if(inet_pton(AF_INET, "140.114.86.199", &servaddr.sin_addr) <= 0) //some pc in room 326
        printf("inet_ption error\n");

    if( connect(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0)
        printf("connect error\n");
    printf(">>>%d",sockfd);
    fflush(stdout);
    str_cli(stdin,sockfd); /* do it all */
    fflush(stdout);
    return 0;
}}
Пример #17
0
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in serv_addr;
  pname = argv[0];

  //
  // Fill in the structure "serv_addr" with the address of
  // the server that we want to connect with
  //

  memset((char *) &serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr(SERV_HOST_ADDR);
  serv_addr.sin_port = htons(SERV_TCP_PORT);

  //
  // Open a TCP socket (an Internet stream socket)
  //
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    err_dump("client : can't open stream socket");
  }

  //
  // Connect the server
  //
  if (connect(sockfd, (
      struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
    err_dump("client : can't connect to server");
  }

  str_cli(stdin, sockfd);
  close(sockfd);

  return EXIT_SUCCESS;
}
Пример #18
0
int main(int argc, char **argv)
{
    int sockfd;
    struct sockaddr_in servaddr;
    int ret = 0;

    if (argc != 2)
    {
        printf("usage: tcpcli <ipaddress>\n");
        return 0;
    }
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    assert(sockfd > 0);

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(SERV_PORT);
    inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

    ret = connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
    assert(ret == 0);

    str_cli(stdin, sockfd);

    return 0;
}
Пример #19
0
int main(int argc, char *argv[])
{
	int	i, sockfd[5];
	if (3 != argc) {
		handle_error("Usage: tcp_client <IPaddress> <port>");
	}

	int server_port = atoi(argv[2]);	
	socklen_t	clientlen;
	struct sockaddr_in server_addr;

    // Create 5 connect
	for(i = 0; i < 5; i++) {
		sockfd[i] = socket(AF_INET, SOCK_STREAM, 0);
		if (-1 == sockfd[i]) {
			handle_error("create socket failed\n");
		}

		memset(&server_addr, 0, sizeof(server_addr));
		server_addr.sin_family = AF_INET;
		server_addr.sin_port = htons(server_port);

		inet_pton(AF_INET, argv[1] ,&server_addr.sin_addr);
	
		if(-1 == connect(sockfd[i], (const struct sockaddr*)&server_addr, sizeof(server_addr))){
            close(sockfd[i]);
			handle_error("connect socket failed\n");
		}

	}

	str_cli(stdin, sockfd[0]);
	exit(0);
}
Пример #20
0
int main(int argc, char **argv)
{
    int sock_fd;
    struct sockaddr_in server_addr;

    if (argc != 3)
    {
        perror("usage: tcpcli <IPaddress> <IPport>");
        exit(0);
    }

    if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {  
        printf("create socket error: %s(errno: %d)\n", strerror(errno), errno);  
        exit(0);  
    }

    memset(&server_addr, 0, sizeof(server_addr));
    server_addr.sin_family = AF_INET;
    inet_aton(argv[1], &server_addr.sin_addr);
    server_addr.sin_port = htons(atoi(argv[2]));

    connect(sock_fd, (struct sockaddr*)&server_addr, sizeof(server_addr));

    str_cli(stdin, sock_fd);

    return 0;
}
Пример #21
0
int
main(int argc, char **argv)
{
	int					sockfd;
	void				sig_alrm(int);
	struct itimerval	val;
	struct sockaddr_in	servaddr;

	if (argc != 2)
		err_quit("usage: tcpcli <IPaddress>");

	sockfd = Socket(AF_INET, SOCK_STREAM, 0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(SERV_PORT);
	Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

		/* Set interval timer to go off before 3WHS completes */
	Signal(SIGALRM, sig_alrm);
	val.it_interval.tv_sec  = 0;
	val.it_interval.tv_usec = 0;
	val.it_value.tv_sec  = 0;
	val.it_value.tv_usec = 50000;	/* 50 ms */
	if (setitimer(ITIMER_REAL, &val, NULL) == -1)
		err_sys("setitimer error");

	Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));

	str_cli(stdin, sockfd);		/* do it all */

	exit(0);
}
int
main(int argc, char **argv)
{
	int		sockfd;
	struct sockaddr_in servaddr, cliaddr;
    int val;

	if (argc != 4)
		err_quit("usage: %s <LocalAddress> <IPaddress> <Port>", *argv);

	sockfd = Socket(AF_INET, SOCK_STREAM, 0);

    val = 1;
    if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0)
        err_sys("setsockopt SO_REUSEADDR error");

	bzero(&servaddr, sizeof servaddr);
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(atoi(argv[3]));
	Inet_pton(AF_INET, argv[2], &servaddr.sin_addr);

    /*
     * Bind local:1500
     */
    bzero(&cliaddr, sizeof cliaddr);
    cliaddr.sin_family = AF_INET;
    cliaddr.sin_port = htons(1500);
    if (!inet_aton(argv[1], &cliaddr.sin_addr))
        err_sys("inet_aton error");

    for (;;) {
        val = bind(sockfd, (SA *) &cliaddr, sizeof(cliaddr));
        if (val == 0)
            break;
        if (errno == EADDRINUSE)
            continue;
        err_sys("bind error");
    }

    /* Block here to test the race condition */
    printf("press any key to continue\n");
    fgetc(stdin);
    if (ferror(stdin))
        err_sys("fgetc error");
    printf("continue now\n");

retry:
	val = connect(sockfd, (SA *) & servaddr, sizeof servaddr);
    if (val < 0) {
        if (errno == EADDRINUSE)
            goto retry;
        err_sys("connect error");
    }

	str_cli(stdin, sockfd);	/* do it all */

	exit(0);
}
Пример #23
0
int
main(int argc, char **argv)
{
	int					c, sockfd, len = 0;
	u_char				*ptr = NULL;
	struct addrinfo		*ai;

	if (argc < 2)
		err_quit("usage: tcpcli01 [ -[gG] <hostname> ... ] <hostname>");

	opterr = 0;		/* don't want getopt() writing to stderr */
	while ( (c = getopt(argc, argv, "gG")) != -1) {
		switch (c) {
		case 'g':			/* loose source route */
			if (ptr)
				err_quit("can't use both -g and -G");
			ptr = inet_srcrt_init(0);
			break;

		case 'G':			/* strict source route */
			if (ptr)
				err_quit("can't use both -g and -G");
			ptr = inet_srcrt_init(1);
			break;

		case '?':
			err_quit("unrecognized option: %c", c);
		}
	}

	if (ptr)
		while (optind < argc-1)
			len = inet_srcrt_add(argv[optind++]);
	else
		if (optind < argc-1)
			err_quit("need -g or -G to specify route");

	if (optind != argc-1)
		err_quit("missing <hostname>");

	ai = Host_serv(argv[optind], SERV_PORT_STR, AF_INET, SOCK_STREAM);

	sockfd = Socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);

	if (ptr) {
		len = inet_srcrt_add(argv[optind]);	/* dest at end */
		Setsockopt(sockfd, IPPROTO_IP, IP_OPTIONS, ptr, len);
		free(ptr);
	}

	Connect(sockfd, ai->ai_addr, ai->ai_addrlen);

	str_cli(stdin, sockfd);		/* do it all */

	exit(0);
}
Пример #24
0
int main(int argc, char **argv)
{
	int sockfd, ret;
	struct sockaddr_in ser_addr;
	char ** pptr;
	struct hostent *sh;
	struct in_addr **addrs;

	if (argc != 2) {
		printf("parameters not match");
	}

	sh = gethostbyname(argv[1]);	                            //get host's information from the input argument
	if (sh == NULL) {
		printf("error when gethostby name");
		exit(0);
	}

	printf("canonical name: %s\n", sh->h_name);
	for (pptr=sh->h_aliases; *pptr != NULL; pptr++)
		printf("the aliases name is: %s\n", *pptr);
	switch(sh->h_addrtype)
	{
		case AF_INET:
			printf("AF_INET\n");
		break;
		default:
			printf("unknown addrtype\n");
		break;
	}
        
	addrs = (struct in_addr **)sh->h_addr_list;                       //get the server(receiver)'s ip address
	sockfd = socket(AF_INET, SOCK_STREAM, 0);                           //create the socket
	if (sockfd <0)
	{
		printf("error in socket");
		exit(1);
	}
	ser_addr.sin_family = AF_INET;                                                      
	ser_addr.sin_port = htons(MYTCP_PORT);
	memcpy(&(ser_addr.sin_addr.s_addr), *addrs, sizeof(struct in_addr));	
	bzero(&(ser_addr.sin_zero), 8);
	ret = connect(sockfd, (struct sockaddr *)&ser_addr, sizeof(struct sockaddr));         //connect the socket with the server(receiver)
	if (ret != 0) {
		printf ("connection failed\n"); 
		close(sockfd); 
		exit(1);
	}
	
	str_cli(stdin, sockfd);                       //perform the transmission

	close(sockfd);
	exit(0);
}
Пример #25
0
}int main(int argc, char *argv[])
{
    int sockfd;
    struct sockaddr_in servaddr;
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    memset(&servaddr, 0, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(9877);
    inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
    connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
    str_cli(stdin, sockfd);
    return 0;
}
Пример #26
0
int main(int argc, char **argv) {
    if (argc != 2)
        lx_err_quit("usage: tcpcli < IPaddress>");
    int sockfd = lx_socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in servaddr;
    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_fimily = AF_INET;
    servaddr.sin_port = htons(SERV_PORT);
    inet_pton(AF_INEF, argv[1], &servaddr.sin_add);
    conect(sockfd, (struct sockaddr_in *)&servaddr, sizeof(servaddr));
    str_cli(stdin, sockfd);
    exit(0);
}
Пример #27
0
int main(int argc, char** argv)
{
    int sockfd, n;
    struct sockaddr_in servaddr;
    struct itimerval val;
    fd_set rset, wset;

    if (argc != 2) err_quit("usage: a.out <IPaddress>");

    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) err_sys("socket error");

    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(13); /* echo server */
    Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

    /* Set interval timer to go off before 3WHS completes */
    Signal(SIGALRM, sig_alrm);
    val.it_interval.tv_sec = 0;
    val.it_interval.tv_usec = 0;
    val.it_value.tv_sec = 0;
    val.it_value.tv_usec = 50000; /* 50 ms */
    if (setitimer(ITIMER_REAL, &val, NULL) == -1) err_sys("setitimer error");

again:
    if (connect(sockfd, (SA*)&servaddr, sizeof(servaddr)) < 0) {
        if (errno == EINTR) {
#ifdef notdef
            goto again; /* second call to connect() -> EADDRINUSE */
#endif
#ifdef notdef
            printf("interrupted system call\n");
            exit(0);
#endif
        } else
            err_sys("connect error");
    }

    FD_ZERO(&rset);
    FD_SET(sockfd, &rset);
    wset = rset;
    sleep(4);
    n = Select(sockfd + 1, &rset, &wset, NULL, NULL);
    printf("select returned %d\n", n);
    if (FD_ISSET(sockfd, &rset)) printf("socket is readable\n");
    if (FD_ISSET(sockfd, &wset)) printf("socket is writable\n");

    str_cli(stdin, sockfd); /* do it all */

    exit(0);
}
Пример #28
0
int main(int argc,char *argv[])
{
	int	sockfd;
	if(argc == 2)
		sockfd = Tcp_connect(NULL,argv[1]);
	else if(argc == 3)
		sockfd = Tcp_connect(argv[1],argv[2]);
	else
		err_quit("usage:client01 [<hostname>] service\n");
	
	str_cli(stdin,sockfd);
	Close(sockfd);
	exit(0);
}
Пример #29
0
int main(int argc, char **argv) {
    if (argc != 2)
        err_quit("usage: str_cli_kqueue04 <IPadress>");

    struct sockaddr_in serv;
    bzero(&serv, sizeof(serv));
    serv.sin_family = AF_INET;
    serv.sin_port = htons(SERV_PORT);
    Inet_pton(AF_INET, argv[1], &serv.sin_addr);
    int sockfd = Socket(AF_INET, SOCK_STREAM, 0);
    Connect(sockfd, (struct sockaddr *)&serv, sizeof(serv));
    str_cli(stdin, sockfd);
    return 0;
}
Пример #30
0
int main(int argc, char **argv) {
	int sockfd;
	struct sockaddr_in servaddr;

	if(argc != 2)
		err_quit("usage: ./echo_client <IPaddress>");
	
	sockfd = Socket(AF_INET, SOCK_STREAM, 0);
	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(5555);
	Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);
	Connect(sockfd, (SA *)&servaddr, sizeof(servaddr));
	str_cli(stdin, sockfd);
	exit(0);
}