## utils/ripupdate/ripupdate.c

/* [<][>][^][v][top][bottom][index][help] */

## FUNCTIONS

This source file includes following functions.

1. main

       1 #include <stdio.h>
       2 #include <sys/types.h>
       3 #include <sys/socket.h>
       4 #include <netinet/in.h>
       5 #include <netdb.h>
       6
       7
       8 int main(int argc, char **argv)
         /* [<][>][^][v][top][bottom][index][help] */
       9 {
      10
      11
      12 int sockfd;
      13 struct hostent *hptr;
      14 struct sockaddr_in serv_addr;
      15 struct in_addr  *paddr;
      16 char line_buff[2048];
      17 int nread;
      18 FILE *networkR, *networkW;
      19
      20  if(argc<3) {
      21          fprintf(stderr, "Usage: %s host port\n", argv[0]);
      22          exit(1);
      23  }
      24  fprintf(stderr, "Making connection to server %s port %d\n", argv[1], atoi(argv[2]));
      25  if ((sockfd=socket(AF_INET, SOCK_STREAM, 0))==-1){
      26      perror("socket");
      27      return(NULL);
      28  }
      29  hptr=gethostbyname(argv[1]);
      30  paddr=(struct in_addr *)hptr->h_addr;
      31  bzero(&serv_addr, sizeof(serv_addr));
      32  serv_addr.sin_family=AF_INET;
      33  serv_addr.sin_port=htons(atoi(argv[2]));
      34  memcpy(&serv_addr.sin_addr, paddr, sizeof(struct in_addr));
      35  fprintf(stderr,"Trying %s port %d\n", inet_ntoa(serv_addr.sin_addr), atoi(argv[2]));
      36  if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))==-1) {
      37    perror("connect");
      38    return(NULL);
      39  }
      40  fprintf(stderr, "Connected. Sending object:\n");
      41
      42
      43  while(fgets(line_buff, sizeof(line_buff), stdin))
      44  {
      45   if(strncmp(line_buff, "%", 1)==0) break;
      46   write(sockfd, line_buff, strlen(line_buff));
      47  }
      48
      49
      50  fprintf(stderr, "waiting for ack, Ctrl-C to exit\n");
      51
      52 while((nread=read(sockfd, line_buff, sizeof(line_buff)))>0)
      53  write(2, line_buff, nread );
      54
      55  fprintf(stderr, "read %d bytes\n", nread);
      56  if(nread==-1) perror("read socket");
      57
      58 return(0);
      59 }

/* [<][>][^][v][top][bottom][index][help] */