Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

quit implementiert. Neues struct instruc hält Socket-Nr. und Pointer …

…auf Command-/Parameterbeginn
  • Loading branch information...
commit 43968b44999b323fcef356dc2a5621346a409ffb 1 parent c73c928
@grobie authored
Showing with 39 additions and 6 deletions.
  1. +39 −6 duoit.c
View
45 duoit.c
@@ -14,6 +14,14 @@
#define DPORT "3020" // the default port for data transfering
#define BACKLOG 10 // how many pending connections queue will hold
+
+//struct for command and parameter pointers
+typedef struct {
+ int socket;
+ char *command;
+ char *params;
+} instruc;
+
// get sockaddr, IPv4 or IPv6:
void *get_in_addr(struct sockaddr *sa){
if (sa->sa_family == AF_INET){
@@ -151,11 +159,38 @@ int send_message(int socket, char *message) {
}
/*
+ * quits the connection with client
+ */
+int quit_command(instruc *instruction, fd_set *master) {
+
+ send_message(instruction->socket, "221 Goodbye.");
+ close_connection(instruction->socket, master);
+ return 0;
+}
+
+/*
* dispatch message
*
* TODO
*/
-int dispatch(int socket, char *received, int received_len) {
+int dispatch(int socket, char *received, int received_len, fd_set *master) {
+ instruc instruction;
+
+ instruction.socket = socket;
+ if (parse_command(received, received_len, &instruction)) {
+ send_message(socket, "500 Syntax Error");
+ return 1;
+ }
+
+ if (!strcmp(instruction.command, "QUIT")) {
+ quit_command(&instruction, master);
+ } else {
+ send_message(socket, "502 Command not implemented.");
+ }
+ return 0;
+}
+
+int parse_command(char *received, int received_len, instruc *instruction) {
char *parameter;
char command[5];
int input_length;
@@ -197,7 +232,8 @@ int dispatch(int socket, char *received, int received_len) {
printf("command: %s\n", command);
- send_message(socket, "502 Command not implemented.");
+ instruction->command = command;
+ instruction->params = parameter;
return 0;
}
@@ -254,10 +290,7 @@ int main(int argc, char *argv[]) {
}
close_connection(i, &master);
} else {
- if (dispatch(i, buf, nbytes)) {
- send_message(i, "500 Syntax Error");
- }
-
+ dispatch(i, buf, nbytes, &master);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.