#include /* predefined types */ #include /* include unix standard library */ #include /* IP addresses conversion utiliites */ #include /* socket library */ #include /* include standard I/O library */ #include /* include error codes */ #include /* include erroro strings definitions */ #include int main(int argc, char **argv) { int sockfd, n, nwrite, nread; char recvline[1025] ; struct sockaddr_in servaddr; char sendbuff[4096],recvbuff[4096]; if (argc != 2) { fprintf(stderr,"usage: %s \n",argv[0]); exit (1); } if ( (sockfd = socket(AF_INET, /*TODO*/ , IPPROTO_UDP)) < 0) { fprintf(stderr,"socket error\n"); exit (1); } /*TODO*/ //Fill in servaddr struct if (fgets(sendbuff, 4096, stdin) == NULL) { return; /* if no input just return */ } else { /* else we have to write to socket */ nwrite = sendto(/*TODO: socket*/, /*TODO: buffer*/, strlen(sendbuff), 0, (struct sockaddr *) /*TODO: servaddr*/, sizeof(servaddr)); if (nwrite < 0) { /* on error stop */ printf("Errore in scrittura: %s", strerror(errno)); return; } } nread = recvfrom(/*TODO:socket*/, /*TODO:buffer */, strlen(sendbuff), 0, NULL, NULL); if (nread < 0) { /* error condition, stop client */ printf("Errore in lettura: %s\n", strerror(errno)); return; } recvbuff[nread] = 0; /* else read is ok, write on stdout */ if (fputs(recvbuff, stdout) == EOF) { perror("Errore in scrittura su terminale"); return; } exit(0); }