diff --git a/11.client-server-test-error- read write on closed socket/client b/11.client-server-test-error- read write on closed socket/client new file mode 100755 index 0000000..423dc80 Binary files /dev/null and b/11.client-server-test-error- read write on closed socket/client differ diff --git a/11.client-server-test-error- read write on closed socket/daytimecli.c b/11.client-server-test-error- read write on closed socket/daytimecli.c new file mode 100644 index 0000000..811d59a --- /dev/null +++ b/11.client-server-test-error- read write on closed socket/daytimecli.c @@ -0,0 +1,94 @@ + + +#include "../basic.h" +#include + +void sigpipeaction (int signal){ + + int status, pid; + + fprintf(stderr, "Sigpipe catturato\n"); + + +} + + +int main(int argc, char **argv) { + + + struct sigaction sigpipestructure; + sigpipestructure.sa_handler = sigpipeaction; + sigpipestructure.sa_flags = 0; + + sigaction (SIGPIPE, &sigpipestructure, NULL); + + + + siginterrupt (SIGPIPE,1); + + + + + int sockfd; + struct sockaddr_in servaddr; + + if (argc != 3){ + printf("usage: daytimecli \n"); + exit(0); +} + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(atoi(argv[2])); /* server port */ + + if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){ + printf("inet_pton error for %s\n", argv[1]); + exit(0); +} + if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){ + printf("connect error\n"); + exit(0); + } + + struct sockaddr_in r_server_local_addr; + unsigned int r_server_local_addr_len = sizeof(r_server_local_addr); + + char * socket_buffer = (char *) malloc (r_server_local_addr_len) ; + int ridden; + + + + + + for (int i = 0; i < 100; i ++){ + + ridden = read (sockfd, socket_buffer,r_server_local_addr_len ); + if (ridden < 0){ + fprintf(stdout,"Errore durante la lettura\n"); + exit(-1); + } else { + fprintf(stdout,"Ho letto %d bytes\n",ridden); + } + } + + + close(sockfd); + + + memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len); + + + char buff[INET_ADDRSTRLEN]; + short port; + + inet_ntop(AF_INET, &(r_server_local_addr.sin_addr), buff, INET_ADDRSTRLEN);// get ip + port = ntohs(r_server_local_addr.sin_port);// get port + + fprintf (stdout,"%s%c%hu\n",buff,':',port); + + + exit(0); +} diff --git a/11.client-server-print-ip-port-bothv2/daytimecli.c~ b/11.client-server-test-error- read write on closed socket/daytimecli.c~ similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimecli.c~ rename to 11.client-server-test-error- read write on closed socket/daytimecli.c~ diff --git a/11.client-server-test-error- read write on closed socket/daytimecli.o b/11.client-server-test-error- read write on closed socket/daytimecli.o new file mode 100644 index 0000000..3753eb4 Binary files /dev/null and b/11.client-server-test-error- read write on closed socket/daytimecli.o differ diff --git a/11.client-server-print-ip-port-bothv2/daytimesrv.c b/11.client-server-test-error- read write on closed socket/daytimesrv.c similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimesrv.c rename to 11.client-server-test-error- read write on closed socket/daytimesrv.c diff --git a/11.client-server-print-ip-port-bothv2/daytimesrv.c~ b/11.client-server-test-error- read write on closed socket/daytimesrv.c~ similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimesrv.c~ rename to 11.client-server-test-error- read write on closed socket/daytimesrv.c~ diff --git a/11.client-server-print-ip-port-bothv2/daytimesrv.o b/11.client-server-test-error- read write on closed socket/daytimesrv.o similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimesrv.o rename to 11.client-server-test-error- read write on closed socket/daytimesrv.o diff --git a/11.client-server-print-ip-port-bothv2/makefile b/11.client-server-test-error- read write on closed socket/makefile similarity index 100% rename from 11.client-server-print-ip-port-bothv2/makefile rename to 11.client-server-test-error- read write on closed socket/makefile diff --git a/11.client-server-print-ip-port-bothv2/makefile~ b/11.client-server-test-error- read write on closed socket/makefile~ similarity index 100% rename from 11.client-server-print-ip-port-bothv2/makefile~ rename to 11.client-server-test-error- read write on closed socket/makefile~ diff --git a/11.client-server-print-ip-port-bothv2/readme~ b/11.client-server-test-error- read write on closed socket/readme similarity index 100% rename from 11.client-server-print-ip-port-bothv2/readme~ rename to 11.client-server-test-error- read write on closed socket/readme diff --git a/11.client-server-test-error- read write on closed socket/readme~ b/11.client-server-test-error- read write on closed socket/readme~ new file mode 100644 index 0000000..e69de29 diff --git a/11.client-server-print-ip-port-bothv2/server b/11.client-server-test-error- read write on closed socket/server similarity index 100% rename from 11.client-server-print-ip-port-bothv2/server rename to 11.client-server-test-error- read write on closed socket/server diff --git a/11.client-server-print-ip-port-bothv2/client b/12.3 nodes communication/client similarity index 100% rename from 11.client-server-print-ip-port-bothv2/client rename to 12.3 nodes communication/client diff --git a/11.client-server-print-ip-port-bothv2/daytimecli.c b/12.3 nodes communication/daytimecli.c similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimecli.c rename to 12.3 nodes communication/daytimecli.c diff --git a/12.3 nodes communication/daytimecli.c~ b/12.3 nodes communication/daytimecli.c~ new file mode 100644 index 0000000..239a866 --- /dev/null +++ b/12.3 nodes communication/daytimecli.c~ @@ -0,0 +1,31 @@ +/* Client che interroga un daytime server */ + +#include "../basic.h" + +int main(int argc, char **argv) { + int sockfd, n; + char recvline[MAXLINE + 1]; + struct sockaddr_in servaddr; + + if (argc != 3){ + printf("usage: daytimecli \n"); + exit(0); +} + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(atoi(argv[2])); /* server port */ + + if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){ + printf("inet_pton error for %s\n", argv[1]); + exit(0); +} + if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){ + printf("connect error\n"); + exit(0); + } + exit(0); +} diff --git a/11.client-server-print-ip-port-bothv2/daytimecli.o b/12.3 nodes communication/daytimecli.o similarity index 100% rename from 11.client-server-print-ip-port-bothv2/daytimecli.o rename to 12.3 nodes communication/daytimecli.o diff --git a/12.3 nodes communication/daytimesrv.c b/12.3 nodes communication/daytimesrv.c new file mode 100644 index 0000000..12c17fd --- /dev/null +++ b/12.3 nodes communication/daytimesrv.c @@ -0,0 +1,63 @@ + + +#include "../basic.h" +#include + +int main(int argc, char **argv) { + int listenfd, connfd, n; + struct sockaddr_in servaddr; + char buff[INET_ADDRSTRLEN]; + short port; + + if (argc != 2 ){ + printf("usage: daytimesrv \n"); + exit(0); +} + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */ + servaddr.sin_port = htons(atoi(argv[1])); /* server port */ + + if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){ + printf("bind error\n"); exit(0); +} + if( listen(listenfd, 5) < 0 ) + { printf("listen error\n"); + exit(0); + } + + struct sockaddr_in client_addr; + unsigned int client_addr_len = sizeof(client_addr); + + struct sockaddr_in server_local_addr; + unsigned int server_local_addr_len = sizeof(server_local_addr); + + char * socket_buffer = (char *) malloc (server_local_addr_len) ; + + + + for ( ; ; ) { + if( (connfd = accept(listenfd, (struct sockaddr *) &client_addr, &client_addr_len)) < 0) + { printf("accept error\n"); + exit(0); + } + + inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN);// get client ip + port = ntohs(client_addr.sin_port);// get client port + + fprintf (stdout,"%s%c%hu\n",buff,':',port); + + + + getsockname (connfd, (struct sockaddr *) &server_local_addr, &server_local_addr_len); + memcpy (socket_buffer, &server_local_addr, server_local_addr_len); + write (connfd,socket_buffer, server_local_addr_len); + + + close(connfd); + } +} diff --git a/12.3 nodes communication/daytimesrv.c~ b/12.3 nodes communication/daytimesrv.c~ new file mode 100644 index 0000000..5a71bf1 --- /dev/null +++ b/12.3 nodes communication/daytimesrv.c~ @@ -0,0 +1,41 @@ +/* stampa l'ip del client */ + +#include "../basic.h" +#include + +int main(int argc, char **argv) { + int listenfd, connfd, n; + struct sockaddr_in servaddr; + char buff[MAXLINE]; + time_t ticks; + + if (argc != 2 ){ + printf("usage: daytimesrv \n"); + exit(0); +} + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */ + servaddr.sin_port = htons(atoi(argv[1])); /* server port */ + + if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){ + printf("bind error\n"); exit(0); +} + if( listen(listenfd, 5) < 0 ) + { printf("listen error\n"); + exit(0); +} + for ( ; ; ) { + if( (connfd = accept(listenfd, (struct sockaddr *) NULL, NULL)) < 0) + { printf("accept error\n"); exit(0);} else { + } + + n=read(connfd, buff, MAXLINE); + fprintf (stdout,%s\n,buff); + close(connfd); + } +} diff --git a/12.3 nodes communication/daytimesrv.o b/12.3 nodes communication/daytimesrv.o new file mode 100644 index 0000000..e160c2e Binary files /dev/null and b/12.3 nodes communication/daytimesrv.o differ diff --git a/12.3 nodes communication/makefile b/12.3 nodes communication/makefile new file mode 100644 index 0000000..16fdd6d --- /dev/null +++ b/12.3 nodes communication/makefile @@ -0,0 +1,9 @@ +all : server client +server : daytimesrv.o ../fun-corso-reti.o + gcc -o server daytimesrv.o ../fun-corso-reti.o +client : daytimecli.o ../fun-corso-reti.o + gcc -o client daytimecli.o ../fun-corso-reti.o +daytimesrv.o : daytimesrv.c ../basic.h + gcc -c -o daytimesrv.o daytimesrv.c +fun-corso-reti.o : ../fun-corso-reti.c ../basic.h + gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c diff --git a/12.3 nodes communication/makefile~ b/12.3 nodes communication/makefile~ new file mode 100644 index 0000000..ed76715 --- /dev/null +++ b/12.3 nodes communication/makefile~ @@ -0,0 +1,8 @@ +server : daytimesrv.o ../fun-corso-reti.o + gcc -o server daytimesrv.o ../fun-corso-reti.o +client : daytimecli.o ../fun-corso-reti.o + gcc -o client daytimecli.o ../fun-corso-reti.o +daytimesrv.o : daytimesrv.c ../basic.h + gcc -c -o daytimesrv.o daytimesrv.c +fun-corso-reti.o : ../fun-corso-reti.c ../basic.h + gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c diff --git a/11.client-server-print-ip-port-bothv2/readme b/12.3 nodes communication/readme similarity index 100% rename from 11.client-server-print-ip-port-bothv2/readme rename to 12.3 nodes communication/readme diff --git a/12.3 nodes communication/readme~ b/12.3 nodes communication/readme~ new file mode 100644 index 0000000..e69de29 diff --git a/12.3 nodes communication/server b/12.3 nodes communication/server new file mode 100755 index 0000000..65d3aab Binary files /dev/null and b/12.3 nodes communication/server differ diff --git a/13.mail smtp test and errors/client b/13.mail smtp test and errors/client new file mode 100755 index 0000000..423dc80 Binary files /dev/null and b/13.mail smtp test and errors/client differ diff --git a/13.mail smtp test and errors/daytimecli.c b/13.mail smtp test and errors/daytimecli.c new file mode 100644 index 0000000..811d59a --- /dev/null +++ b/13.mail smtp test and errors/daytimecli.c @@ -0,0 +1,94 @@ + + +#include "../basic.h" +#include + +void sigpipeaction (int signal){ + + int status, pid; + + fprintf(stderr, "Sigpipe catturato\n"); + + +} + + +int main(int argc, char **argv) { + + + struct sigaction sigpipestructure; + sigpipestructure.sa_handler = sigpipeaction; + sigpipestructure.sa_flags = 0; + + sigaction (SIGPIPE, &sigpipestructure, NULL); + + + + siginterrupt (SIGPIPE,1); + + + + + int sockfd; + struct sockaddr_in servaddr; + + if (argc != 3){ + printf("usage: daytimecli \n"); + exit(0); +} + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(atoi(argv[2])); /* server port */ + + if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){ + printf("inet_pton error for %s\n", argv[1]); + exit(0); +} + if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){ + printf("connect error\n"); + exit(0); + } + + struct sockaddr_in r_server_local_addr; + unsigned int r_server_local_addr_len = sizeof(r_server_local_addr); + + char * socket_buffer = (char *) malloc (r_server_local_addr_len) ; + int ridden; + + + + + + for (int i = 0; i < 100; i ++){ + + ridden = read (sockfd, socket_buffer,r_server_local_addr_len ); + if (ridden < 0){ + fprintf(stdout,"Errore durante la lettura\n"); + exit(-1); + } else { + fprintf(stdout,"Ho letto %d bytes\n",ridden); + } + } + + + close(sockfd); + + + memcpy (&r_server_local_addr,socket_buffer, r_server_local_addr_len); + + + char buff[INET_ADDRSTRLEN]; + short port; + + inet_ntop(AF_INET, &(r_server_local_addr.sin_addr), buff, INET_ADDRSTRLEN);// get ip + port = ntohs(r_server_local_addr.sin_port);// get port + + fprintf (stdout,"%s%c%hu\n",buff,':',port); + + + exit(0); +} diff --git a/13.mail smtp test and errors/daytimecli.c~ b/13.mail smtp test and errors/daytimecli.c~ new file mode 100644 index 0000000..239a866 --- /dev/null +++ b/13.mail smtp test and errors/daytimecli.c~ @@ -0,0 +1,31 @@ +/* Client che interroga un daytime server */ + +#include "../basic.h" + +int main(int argc, char **argv) { + int sockfd, n; + char recvline[MAXLINE + 1]; + struct sockaddr_in servaddr; + + if (argc != 3){ + printf("usage: daytimecli \n"); + exit(0); +} + if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_port = htons(atoi(argv[2])); /* server port */ + + if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0){ + printf("inet_pton error for %s\n", argv[1]); + exit(0); +} + if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0){ + printf("connect error\n"); + exit(0); + } + exit(0); +} diff --git a/13.mail smtp test and errors/daytimecli.o b/13.mail smtp test and errors/daytimecli.o new file mode 100644 index 0000000..3753eb4 Binary files /dev/null and b/13.mail smtp test and errors/daytimecli.o differ diff --git a/13.mail smtp test and errors/daytimesrv.c b/13.mail smtp test and errors/daytimesrv.c new file mode 100644 index 0000000..12c17fd --- /dev/null +++ b/13.mail smtp test and errors/daytimesrv.c @@ -0,0 +1,63 @@ + + +#include "../basic.h" +#include + +int main(int argc, char **argv) { + int listenfd, connfd, n; + struct sockaddr_in servaddr; + char buff[INET_ADDRSTRLEN]; + short port; + + if (argc != 2 ){ + printf("usage: daytimesrv \n"); + exit(0); +} + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */ + servaddr.sin_port = htons(atoi(argv[1])); /* server port */ + + if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){ + printf("bind error\n"); exit(0); +} + if( listen(listenfd, 5) < 0 ) + { printf("listen error\n"); + exit(0); + } + + struct sockaddr_in client_addr; + unsigned int client_addr_len = sizeof(client_addr); + + struct sockaddr_in server_local_addr; + unsigned int server_local_addr_len = sizeof(server_local_addr); + + char * socket_buffer = (char *) malloc (server_local_addr_len) ; + + + + for ( ; ; ) { + if( (connfd = accept(listenfd, (struct sockaddr *) &client_addr, &client_addr_len)) < 0) + { printf("accept error\n"); + exit(0); + } + + inet_ntop(AF_INET, &(client_addr.sin_addr), buff, INET_ADDRSTRLEN);// get client ip + port = ntohs(client_addr.sin_port);// get client port + + fprintf (stdout,"%s%c%hu\n",buff,':',port); + + + + getsockname (connfd, (struct sockaddr *) &server_local_addr, &server_local_addr_len); + memcpy (socket_buffer, &server_local_addr, server_local_addr_len); + write (connfd,socket_buffer, server_local_addr_len); + + + close(connfd); + } +} diff --git a/13.mail smtp test and errors/daytimesrv.c~ b/13.mail smtp test and errors/daytimesrv.c~ new file mode 100644 index 0000000..5a71bf1 --- /dev/null +++ b/13.mail smtp test and errors/daytimesrv.c~ @@ -0,0 +1,41 @@ +/* stampa l'ip del client */ + +#include "../basic.h" +#include + +int main(int argc, char **argv) { + int listenfd, connfd, n; + struct sockaddr_in servaddr; + char buff[MAXLINE]; + time_t ticks; + + if (argc != 2 ){ + printf("usage: daytimesrv \n"); + exit(0); +} + if( (listenfd = socket(AF_INET, SOCK_STREAM, 0)) < 0){ + printf("socket error\n"); + exit(0); +} + bzero(&servaddr, sizeof(servaddr)); + servaddr.sin_family = AF_INET; + servaddr.sin_addr.s_addr = htonl(INADDR_ANY); /* wildcard address */ + servaddr.sin_port = htons(atoi(argv[1])); /* server port */ + + if( (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) < 0){ + printf("bind error\n"); exit(0); +} + if( listen(listenfd, 5) < 0 ) + { printf("listen error\n"); + exit(0); +} + for ( ; ; ) { + if( (connfd = accept(listenfd, (struct sockaddr *) NULL, NULL)) < 0) + { printf("accept error\n"); exit(0);} else { + } + + n=read(connfd, buff, MAXLINE); + fprintf (stdout,%s\n,buff); + close(connfd); + } +} diff --git a/13.mail smtp test and errors/daytimesrv.o b/13.mail smtp test and errors/daytimesrv.o new file mode 100644 index 0000000..e160c2e Binary files /dev/null and b/13.mail smtp test and errors/daytimesrv.o differ diff --git a/13.mail smtp test and errors/makefile b/13.mail smtp test and errors/makefile new file mode 100644 index 0000000..16fdd6d --- /dev/null +++ b/13.mail smtp test and errors/makefile @@ -0,0 +1,9 @@ +all : server client +server : daytimesrv.o ../fun-corso-reti.o + gcc -o server daytimesrv.o ../fun-corso-reti.o +client : daytimecli.o ../fun-corso-reti.o + gcc -o client daytimecli.o ../fun-corso-reti.o +daytimesrv.o : daytimesrv.c ../basic.h + gcc -c -o daytimesrv.o daytimesrv.c +fun-corso-reti.o : ../fun-corso-reti.c ../basic.h + gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c diff --git a/13.mail smtp test and errors/makefile~ b/13.mail smtp test and errors/makefile~ new file mode 100644 index 0000000..ed76715 --- /dev/null +++ b/13.mail smtp test and errors/makefile~ @@ -0,0 +1,8 @@ +server : daytimesrv.o ../fun-corso-reti.o + gcc -o server daytimesrv.o ../fun-corso-reti.o +client : daytimecli.o ../fun-corso-reti.o + gcc -o client daytimecli.o ../fun-corso-reti.o +daytimesrv.o : daytimesrv.c ../basic.h + gcc -c -o daytimesrv.o daytimesrv.c +fun-corso-reti.o : ../fun-corso-reti.c ../basic.h + gcc -c -o ../fun-corso-reti.o ../fun-corso-reti.c diff --git a/13.mail smtp test and errors/readme b/13.mail smtp test and errors/readme new file mode 100644 index 0000000..e69de29 diff --git a/13.mail smtp test and errors/readme~ b/13.mail smtp test and errors/readme~ new file mode 100644 index 0000000..e69de29 diff --git a/13.mail smtp test and errors/server b/13.mail smtp test and errors/server new file mode 100755 index 0000000..65d3aab Binary files /dev/null and b/13.mail smtp test and errors/server differ