utils/ripupdate/ripupdate.c

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

FUNCTIONS

This source file includes following functions.
  1. main

   1 /******************
   2   Copyright (c) 2002                                        RIPE NCC
   3 
   4   All Rights Reserved
   5 
   6   Permission to use, copy, modify, and distribute this software and its
   7   documentation for any purpose and without fee is hereby granted,
   8   provided that the above copyright notice appear in all copies and that
   9   both that copyright notice and this permission notice appear in
  10   supporting documentation, and that the name of the author not be
  11   used in advertising or publicity pertaining to distribution of the
  12   software without specific, written prior permission.
  13 
  14   THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  16   AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  17   DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  18   AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20   ***************************************/
  21 
  22 #include <stdio.h>
  23 #include <sys/types.h>
  24 #include <sys/socket.h>
  25 #include <netinet/in.h>
  26 #include <netdb.h>
  27 
  28 
  29 int main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  30 {
  31 
  32 
  33 int sockfd;
  34 struct hostent *hptr;
  35 struct sockaddr_in serv_addr;
  36 struct in_addr  *paddr;
  37 char line_buff[2048];
  38 int nread;
  39 FILE *networkR, *networkW;
  40 
  41  if(argc<3) {
  42          fprintf(stderr, "Usage: %s host port\n", argv[0]);
  43          exit(1);
  44  }
  45  fprintf(stderr, "Making connection to server %s port %d\n", argv[1], atoi(argv[2]));
  46  if ((sockfd=socket(AF_INET, SOCK_STREAM, 0))==-1){
  47      perror("socket");
  48      return(NULL);
  49  }
  50  hptr=gethostbyname(argv[1]);
  51  paddr=(struct in_addr *)hptr->h_addr;
  52  bzero(&serv_addr, sizeof(serv_addr));
  53  serv_addr.sin_family=AF_INET;
  54  serv_addr.sin_port=htons(atoi(argv[2]));
  55  memcpy(&serv_addr.sin_addr, paddr, sizeof(struct in_addr));
  56  fprintf(stderr,"Trying %s port %d\n", inet_ntoa(serv_addr.sin_addr), atoi(argv[2]));
  57  if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))==-1) {
  58    perror("connect");
  59    return(NULL);
  60  }
  61  fprintf(stderr, "Connected. Sending object:\n");
  62  
  63  
  64  while(fgets(line_buff, sizeof(line_buff), stdin))
  65  {
  66   if(strncmp(line_buff, "%", 1)==0) break;
  67   write(sockfd, line_buff, strlen(line_buff));
  68  } 
  69 
  70 
  71  fprintf(stderr, "waiting for ack, Ctrl-C to exit\n"); 
  72  
  73 while((nread=read(sockfd, line_buff, sizeof(line_buff)))>0)
  74  write(2, line_buff, nread );
  75 
  76  fprintf(stderr, "read %d bytes\n", nread);
  77  if(nread==-1) perror("read socket");
  78       
  79 return(0);
  80 }

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