Materiale su {{{TCP_CONNECTION}}}.
[gapil.git] / sources / TCP_echo.c
index 6b806ac944032fd763cfe948e959b8e1582c8f18..50f681b6e09aacb0d59acccaf885161294337601 100644 (file)
 #include <errno.h>      /* include error codes */
 #include <string.h>     /* include erroro strings definitions */
 #include <stdlib.h>
 #include <errno.h>      /* include error codes */
 #include <string.h>     /* include erroro strings definitions */
 #include <stdlib.h>
+#include <netinet/tcp.h>
+
+/* still not defined in some include, because too new ... */
+#ifndef TCP_CONGESTION
+#define TCP_CONGESTION 13
+#endif
+
+
 
 #include "Gapil.h"
 #include "macros.h"
 
 #include "Gapil.h"
 #include "macros.h"
@@ -56,14 +64,17 @@ int main(int argc, char *argv[])
  * Variables definition  
  */
     int sock, i;
  * Variables definition  
  */
     int sock, i;
+    socklen_t len;
     int reset = 0;
     int reset = 0;
+    int verbosity = 0;
+    char buffer[MAXLINE];
     struct linger ling;
     /*
      * Input section: decode parameters passed in the calling 
      * Use getopt function
      */
     opterr = 0;         /* don't want writing to stderr */
     struct linger ling;
     /*
      * Input section: decode parameters passed in the calling 
      * Use getopt function
      */
     opterr = 0;         /* don't want writing to stderr */
-    while ( (i = getopt(argc, argv, "hr")) != -1) {
+    while ( (i = getopt(argc, argv, "hrv")) != -1) {
        switch (i) {
        /* 
         * Handling options 
        switch (i) {
        /* 
         * Handling options 
@@ -73,6 +84,9 @@ int main(int argc, char *argv[])
            usage();
            return(1);
            break;
            usage();
            return(1);
            break;
+       case 'v':
+           verbosity = 1;
+           break;
        case 'r':
            reset = 1;
            break;
        case 'r':
            reset = 1;
            break;
@@ -90,11 +104,21 @@ int main(int argc, char *argv[])
      *               Main code beginning
      * 
      * ***********************************************************/
      *               Main code beginning
      * 
      * ***********************************************************/
-    /* call sockaddr to get a connected socket */
+    /* call sockconn to get a connected socket */
     if ( (sock = sockconn(argv[optind], "echo", 6, SOCK_STREAM)) < 0) {
        if (errno) perror("Socket creation error");
        return 1;
     }
     if ( (sock = sockconn(argv[optind], "echo", 6, SOCK_STREAM)) < 0) {
        if (errno) perror("Socket creation error");
        return 1;
     }
+    /* print some info about the socket, used to test some TCP_* options */
+    if (verbosity) {
+       len = sizeof(buffer);
+       if (getsockopt(sock, SOL_TCP, TCP_CONGESTION, buffer, &len) < 0) {
+           perror("Cannot read congestion algorithm");
+       } else {
+           buffer[len]=0;
+           printf("Congestion algorithm %s\n", buffer);
+       }
+    }
     /* check if resetting on close is required */
     if (reset) {
        printf("Setting reset on close \n");
     /* check if resetting on close is required */
     if (reset) {
        printf("Setting reset on close \n");