Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. int         sv_handle_pasv(char *str, int csfd, status_t *stat)
  2. {
  3.   struct sockaddr_in    addr;
  4.   socklen_t     size;
  5.   char          *ip;
  6.   int           i;
  7.   char          buff[50];
  8.  
  9.   if (stat->ds_fd > - 1)
  10.     reset_dc(stat);
  11.   size = sizeof(addr);
  12.   err(getsockname(csfd, (struct sockaddr*)&addr, &size));
  13.   addr.sin_port = 0;
  14.   addr.sin_family = AF_INET;
  15.   create_listen_socket(&addr, &stat->ds_fd);
  16.   send_command("227 Entering Passive Mode. ", csfd);
  17.   ip = inet_ntoa(addr.sin_addr);
  18.   i = 0;
  19.   while (ip[i] != 0)
  20.     {
  21.       if (ip[i] == '.')
  22.     ip[i] = ',';
  23.       i++;
  24.     }
  25.   send_command(ip, csfd);
  26.   send_command(",", csfd);
  27.   err(getsockname(stat->ds_fd, (struct sockaddr*)&addr, &size));
  28.   printf("Opening socket on: %s:%d\n",
  29.      inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
  30.   sprintf(buff, "%d", ntohs(addr.sin_port) / 256);
  31.   send_command(buff, csfd);
  32.   send_command(",", csfd);
  33.   sprintf(buff, "%d", (ntohs(addr.sin_port) % 256));
  34.   send_command(buff, csfd);
  35.   send_command("\n", csfd);
  36.   stat->dcs_fd = accept(stat->ds_fd, (struct sockaddr*)&addr, &size);
  37.   err(stat->dcs_fd);
  38.   printf("Client connected from: %s:%d\n",
  39.      inet_ntoa(addr.sin_addr), ntohs(addr.sin_port));
  40.   (void)str;
  41.   return (0);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement