Functions | Variables

socket_client.c File Reference

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "proxylib.h"
#include "echo.h"
Include dependency graph for socket_client.c:

Go to the source code of this file.

Functions

void str_cli (FILE *, int)
int main (int argc, char **argv)

Variables

int ns_errno

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 13 of file socket_client.c.

{
  int sockfd;
  struct sockaddr_in servaddr;

  if (argc != 3) {
    fprintf(stderr, "usage: tcpcli <IPaddress> <port>");
    exit(-1);
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);

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

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

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

  exit(0);
}

Here is the call graph for this function:

void str_cli ( FILE *  fp,
int  sockfd 
)

Definition at line 37 of file socket_client.c.

{
  char sendline[MAXLINE], recvline[MAXLINE];

  while (fgets(sendline, MAXLINE, fp) != NULL) {

    Writen(sockfd, sendline, strlen(sendline));

    if (Readline(sockfd, recvline, MAXLINE) == 0) {
      fprintf(stderr, "str_cli: server terminated prematurely");
      return;
    }

    fputs(recvline, stdout);
  }
}

Here is the call graph for this function:


Variable Documentation

int ns_errno

Definition at line 9 of file socket_client.c.