*
* 06-Oct-2007 : Various fixes to allow the build on MinGW
*
+ * 13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
* Original License and code follows.
*/
#include "squid.h"
dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) {
struct addrinfo *ret;
- ret = malloc (sizeof (struct addrinfo));
+ ret = (struct addrinfo *)malloc(sizeof (struct addrinfo));
if (ret == NULL)
return NULL;
memcpy (ret, info, sizeof (struct addrinfo));
- ret->ai_addr = malloc (addrlen);
+ ret->ai_addr = (struct sockaddr*)malloc(addrlen);
if (ret->ai_addr == NULL) {
free (ret);
return NULL;
sin.sin_family = result.ai_family;
sin.sin_port = htons (port);
- if (inet_pton(result.ai_family, nodename, &sin.sin_addr))
+ if (inet_pton(result.ai_family, nodename, &sin.sin_addr) != 1)
return EAI_NONAME;
sin.sin_addr.s_addr = inet_addr (nodename);
/* Duplicate result and addr and return */
}
if (hints->ai_flags & AI_CANONNAME) {
- sai->ai_canonname = malloc (strlen (hp->h_name) + 1);
+ sai->ai_canonname = (char *)malloc(strlen(hp->h_name) + 1);
if (sai->ai_canonname == NULL) {
xfreeaddrinfo (sai);
return EAI_MEMORY;
* - 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"
#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;
*
* 04-Nov-2010: drop SPRINTF casting macro
*
+ * 13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
* Original License and code follows.
*/
* Paul Vixie, 1996.
*/
const char *
-xinet_ntop(af, src, dst, size)
-int af;
-const void *src;
-char *dst;
-size_t size;
+xinet_ntop(int af, const void *src, char *dst, size_t size)
{
switch (af) {
case AF_INET:
- return (inet_ntop4(src, dst, size));
+ return (inet_ntop4((const u_char*)src, dst, size));
case AF_INET6:
- return (inet_ntop6(src, dst, size));
+ return (inet_ntop6((const u_char*)src, dst, size));
default:
errno = EAFNOSUPPORT;
return (NULL);
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop4(src, dst, size)
-const u_char *src;
-char *dst;
-size_t size;
+inet_ntop4(const u_char *src, char *dst, size_t size)
{
static const char fmt[] = "%u.%u.%u.%u";
- char tmp[sizeof "255.255.255.255"];
+ char tmp[sizeof("255.255.255.255")+1];
- if (snprintf(tmp, min(sizeof("255.255.255.255"),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
+ if ((size_t)snprintf(tmp, min(sizeof(tmp),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
errno = ENOSPC;
return (NULL);
}
* Paul Vixie, 1996.
*/
static const char *
-inet_ntop6(src, dst, size)
-const u_char *src;
-char *dst;
-size_t size;
+inet_ntop6(const u_char *src, char *dst, size_t size)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
*
* 28-Oct-2007: drop some dead code. now tested working without.
*
+ * 13-Jan-2015 : Various fixed for C++ and MinGW native build
+ *
* Original License and code follows.
*/
* Paul Vixie, 1996.
*/
int
-xinet_pton(af, src, dst)
-int af;
-const char *src;
-void *dst;
+xinet_pton(int af, const char *src, void *dst)
{
switch (af) {
case AF_INET:
- return (inet_pton4(src, dst));
+ return (inet_pton4(src, (u_char*)dst));
case AF_INET6:
- return (inet_pton6(src, dst));
+ return (inet_pton6(src, (u_char*)dst));
default:
errno = EAFNOSUPPORT;
return (-1);
* Paul Vixie, 1996.
*/
static int
-inet_pton4(src, dst)
-const char *src;
-u_char *dst;
+inet_pton4(const char *src, u_char *dst)
{
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
const char *pch;
if ((pch = strchr(digits, ch)) != NULL) {
- u_int new = *tp * 10 + (pch - digits);
+ u_int nw = *tp * 10 + (pch - digits);
if (saw_digit && *tp == 0)
return (0);
- if (new > 255)
+ if (nw > 255)
return (0);
- *tp = new;
+ *tp = nw;
if (!saw_digit) {
if (++octets > 4)
return (0);
* Paul Vixie, 1996.
*/
static int
-inet_pton6(src, dst)
-const char *src;
-u_char *dst;
+inet_pton6(const char *src, u_char *dst)
{
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";