Permalink
Browse files

pasv debuggt, memset für ipstr

  • Loading branch information...
1 parent d212860 commit c5a7d82c0cafea82f379dac2eb7a3e15784eb92a @trebor8x trebor8x committed Jun 11, 2009
Showing with 15 additions and 19 deletions.
  1. +15 −19 duoit.c
View
@@ -228,8 +228,6 @@ int handle_data_connection(int lsocket, usr *head) {
socklen_t addrlen = sizeof remoteaddr;
int newfd; // newly accept()ed socket descriptor
usr *user;
-
- printf("opening passive data connection\n");
// find user
if (find_user_by_dsocket(lsocket, head, &user)) {
@@ -499,7 +497,7 @@ int list_command(instruc *instruction, usr *user) {
*/
int pasv_command(instruc *instruction, usr *user) {
char reply[30 + 18 + 7]; //#chars of standard reply + ip + #,
- char ipstr[INET6_ADDRSTRLEN] = LISTENIP;
+ char ipstr[INET6_ADDRSTRLEN];
char port1[4];
char port2[4];
char possible_port[5];
@@ -513,7 +511,9 @@ int pasv_command(instruc *instruction, usr *user) {
memset(port2, '\0', sizeof port2);
memset(possible_port, '\0', sizeof possible_port);
memset(reply, '\0', sizeof reply);
+ memset(ipstr, '\0', sizeof ipstr);
+ strcpy(ipstr, LISTENIP);
//Create new d_socket we will listen on
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET; //PASV command only definded for IPv4
@@ -602,7 +602,6 @@ int pasv_command(instruc *instruction, usr *user) {
*/
int epsv_command(instruc *instruction, usr *user) {
char reply[43 + 5]; // chars of standard reply + port
- char ipstr[INET6_ADDRSTRLEN] = LISTENIP;
char possible_port[5];
char *ptr;
int mod, div, i, h;
@@ -881,22 +880,18 @@ int main(int argc, char *argv[]) {
} else {
if (!find_user_by_dsocket(i, head, &current_user)) {
//got new data-connection
- handle_data_connection(i, head);
- continue;
- }
- //???
- printf(" \n");
- if ((nbytes = recv(i, buf, sizeof buf, 0)) <= 0) {
- // got error or connection closed by client
- if (nbytes == 0) {
- // connection closed
- printf("socket %d hung up\n", i);
- } else {
- printf("--- fuck\n");
- perror("recv");
- }
- remove_fd(i);
+ handle_data_connection(i, head);
} else {
+ if ((nbytes = recv(i, buf, sizeof buf, 0)) <= 0) {
+ // got error or connection closed by client
+ if (nbytes == 0) {
+ // connection closed
+ printf("socket %d hung up\n", i);
+ } else {
+ perror("recv");
+ }
+ remove_fd(i);
+ } else {
// client sends message. dispatch it
if (find_user_by_csocket(i, head, &current_user)) {
printf("*ERR* corresponding user to socket %d not found!\n", i);
@@ -908,5 +903,6 @@ int main(int argc, char *argv[]) {
}
}
}
+ }
return 0;
}

0 comments on commit c5a7d82

Please sign in to comment.