sft_.c

Go to the documentation of this file.
00001 
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <sys/stat.h>
00024 #include <sys/types.h>
00025 #include <unistd.h>
00026 #include <netinet/in.h>
00027 #include <netdb.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include <unistd.h> //para comando de usleep
00032 #include <ctype.h>
00033 
00034 
00035 #include "sft.h"
00036 
00037 struct sockaddr_in server;
00038 struct hostent *hp, *gethostbyname();
00039 
00040 
00048 int main(int argc, char *argv[])
00049 {
00050 
00051   if (argc < 2) {
00052      printf("Erro uso correto:\n") ;
00053      printf("\n    %s <hostname> \n\n", argv[0]) ;
00054      exit(1) ;
00055   }
00056 
00058   s1=socket(AF_INET, SOCK_STREAM, 0);
00059 
00060   if (s1<0) {
00061      perror("opening stream socket");
00062      exit(1);
00063   }
00064 
00065   hp = gethostbyname(argv[1]);
00066   if (hp == 0) {
00067      fprintf(stderr,"%s: Unkown host\n",argv[1]);
00068      exit(2);
00069   }
00070   
00071   server.sin_family = AF_INET;
00072   server.sin_port = htons(SFT_PORT);
00073   server.sin_addr = *((struct in_addr *)hp->h_addr);
00074   memset(&(server.sin_zero), '\0', 8);  // zero the rest of the struct 
00075     
00076 
00077   if (connect(s1, (struct sockaddr *)&server, sizeof server ) < 0) {
00078     perror("connectando stream socket");
00079     exit(1);
00080   }
00081 
00082   printf("\nSFT Conectado com sucesso...\n") ;
00083   id_stc = 0;//id do primeiro pacote
00084   
00085   do {
00086          printf("\nSFT>") ;
00087          fgets(buff,TAMMSG,stdin);//pega a informação do terminal.
00088          if(strncmp(buff, "quit",4)==0) break;
00089 
00090          if(trata_sft()== -1){
00091                  printf("Comando nao existe\n");
00092                  continue;
00093          }
00094 
00095 
00096 
00097                 } while (msg_send[0] != '.');
00098    
00099   close(s1);
00100   exit(0);
00101  
00102 }
00103 
00104 
00105 
00106