Completata la parte su getaddinfo con delle funzioni di ausilio per chiamare
[gapil.git] / sources / TCP_echo.c
index 691911e0c57c0c23b38ac742d7fa4a3d707d9ff0..f60c518233c4d2e399d9fcc7357c74319a5b571b 100644 (file)
@@ -40,6 +40,7 @@
 #include <errno.h>      /* include error codes */
 #include <string.h>     /* include erroro strings definitions */
 
+#include "Gapil.h"
 #include "macros.h"
 
 #define MAXLINE 256
@@ -55,7 +56,6 @@ int main(int argc, char *argv[])
  */
     int sock, i;
     int reset = 0;
-    struct sockaddr_in serv_add;
     struct linger ling;
     /*
      * Input section: decode parameters passed in the calling 
@@ -89,23 +89,9 @@ int main(int argc, char *argv[])
      *               Main code beginning
      * 
      * ***********************************************************/
-    /* create socket */
-    if ( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
-       perror("Socket creation error");
-       return 1;
-    }
-    /* initialize address */
-    memset((void *) &serv_add, 0, sizeof(serv_add)); /* clear server address */
-    serv_add.sin_family = AF_INET;                   /* address type is INET */
-    serv_add.sin_port = htons(7);                    /* echo port is 7 */
-    /* build address using inet_pton */
-    if ( (inet_pton(AF_INET, argv[optind], &serv_add.sin_addr)) <= 0) {
-       perror("Address creation error");
-       return 1;
-    }
-    /* extablish connection */
-    if (connect(sock, (struct sockaddr *)&serv_add, sizeof(serv_add)) < 0) {
-       perror("Connection error");
+    /* call sockaddr to get a connected socket */
+    if ( (sock = sockconn(argv[optind], "echo", 6, SOCK_STREAM)) < 0) {
+       if (errno) perror("Socket creation error");
        return 1;
     }
     /* check if resetting on close is required */