• Welcome to Valhalla Legends Archive.
 

dcc protocol help

Started by tenbytes, September 13, 2004, 02:24 PM

Previous topic - Next topic

tenbytes

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?

Banana fanna fo fanna

it would help if you elaborated.

tenbytes

what didn't you understand clearly?

Banana fanna fo fanna

code. there's so many different problems that could be wrong with it.

tenbytes

#4
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);
}

dxoigmn

#5
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.