Aggiornamento note copyright
[gapil.git] / sources / UDP_echo.c
index a3bbd9b8c4fac087caacace36f33ed3fcda45652..e8fa3adbcfd8a247c6b5d58fbcc699321d918efb 100644 (file)
  *
  * Usage: echo -h give all info's
  *
- * $Id: UDP_echo.c,v 1.3 2004/06/02 16:31:50 piccardi Exp $
- *
  ****************************************************************/
 /* 
  * Include needed headers
  */
-#include <sys/types.h>   /* predefined types */
-#include <unistd.h>      /* include unix standard library */
-#include <arpa/inet.h>   /* IP addresses conversion utiliites */
-#include <sys/socket.h>  /* socket library */
-#include <stdio.h>      /* include standard I/O library */
-#include <errno.h>      /* include error codes */
-#include <string.h>     /* include erroro strings definitions */
+#include <sys/types.h>   /* primitive system data types */
+#include <unistd.h>      /* unix standard library */
+#include <arpa/inet.h>   /* IP addresses conversion utilities */
+#include <sys/socket.h>  /* socket constants, types and functions */
+#include <stdio.h>      /* standard I/O library */
+#include <errno.h>      /* error definitions and routines */
+#include <string.h>     /* C strings library */
+#include <stdlib.h>      /* C standard library */
 
 #include "macros.h"
 
 #define MAXLINE 256
 void usage(void);
-void ClientEcho(FILE * filein, int socket, struct sockaddr_in *serv_add);
+void ClientEcho(FILE * filein, int socket);
 void SigTERM_hand(int sig);
 
 /* Program begin */
@@ -54,7 +53,7 @@ int main(int argc, char *argv[])
  * Variables definition  
  */
     int sock, i;
-    struct sockaddr_in serv_add;
+    struct sockaddr_in dst_addr;
     /*
      * Input section: decode parameters passed in the calling 
      * Use getopt function
@@ -90,15 +89,15 @@ int main(int argc, char *argv[])
        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 */
+    memset((void *) &dst_addr, 0, sizeof(dst_addr)); /* clear address */
+    dst_addr.sin_family = AF_INET;                   /* address type is INET */
+    dst_addr.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) {
+    if ( (inet_pton(AF_INET, argv[optind], &dst_addr.sin_addr)) <= 0) {
        perror("Address creation error");
        return 1;
     }
-    connect(sock, &serv_add, sizeof(*serv_add));
+    connect(sock, (struct sockaddr *) &dst_addr, sizeof(dst_addr));
     /* do read/write operations */
     ClientEcho(stdin, sock);
     /* normal exit */