ddos/server.c
changeset 160 26414889dded
parent 159 44823a881da1
child 161 36f763c8ab16
--- a/ddos/server.c
+++ b/ddos/server.c
@@ -7,20 +7,25 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/socket.h>
 #include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
 #include <netdb.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
+#include <netinet/in.h>
 #include <signal.h>
 
-#define MAXLEN 80
-
 int set_proc_limit (int);
 
+#define SVPORT "4000"
+#define MAXLEN 1024
+#define MAXMEM 200
+
 int server_write (int client_socket, char *s)
 {
+    if (s == NULL) {
+        fprintf (stderr, "Invalid data: s == NULL");
+        return -1;
+    }
+
     return write (client_socket, s, strlen (s));
 }
 
@@ -55,14 +60,15 @@
         }
         // disable IPV6ONLY, eg enable an hybrid socket
         if (rp->ai_family == AF_INET6)
-            setsockopt (server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof (int));
+            if (setsockopt (server_socket, IPPROTO_IPV6, IPV6_V6ONLY, &no, sizeof (int)) == -1)
+                perror ("setsockopt");
 
         if ((bind (server_socket, rp->ai_addr, rp->ai_addrlen)) == -1) {
             perror ("BIND");
             close (server_socket);
             server_socket = -1;
         } else {
-            printf ("bound to an %s socket\n", (rp->ai_family == AF_INET6) ? "IPv6" : "IPv4");
+            printf ("bound to an %s socket on port %s\n", (rp->ai_family == AF_INET6) ? "IPv6" : "IPv4", port);
         }
     }
 
@@ -90,7 +96,7 @@
     pid_t pid;
     pid_t parent_pid;
 
-    if ((server_socket = server_init ("4000")) < 0)
+    if ((server_socket = server_init (SVPORT)) < 0)
         return EXIT_FAILURE;
 
     int links = 0;