[libmicrohttpd] tsearch updates from NetBSD source
Hi, is this okay for merge? I took it from our (NetBSD) tree, compared to what libmicrohttpd contains. diff --git a/src/lib/tsearch.c b/src/lib/tsearch.c index 78f37608..2d374cad 100644 --- a/src/lib/tsearch.c +++ b/src/lib/tsearch.c @@ -12,6 +12,9 @@ #include "tsearch.h" #include +#ifndef __UNCONST +#define __UNCONST(a)((void *)(unsigned long)(const void *)(a)) +#endif typedef struct node { @@ -21,7 +24,7 @@ typedef struct node } node_t; -/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ +/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /* find or insert datum into search tree */ void * tsearch (const void *vkey,/* key to be located */ @@ -47,10 +50,10 @@ tsearch (const void *vkey,/* key to be located */ } q = malloc (sizeof(node_t));/* T5: key not found */ - if (q) + if (q != 0) { /* make new node */ *rootp = q; /* link new node to old */ -q->key = vkey; /* initialize new node */ +q->key = __UNCONST(vkey); /* initialize new node */ q->llink = q->rlink = NULL; } return q; signature.asc Description: PGP signature
Re: [libmicrohttpd] tsearch updates from NetBSD source
This could cause a problem on platforms where size of unsigned long is smaller than size of pointer. Windows x64 is obvious example. -- Best Wishes,Evgeny Grin 27.11.2019, 14:47, "ng0" :Hi,is this okay for merge? I took it from our (NetBSD) tree,compared to what libmicrohttpd contains.diff --git a/src/lib/tsearch.c b/src/lib/tsearch.cindex 78f37608..2d374cad 100644--- a/src/lib/tsearch.c+++ b/src/lib/tsearch.c@@ -12,6 +12,9 @@ #include "tsearch.h" #include +#ifndef __UNCONST+#define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))+#endif typedef struct node {@@ -21,7 +24,7 @@ typedef struct node } node_t;-/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */+/* $NetBSD: tsearch.c,v 1.7 2012/06/25 22:32:45 abs Exp $ */ /* find or insert datum into search tree */ void * tsearch (const void *vkey, /* key to be located */@@ -47,10 +50,10 @@ tsearch (const void *vkey, /* key to be located */ } q = malloc (sizeof(node_t)); /* T5: key not found */- if (q)+ if (q != 0) { /* make new node */ *rootp = q; /* link new node to old */- q->key = vkey; /* initialize new node */+ q->key = __UNCONST(vkey); /* initialize new node */ q->llink = q->rlink = NULL; } return q;
Re: [libmicrohttpd] tsearch updates from NetBSD source
Okay, thanks. What about the != 0 addition, could this be problematic as well?
Re: [libmicrohttpd] tsearch updates from NetBSD source
Let's stay with current version. '!= 0' will not add any improvement.Unpatched version gives maintenance simplicity. -- Best Wishes,Evgeny Grin 27.11.2019, 16:53, "ng0" :Okay, thanks.What about the != 0 addition, could this be problematic as well?
Re: [libmicrohttpd] tsearch updates from NetBSD source
Okay. Thanks for reviewing the patch.
[libmicrohttpd] How to get the client IP as IPv4 in dual stack mode?
Hi. I have a function which checks if the sa_family is AF_INET or AF_INET6 and formats the client address as IPv4 (e.g. 127.0.0.1) or IPv6 (e.g. ::1) into a string. However, when I enable the dual stack in MHD, it always returns AF_INET6 in sa_family even when passing -4 as parameter in curl. I'm using MHD_get_connection_info(..., MHD_CONNECTION_INFO_CLIENT_ADDRESS)->client_addr to get the client address and the formatting function is in attachment below. Is there any flag to force MHD to return AF_INET when the client connects explicitly as IPv4? Thank you! // Attachment: function to format the client address as IPv4 or IPv6 int get_ip(const void *socket, char *buf, size_t size) { const struct sockaddr *sa; if (!socket || !buf || (ssize_t) size < 0) return EINVAL; sa = socket; switch (sa->sa_family) { case AF_INET: if (!inet_ntop(AF_INET, &(((struct sockaddr_in *) sa)->sin_addr), buf, size)) return errno; break; case AF_INET6: if (!inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) sa)->sin6_addr), buf, size)) return errno; break; default: return EINVAL; } return 0; } -- Silvio Clécio