-//
-// $Id: convert.cc,v 1.3 2000/06/20 09:43:01 voeckler Exp $
-//
+/*
+ * Copyright (C) 1996-2018 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: convert.cc,v 1.3 2000/06/20 09:43:01 voeckler Exp $";
-
const char*
my_inet_ntoa( const struct in_addr& a, HostAddress output )
// purpose: thread-safely convert IPv4 address -> ASCII representation
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;
}
// 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;
}
// 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 )
}
return 0;
}
+