]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - compat/getnameinfo.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / compat / getnameinfo.cc
index dd17c5f521a354529752a9ac1d13e8f48a05cf1e..b0bb7afd14a204cbac2353ee79841531dc5e98d0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -13,7 +13,7 @@
  * Update/Maintenance History:
  *
  *    16-Aug-2007 : Copied from fetchmail 6.3.8
- *                      - added protection around libray headers
+ *                      - added protection around library headers
  *                      - added use of alternative name xgetnameinfo
  *                        to split from any OS-provided.
  *
@@ -22,6 +22,8 @@
  *                      - use xinet_ntop instead of inet_ntop
  *                      - use SQUIDHOSTNAMELEN instead of MAXHOSTNAMELEN
  *
+ *    13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
  *  Original License and code follows.
  */
 #include "squid.h"
@@ -149,14 +151,7 @@ static int ip6_sa2str __P((const struct sockaddr_in6 *, char *, size_t, int));
 #endif
 
 int
-xgetnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
-const struct sockaddr *sa;
-socklen_t salen;
-char *host;
-size_t hostlen;
-char *serv;
-size_t servlen;
-int flags;
+xgetnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags)
 {
     const struct afd *afd;
     struct servent *sp;
@@ -208,12 +203,12 @@ found:
         if (sp) {
             if (strlen(sp->s_name) + 1 > servlen)
                 return EAI_OVERFLOW;
-            strncpy(serv, sp->s_name, servlen);
+            xstrncpy(serv, sp->s_name, servlen);
         } else {
             snprintf(numserv, sizeof(numserv), "%u", ntohs(port));
             if (strlen(numserv) + 1 > servlen)
                 return EAI_OVERFLOW;
-            strncpy(serv, numserv, servlen);
+            xstrncpy(serv, numserv, servlen);
         }
     }
 
@@ -306,7 +301,7 @@ found:
 #endif
                 return EAI_OVERFLOW;
             }
-            strncpy(host, hp->h_name, hostlen);
+            xstrncpy(host, hp->h_name, hostlen);
 #if USE_GETIPNODEBY
             freehostent(hp);
 #endif
@@ -356,7 +351,7 @@ int flags;
     numaddrlen = strlen(numaddr);
     if (numaddrlen + 1 > hostlen) /* don't forget terminator */
         return EAI_OVERFLOW;
-    strncpy(host, numaddr, hostlen);
+    xstrncpy(host, numaddr, hostlen);
 
     if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
         char zonebuf[SQUIDHOSTNAMELEN];