lists.arthurdejong.org
RSS feed

cvsd commit: MODIFIED: . ...

[Date Prev][Date Next] [Thread Prev][Thread Next]

cvsd commit: MODIFIED: . ...



User: arthur
Date: 11/01/29 22:20:02

Modified:    . cvsd.c
Log:
log address and port with bind() failures and only do getnameinfo once for 
every address/port to bind


Revision  Changes    Path
1.124     +13 -21    cvsd/cvsd.c

Index: cvsd.c
===================================================================
RCS file: /home/arthur/devel/repos/cvsd/cvsd.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -b -r1.123 -r1.124
--- cvsd.c      23 Dec 2010 16:44:51 -0000      1.123
+++ cvsd.c      29 Jan 2011 21:20:02 -0000      1.124
@@ -15,7 +15,7 @@
    Copyright (C) 1999 Chris Black.
    Copyright (C) 2000 Philippe Kehl.
    Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-                 2010 Arthur de Jong.
+                 2010, 2011 Arthur de Jong.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -124,7 +124,7 @@
 {
   fprintf(fp,"%s\n",PACKAGE_STRING);
   fprintf(fp,"Written by Chris Black, Philippe Kehl and Arthur de Jong.\n\n");
-  fprintf(fp,"Copyright (C) 1999-2010 Chris Black, Philippe Kehl and Arthur de 
Jong.\n"
+  fprintf(fp,"Copyright (C) 1999-2011 Chris Black, Philippe Kehl and Arthur de 
Jong.\n"
              "This is free software; see the source for copying conditions.  
There is NO\n"
              "warranty; not even for MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.\n");
 }
@@ -379,8 +379,9 @@
   for (addr=addrs->addrs;addr!=NULL;addr=addr->ai_next)
   {
 
+    /* translate address to name */
     switch (i=getnameinfo(addr->ai_addr,addr->ai_addrlen,
-                          host,80,serv,40,
+                          host,sizeof(host),serv,sizeof(serv),
                           NI_NUMERICHOST|NI_NUMERICSERV)<0)
     {
       case 0:
@@ -388,10 +389,14 @@
                       addr->ai_family,addr->ai_socktype,addr->ai_protocol);
         break;
       case EAI_SYSTEM:
-        log_log(LOG_DEBUG,"debug: getnameinfo() failed: %s",strerror(errno));
+        log_log(LOG_DEBUG,"debug: getnameinfo() failed (ignored): 
%s",strerror(errno));
+        strcpy(host,"?");
+        strcpy(serv,"?");
         break;
       default:
-        log_log(LOG_DEBUG,"debug: getnameinfo() failed: %s",gai_strerror(i));
+        log_log(LOG_DEBUG,"debug: getnameinfo() failed (ignored): 
%s",gai_strerror(i));
+        strcpy(host,"?");
+        strcpy(serv,"?");
         break;
     }
 
@@ -470,9 +475,9 @@
     /* bind the socket to the specified port */
     if (bind(sock,addr->ai_addr,addr->ai_addrlen)<0)
     {
-      log_log(LOG_ERR,"bind() failed: %s",strerror(errno));
+      log_log(LOG_ERR,"bind(%s,%s) failed: %s",host,serv,strerror(errno));
       if (close(sock))
-        log_log(LOG_WARNING,"problem closing socket (ignored): 
%s",strerror(errno));
+        log_log(LOG_WARNING,"problem closing socket: %s",strerror(errno));
       exit(1);
     }
 
@@ -496,20 +501,7 @@
     cvsd_serversockets[cvsd_serversocketnum++]=sock;
 
     /* log stuff */
-    switch (i=getnameinfo(addr->ai_addr,addr->ai_addrlen,
-                          host,80,serv,40,
-                          NI_NUMERICHOST|NI_NUMERICSERV)<0)
-    {
-      case 0:
         log_log(LOG_INFO,"listening on %s %s",host,serv);
-        break;
-      case EAI_SYSTEM:
-        log_log(LOG_ERR,"getnameinfo() failed (ignored): %s",strerror(errno));
-        break;
-      default:
-        log_log(LOG_ERR,"getnameinfo() failed (ignored): %s",gai_strerror(i));
-        break;
-    }
 
     count++;
   } /* next addr */


-- 
To unsubscribe send an email to
cvsd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/cvsd-commits