]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - tools/purge/convert.cc
SourceFormat Enforcement
[thirdparty/squid.git] / tools / purge / convert.cc
index 189d896b917a120364dfd922533cf98c01f59c64..a3aa680f75fbb5ed0734497da720eed3a9a409cd 100644 (file)
@@ -1,6 +1,11 @@
-//
-// $Id$
-//
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 // Author:  Jens-S. V?ckler <voeckler@rvs.uni-hannover.de>
 //
 // File:    convert.cc
 // Revision 1.1  1998/08/13 21:38:04  voeckler
 // Initial revision
 //
-//
-#if defined(__GNUC__) || defined(__GNUG__)
-#pragma implementation
-#endif
 
+#include "squid.h"
 #include "convert.hh"
-#include <string.h>
+
+#include <cstdlib>
+#include <cstring>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
-#include <stdlib.h>
-#include <stdio.h>
 
 #ifndef SA
 #define SA struct sockaddr
 #endif
 
-static const char* RCS_ID =
-    "$Id$";
-
 const char*
 my_inet_ntoa( const struct in_addr& a, HostAddress output )
 // purpose: thread-safely convert IPv4 address -> ASCII representation
@@ -77,7 +76,7 @@ my_inet_ntoa( const struct in_addr& a, HostAddress output )
         unsigned char s[sizeof(a.s_addr)];
         memcpy( s, &a.s_addr, sizeof(a.s_addr) );
 
-        sprintf( output, "%d.%d.%d.%d", s[0], s[1], s[2], s[3] );
+        snprintf(output, sizeof(HostAddress), "%d.%d.%d.%d", s[0], s[1], s[2], s[3] );
     }
     return output;
 }
@@ -90,8 +89,8 @@ my_sock_ntoa( const struct sockaddr_in& a, SockAddress buffer )
 // returns: pointer to buffer
 {
     HostAddress host;
-    sprintf( buffer, "%s:%u",
-             my_inet_ntoa(a.sin_addr,host), ntohs(a.sin_port) );
+    snprintf( buffer, sizeof(SockAddress), "%s:%u",
+              my_inet_ntoa(a.sin_addr,host), ntohs(a.sin_port) );
     return buffer;
 }
 
@@ -107,7 +106,7 @@ my_sock_fd2a( int fd, SockAddress buffer, bool peer )
 //          Refer to errno in case of error (usually unconnected fd...)
 {
     struct sockaddr_in socket;
-    SOCKLEN len = sizeof(socket);
+    socklen_t len = sizeof(socket);
 
     if ( (peer ? getpeername( fd, (SA*) &socket, &len ) :
             getsockname( fd, (SA*) &socket, &len )) == -1 )
@@ -157,3 +156,4 @@ convertPortname( const char* port, unsigned short& dst )
     }
     return 0;
 }
+