X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=listati%2FEchoServerWrong.c;fp=listati%2FEchoServerWrong.c;h=f9a67b6467e649e2c245b3207eb788df681de693;hb=06661f47754a536098afe2b30cb04469918f2fa3;hp=0000000000000000000000000000000000000000;hpb=bdf6e88eeb9b3aef06d57930ec8b89083639e56d;p=gapil.git diff --git a/listati/EchoServerWrong.c b/listati/EchoServerWrong.c new file mode 100644 index 0000000..f9a67b6 --- /dev/null +++ b/listati/EchoServerWrong.c @@ -0,0 +1,32 @@ +int main(int argc, char *argv[]) +{ +/* + * Variables definition + */ + int sock_fd, i; + struct sockaddr_in serv_add; + ... + /* create socket */ + if ( (sock_fd = 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_fd, (struct sockaddr *)&serv_add, sizeof(serv_add)) < 0) { + perror("Connection error"); + return -1; + } + /* read daytime from server */ + ClientEcho(stdin, sock_fd); + /* normal exit */ + return 0; +}