From dcb0aee6871c25a9dfc1be3c663c3cbbf5efec66 Mon Sep 17 00:00:00 2001 From: "fredrik@DOLDA2000.COM" Date: Fri, 29 Apr 2005 00:45:59 +0000 Subject: [PATCH] Better error handling code. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/icmp-dn@215 959494ce-11ee-0310-bf91-de5d638817bd --- icmpdnd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/icmpdnd.c b/icmpdnd.c index 2b59175..3cd6f5f 100644 --- a/icmpdnd.c +++ b/icmpdnd.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,7 @@ int main(int argc, char **argv) struct reqhdr req; struct rephdr rep; struct iphdr iphdr; + time_t curtime, lasterr; daemonize = 1; ttl = 3600; @@ -168,15 +170,23 @@ int main(int argc, char **argv) openlog("icmpdnd", LOG_PID, LOG_DAEMON); alive = 1; + lasterr = 0; while(alive) { namelen = sizeof(name); ret = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&name, &namelen); + + curtime = time(NULL); if(ret < 0) { if(errno == EINTR) continue; syslog(LOG_ERR, "error in receiving datagram: %m"); - exit(1); + if(lasterr == curtime) { + syslog(LOG_CRIT, "exiting due to repeated errors"); + exit(1); + } + lasterr = curtime; } + if(ret < sizeof(iphdr) + sizeof(req)) continue; memcpy(&iphdr, buf, sizeof(iphdr)); -- 2.11.0