Valhalla Legends Archive

Programming => General Programming => Topic started by: tenbytes on September 13, 2004, 02:24 PM

Title: dcc protocol help
Post by: tenbytes on September 13, 2004, 02:24 PM
ok i have my programsending files and shit using the dcc protocol, but when it try to send a file that already exists, the client that i am trying to send to doesn't acknowledge the send...why is this?
Title: Re:dcc protocol help
Post by: Banana fanna fo fanna on September 13, 2004, 03:39 PM
it would help if you elaborated.
Title: Re:dcc protocol help
Post by: tenbytes on September 13, 2004, 03:42 PM
what didn't you understand clearly?
Title: Re:dcc protocol help
Post by: Banana fanna fo fanna on September 13, 2004, 03:45 PM
code. there's so many different problems that could be wrong with it.
Title: Re:dcc protocol help
Post by: tenbytes on September 13, 2004, 03:50 PM
code is rough right now...

it sends the file if it doesn't exist, but if it does then the client never connects to the server and 'accept()' just blocks..


int CreateServer(int irc_sock_fd, TargetInfo target_info) {
   int sock_fd, dcc_sock_fd, local_addr_len, loop;
   struct sockaddr_in sockaddr, local_addr;
   char packet[255], buf[4], file_buf[40];
   FILE *fp;

   sock_fd = socket(AF_INET, SOCK_STREAM, 0);
   
   local_addr_len = sizeof(struct sockaddr);

   if(-1 == sock_fd) {
      puts("Error Creating Socket");
      return(-1);
   }
   
   sockaddr.sin_family      = AF_INET;
   sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
   sockaddr.sin_port        = htons(80);

   memset(&(sockaddr.sin_zero), '\0', 8);

   if(bind(sock_fd, (struct sockaddr*)&sockaddr, sizeof(struct sockaddr)) == -1) {
      puts("Error Binding Socket");
      return(-1);
   }
   
   if(listen(sock_fd, 5) == -1) {
      puts("Error Listening");
      return(-1);
   }
   
   /* gets the port this server is running on */   
   if(getsockname(sock_fd, (struct sockaddr*)&local_addr, &local_addr_len) == -1) {
      return(-1);
   }
   
   fp = fopen("C:\\extras\\programming\\c\\dcc_server\\Debug\\test.txt", "r");
   
   if(NULL == fp) {
      puts("Error Opening File!");

      return(0);
   }

   /* PRIVMSG ((target) :^ADCC SEND ((filename) ((longip) ((port) ((filesize)^A */
   sprintf(packet, "PRIVMSG %s :\001DCC SEND %s %d %d %d\001\r\n",
                  target_info.nick, target_info.file_name, ntohl(inet_addr(ip_addr)), ntohs(local_addr.sin_port),
                  FileSize(fp));
   
   send(irc_sock_fd, packet, strlen(packet), 0);
   
   puts("Waiting..");
   
   dcc_sock_fd = accept(sock_fd, NULL, NULL);

   if(dcc_sock_fd == -1) {
      puts("Error In Accept()");
     return(-1);
   }

   puts("Got A Connection!\n");
   
   while(fgets(file_buf, sizeof(file_buf), fp) != NULL) {
      send(dcc_sock_fd, file_buf, sizeof(file_buf), 0);

      memset(file_buf, '\0', sizeof(file_buf));
   }

   closesocket(sock_fd);

   return(1);
}
Title: Re:dcc protocol help
Post by: dxoigmn on September 13, 2004, 04:01 PM
Maybe the client doesn't want to overwrite an existing file for security reasons?

Edit:  You should have a timeout for your accept().  Because if it blocks infinitely, then a remote client could exploit this causing your app to hang.