-/* TCP_echod.c
+/* TCP_echod_first.c
*
* Copyright (C) 2001-2003 Simone Piccardi
*
*
* 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.2 2003/07/27 23:41:04 piccardi Exp $
*
****************************************************************/
/*
#include <time.h>
#include <syslog.h> /* syslog system functions */
#include <signal.h> /* signal functions */
+#include <errno.h> /* error code */
+#include <string.h> /* error strings */
#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);
/* 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;
* 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);
}