X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=listati%2FTCP_echod_first.c;h=2fb50a3a91ad37e2cdc37eda841c50289be92b6f;hp=81085a7b5f59f831291723a6561475e6aaf624f5;hb=7e19b798d0cc09960daad695d8f3b242170bb3b4;hpb=3e8003adb1396080659ef5d34896eb2f573be6cd diff --git a/listati/TCP_echod_first.c b/listati/TCP_echod_first.c index 81085a7..2fb50a3 100644 --- a/listati/TCP_echod_first.c +++ b/listati/TCP_echod_first.c @@ -4,12 +4,11 @@ int main(int argc, char *argv[]) pid_t pid; struct sockaddr_in serv_add; ... - /* create socket */ + /* create and init socket */ if ( (list_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("Socket creation error"); exit(1); } - /* initialize address and bind socket */ 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 */ @@ -40,6 +39,7 @@ int main(int argc, char *argv[]) exit(1); } while (1) { /* handle echo to client */ + len = sizeof(cli_add); if ( (conn_fd = accept(list_fd, NULL, NULL)) < 0) { PrintErr("accept error"); exit(1);