X-Git-Url: https://gapil.gnulinux.it/gitweb/?a=blobdiff_plain;f=sources%2FTCP_echod_first.c;h=bfe826a8c76d7ad61a05ac032390c32cb456d5b4;hb=5af25bf51719d4f435f57a8d7df64f286ad64996;hp=55fd5c6981842e28f47d614c293d07c45170d7ae;hpb=3e8003adb1396080659ef5d34896eb2f573be6cd;p=gapil.git diff --git a/sources/TCP_echod_first.c b/sources/TCP_echod_first.c index 55fd5c6..bfe826a 100644 --- a/sources/TCP_echod_first.c +++ b/sources/TCP_echod_first.c @@ -1,4 +1,4 @@ -/* TCP_echod.c +/* TCP_echod_first.c * * Copyright (C) 2001-2003 Simone Piccardi * @@ -26,7 +26,7 @@ * * Usage: echod -h give all info * - * $Id: TCP_echod_first.c,v 1.1 2003/05/06 14:05:12 piccardi Exp $ + * $Id: TCP_echod_first.c,v 1.3 2003/12/25 17:31:09 piccardi Exp $ * ****************************************************************/ /* @@ -40,12 +40,16 @@ #include #include /* syslog system functions */ #include /* signal functions */ +#include /* error code */ +#include /* error strings */ +#include + #include "Gapil.h" #define BACKLOG 10 #define MAXLINE 256 -int demonize = 1; /* daemon use option */ -int debugging = 0; /* debug info printing option */ +int demonize = 1; /* daemon use option: default is daemon */ +int debugging = 0; /* debug info printing option: default is no debug */ /* Subroutines declaration */ void usage(void); void ServEcho(int sockfd); @@ -136,6 +140,7 @@ int main(int argc, char *argv[]) /* handle echo to client */ while (1) { /* accept connection */ + len = sizeof(cli_add); if ( (conn_fd = accept(list_fd, NULL, NULL)) < 0) { PrintErr("accept error"); exit(1); @@ -179,14 +184,8 @@ void ServEcho(int sockfd) { /* main loop, reading 0 char means client close connection */ while ( (nread = read(sockfd, buffer, MAXLINE)) != 0) { nwrite = FullWrite(sockfd, buffer, nread); - if (debugging) { - buffer[nread] = 0; - snprintf(debug, MAXLINE+20, "Letti %d byte, %s", nread, buffer); - if (demonize) { /* go daemon */ - syslog(LOG_DEBUG, debug); - } else { - printf("%s", debug); - } + if (nwrite) { + PrintErr("write error"); } } return; @@ -195,8 +194,8 @@ void ServEcho(int sockfd) { * routine to print error on stout or syslog */ void PrintErr(char * error) { - if (demonize) { /* go daemon */ - syslog(LOG_ERR, error); + if (demonize) { /* daemon mode */ + syslog(LOG_ERR, "%s: %m", error); /* log string and error message */ } else { perror(error); }