X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FUDP_echo.c;h=a3bbd9b8c4fac087caacace36f33ed3fcda45652;hp=b14e1f6cbb884fa711c07aae1ce019ebe770fe64;hb=2a09a578f80e369673bd5ac24179c021e903358b;hpb=caa33ab45032ea8c9917a9d2914ff59266b30ad2 diff --git a/sources/UDP_echo.c b/sources/UDP_echo.c index b14e1f6..a3bbd9b 100644 --- a/sources/UDP_echo.c +++ b/sources/UDP_echo.c @@ -26,7 +26,7 @@ * * Usage: echo -h give all info's * - * $Id: UDP_echo.c,v 1.2 2004/05/02 13:10:32 piccardi Exp $ + * $Id: UDP_echo.c,v 1.3 2004/06/02 16:31:50 piccardi Exp $ * ****************************************************************/ /* @@ -98,8 +98,9 @@ int main(int argc, char *argv[]) perror("Address creation error"); return 1; } + connect(sock, &serv_add, sizeof(*serv_add)); /* do read/write operations */ - ClientEcho(stdin, sock, &serv_add); + ClientEcho(stdin, sock); /* normal exit */ return 0; } @@ -116,7 +117,7 @@ void usage(void) { exit(1); } -void ClientEcho(FILE * filein, int socket, struct sockaddr_in * serv_addr) +void ClientEcho(FILE * filein, int socket) { char sendbuff[MAXLINE+1], recvbuff[MAXLINE+1]; int nread, nwrite; @@ -125,14 +126,13 @@ void ClientEcho(FILE * filein, int socket, struct sockaddr_in * serv_addr) if (fgets(sendbuff, MAXLINE, filein) == NULL) { return; /* if no input just return */ } else { /* else we have to write to socket */ - nwrite = sendto(socket, sendbuff, strlen(sendbuff), 0, - (struct sockaddr *) serv_addr, sizeof(*serv_addr)); + nwrite = write(socket, sendbuff, strlen(sendbuff)); if (nwrite < 0) { /* on error stop */ printf("Errore in scrittura: %s", strerror(errno)); return; } } - nread = recvfrom(socket, recvbuff, strlen(sendbuff), 0, NULL, NULL); + nread = read(socket, recvbuff, strlen(sendbuff)); if (nread < 0) { /* error condition, stop client */ printf("Errore in lettura: %s\n", strerror(errno)); return;