Permalink
Browse files

Port command implemented

  • Loading branch information...
1 parent 65235d8 commit 890e62c0b1538e2cd9529f1f04d1923db180aae5 Robert A committed Jun 9, 2009
Showing with 30 additions and 5 deletions.
  1. +30 −5 duoit.c
View
35 duoit.c
@@ -329,17 +329,43 @@ int user_command(instruc *instruction, usr *user) {
/*
* save non-default data-connection infos
+ * TODO assure correct parameter sytnax, AF_INET (!=INET6)
*/
int port_command(instruc *instruction, usr *user) {
-
+ int i = 0, port = 0;
+ char *ptr, *param;
+ char ip[INET6_ADDRSTRLEN + 5 + 6]; //INET6_ADDR + #"," + #(port-digits)
- if (!instruction->params) {
+ memset(ip, '\0', sizeof ip);
+ param = instruction->params;
+ if (!param) {
send_message(user->csocket, "501 Syntax error in parameters or arguments.");
return 1;
}
//remove redundant whitespaces from params
- instruction->params = trim(instruction->params);
-
+ param = trim(param);
+
+ //determine IP and Port for Data-Connection
+ ptr = strtok(param, ",");
+ while(ptr != NULL) {
+ if (i < 3) {
+ strcat(ip, ptr);
+ strcat(ip, ".");
+ } else if (i == 3) {
+ strcat(ip, ptr);
+ } else if (i == 4) {
+ port += atoi(ptr) * 256;
+ } else if (i == 5) {
+ port += atoi(ptr);
+ } else {
+ send_message(user->csocket, "501 Syntax error in parameters or arguments.");
+ return 1;
+ }
+ i++;
+ ptr = strtok(NULL, ",");
+ }
+ strcpy(user->d_address, ip);
+ user->d_port = port;
send_message(user->csocket, "200 PORT command successful.");
return 0;
}
@@ -475,7 +501,6 @@ int dispatch(usr *user, char *received, int received_len, fd_set *master, usr **
return 1;
}
} else if (!strcmp(instruction.command, "PORT")) {
- printf("+++params: %s\n", instruction.params);
if (port_command(&instruction, user)) {
return 1;
}

0 comments on commit 890e62c

Please sign in to comment.