Permalink
Browse files

pasv debuggt

  • Loading branch information...
1 parent 03a7e2e commit c47f70d6a9503c759687595ea28218a1005564ed Robert A committed Jun 11, 2009
Showing with 11 additions and 51 deletions.
  1. +11 −51 duoit.c
View
@@ -1,42 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#include <time.h>
-
-#define LISTENIP "127.0.0.1"
-#define CPORT "3021" // the port users will be connecting to
-#define DPORT "3020" // the default port for data transfering
-#define BACKLOG 10 // how many pending connections queue will hold
-#define PATHLENGTH 256 //default pathlength for pwd-command - may be dynamically increased later
-#define IMAGE 1 //type image/binary
-#define ASCII 2 //type ascii
-
-//struct for command and parameter pointers
-typedef struct {
- char *command;
- char *params;
-} instruc;
-
-// user struct
-typedef struct usr {
- int c_socket;
- int d_socket;
- char d_address[INET6_ADDRSTRLEN];
- int d_port;
- int passv;
- int type;
- char *pwd;
- int pwd_len;
- struct usr *next;
-} usr;
+#include "duoit.h"
// global, I want this!!! ;)
fd_set master; // master file descriptor list
@@ -356,7 +318,6 @@ char *trim(char *str) {
return temp;
}
-
/*
* send messages to socket
*
@@ -442,7 +403,7 @@ int port_command(instruc *instruction, usr *user) {
/*
* sets the mode of file transfer
*/
-int set_user_type(instruc *instruction, usr *user) {
+int type_command(instruc *instruction, usr *user) {
int i = 0;
if (!instruction->params) {
@@ -654,7 +615,7 @@ int epsv_command(instruc *instruction, usr *user) {
//Create new d_socket we will listen on
memset(&hints, 0, sizeof hints);
- hints.ai_family = AF_INET; //PASV command only definded for IPv4
+ hints.ai_family = AF_INET6; //EPASV command only definded for IPv6
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE; //use own IP
@@ -811,7 +772,7 @@ int dispatch(usr *user, char *received, int received_len, usr **head) {
return 1;
}
} else if (!strcmp(instruction.command, "TYPE")) {
- if (set_user_type(&instruction, user)) {
+ if (type_command(&instruction, user)) {
return 1;
}
} else if (!strcmp(instruction.command, "LIST")) {
@@ -913,13 +874,18 @@ int main(int argc, char *argv[]) {
perror("select");
exit(4);
}
- printf("--- sth happens\n");
for(i = 0; i <= fdmax; i++) {
if (FD_ISSET(i, &read_fds)) {
if (i == listener) {
handle_new_connection(&listener, &head);
} else {
- printf("--- client sends sth or got new data connection\n");
+ 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) {
@@ -931,22 +897,16 @@ int main(int argc, char *argv[]) {
}
remove_fd(i);
} else {
- if (find_user_by_dsocket(i, head, &current_user)) {
// 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);
continue;
}
dispatch(current_user, buf, nbytes, &head);
- } else {
- printf("--- handle data connection\n");
- handle_data_connection(i, head);
}
}
}
}
}
- }
-
return 0;
}

0 comments on commit c47f70d

Please sign in to comment.