LIB_CURLX_CFILES = \
curlx/base64.c \
curlx/dynbuf.c \
+ curlx/inet_ntop.c \
curlx/inet_pton.c \
curlx/multibyte.c \
curlx/nonblock.c \
curlx/base64.h \
curlx/curlx.h \
curlx/dynbuf.h \
+ curlx/inet_ntop.h \
curlx/inet_pton.h \
curlx/multibyte.h \
curlx/nonblock.h \
idn.c \
if2ip.c \
imap.c \
- inet_ntop.c \
krb5.c \
ldap.c \
llist.c \
idn.h \
if2ip.h \
imap.h \
- inet_ntop.h \
llist.h \
macos.h \
memdebug.h \
#include "share.h"
#include "url.h"
#include "multiif.h"
-#include "inet_ntop.h"
#include "curl_threads.h"
#include "strdup.h"
#include "url.h" /* for Curl_safefree() */
#include "multiif.h"
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
-#include "inet_ntop.h"
#include "curlx/inet_pton.h"
#include "progress.h"
#include "curlx/warnless.h"
#include "url.h" /* for Curl_safefree() */
#include "multiif.h"
#include "sockaddr.h" /* required for Curl_sockaddr_storage */
-#include "inet_ntop.h"
+#include "curlx/inet_ntop.h"
#include "curlx/inet_pton.h"
#include "vtls/vtls.h" /* for vtsl cfilters */
#include "progress.h"
return NULL;
}
-/* retrieves ip address and port from a sockaddr structure.
- note it calls Curl_inet_ntop which sets errno on fail, not SOCKERRNO. */
+/* retrieves ip address and port from a sockaddr structure. note it calls
+ curlx_inet_ntop which sets errno on fail, not SOCKERRNO. */
bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
char *addr, int *port)
{
switch(sa->sa_family) {
case AF_INET:
si = (struct sockaddr_in *)(void *) sa;
- if(Curl_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) {
+ if(curlx_inet_ntop(sa->sa_family, &si->sin_addr, addr, MAX_IPADR_LEN)) {
unsigned short us_port = ntohs(si->sin_port);
*port = us_port;
return TRUE;
#ifdef USE_IPV6
case AF_INET6:
si6 = (struct sockaddr_in6 *)(void *) sa;
- if(Curl_inet_ntop(sa->sa_family, &si6->sin6_addr, addr, MAX_IPADR_LEN)) {
+ if(curlx_inet_ntop(sa->sa_family, &si6->sin6_addr, addr,
+ MAX_IPADR_LEN)) {
unsigned short us_port = ntohs(si6->sin6_port);
*port = us_port;
return TRUE;
#include "inet_pton.h"
/* for curlx_inet_pton */
+#include "inet_ntop.h"
+/* for curlx_inet_ntop */
+
#endif /* HEADER_CURL_CURLX_H */
* Original code by Paul Vixie. "curlified" by Gisle Vanem.
*/
-#include "curl_setup.h"
+#include "../curl_setup.h"
#ifndef HAVE_INET_NTOP
#endif
#include "inet_ntop.h"
-#include "curl_printf.h"
#define IN6ADDRSZ 16
/* #define INADDRSZ 4 */
DEBUGASSERT(size >= 16);
- tmp[0] = '\0';
- (void)msnprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
+ /* this sprintf() does not overflow the buffer. Avoids snprintf to work more
+ widely. Avoids the msnprintf family to work as a curlx function. */
+ (void)(sprintf)(tmp, "%d.%d.%d.%d",
((int)((unsigned char)src[0])) & 0xff,
((int)((unsigned char)src[1])) & 0xff,
((int)((unsigned char)src[2])) & 0xff,
tp += strlen(tp);
break;
}
- tp += msnprintf(tp, 5, "%x", words[i]);
+ else {
+ /* Lower-case digits. Can't use the set from mprintf.c since this
+ needs to work as a curlx function */
+ static const unsigned char ldigits[] = "0123456789abcdef";
+
+ unsigned int w = words[i];
+ /* output lowercase 16bit hex number but ignore leading zeroes */
+ if(w & 0xf000)
+ *tp++ = ldigits[(w & 0xf000) >> 12];
+ if(w & 0xff00)
+ *tp++ = ldigits[(w & 0x0f00) >> 8];
+ if(w & 0xfff0)
+ *tp++ = ldigits[(w & 0x00f0) >> 4];
+ *tp++ = ldigits[(w & 0x000f)];
+ }
}
/* Was it a trailing run of 0x00's?
* code. This is to avoid losing the actual last Winsock error. When this
* function returns NULL, check errno not SOCKERRNO.
*/
-char *Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
+char *curlx_inet_ntop(int af, const void *src, char *buf, size_t size)
{
switch(af) {
case AF_INET:
*
***************************************************************************/
-#include "curl_setup.h"
+#include "../curl_setup.h"
-char *Curl_inet_ntop(int af, const void *addr, char *buf, size_t size);
+char *curlx_inet_ntop(int af, const void *addr, char *buf, size_t size);
#ifdef HAVE_INET_NTOP
#ifdef HAVE_NETINET_IN_H
#include <arpa/inet.h>
#endif
#ifdef __AMIGA__
-#define Curl_inet_ntop(af,addr,buf,size) \
+#define curlx_inet_ntop(af,addr,buf,size) \
(char *)inet_ntop(af, CURL_UNCONST(addr), (unsigned char *)buf, \
(curl_socklen_t)(size))
#else
-#define Curl_inet_ntop(af,addr,buf,size) \
+#define curlx_inet_ntop(af,addr,buf,size) \
inet_ntop(af, addr, buf, (curl_socklen_t)(size))
#endif
#endif
#include "cf-socket.h"
#include "connect.h"
#include "strerror.h"
-#include "inet_ntop.h"
+#include "curlx/inet_ntop.h"
#include "curlx/inet_pton.h"
#include "select.h"
#include "parsedate.h" /* for the week day and month names */
switch(sa->sa_family) {
#ifdef USE_IPV6
case AF_INET6:
- r = Curl_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf));
+ r = curlx_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf));
break;
#endif
default:
- r = Curl_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf));
+ r = curlx_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf));
break;
}
if(!r) {
#include "rand.h"
#include "share.h"
#include "url.h"
-#include "inet_ntop.h"
+#include "curlx/inet_ntop.h"
#include "curlx/inet_pton.h"
#include "multiif.h"
#include "doh.h"
case AF_INET: {
const struct sockaddr_in *sa4 = (const void *)ai->ai_addr;
const struct in_addr *ipaddr4 = &sa4->sin_addr;
- (void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
+ (void)curlx_inet_ntop(ai->ai_family, (const void *)ipaddr4, buf, bufsize);
break;
}
#ifdef USE_IPV6
case AF_INET6: {
const struct sockaddr_in6 *sa6 = (const void *)ai->ai_addr;
const struct in6_addr *ipaddr6 = &sa6->sin6_addr;
- (void)Curl_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
+ (void)curlx_inet_ntop(ai->ai_family, (const void *)ipaddr6, buf, bufsize);
break;
}
#endif
# include <inet.h>
#endif
-#include "inet_ntop.h"
+#include "curlx/inet_ntop.h"
#include "strcase.h"
#include "if2ip.h"
/* The last 3 #include files should be in this order */
addr =
&((struct sockaddr_in *)(void *)iface->ifa_addr)->sin_addr;
res = IF2IP_FOUND;
- ip = Curl_inet_ntop(af, addr, ipstr, sizeof(ipstr));
+ ip = curlx_inet_ntop(af, addr, ipstr, sizeof(ipstr));
msnprintf(buf, buf_size, "%s%s", ip, scope);
break;
}
s = (struct sockaddr_in *)(void *)&req.ifr_addr;
memcpy(&in, &s->sin_addr, sizeof(in));
- r = Curl_inet_ntop(s->sin_family, &in, buf, buf_size);
+ r = curlx_inet_ntop(s->sin_family, &in, buf, buf_size);
sclose(dummy);
if(!r)
#include "imap.h"
#include "url.h"
#include "connect.h"
-#include "inet_ntop.h"
#include "http_ntlm.h"
#include "curl_rtmp.h"
#include "gopher.h"
#include "escape.h"
#include "curl_ctype.h"
#include "curlx/inet_pton.h"
-#include "inet_ntop.h"
+#include "curlx/inet_ntop.h"
#include "strdup.h"
#include "idn.h"
#include "curlx/strparse.h"
hostname[hlen] = 0; /* end the address there */
if(1 != curlx_inet_pton(AF_INET6, hostname, dest))
return CURLUE_BAD_IPV6;
- if(Curl_inet_ntop(AF_INET6, dest, hostname, hlen)) {
+ if(curlx_inet_ntop(AF_INET6, dest, hostname, hlen)) {
hlen = strlen(hostname); /* might be shorter now */
hostname[hlen + 1] = 0;
}
#include "../vtls/vtls.h"
#include "../cfilters.h"
#include "../connect.h"
-#include "../inet_ntop.h"
#include "../parsedate.h" /* for the week day and month names */
#include "../sockaddr.h" /* required for Curl_sockaddr_storage */
#include "../curlx/strparse.h"
#include "../vtls/vtls.h"
#include "../cfilters.h"
#include "../connect.h"
-#include "../inet_ntop.h"
#include "../parsedate.h" /* for the week day and month names */
#include "../sockaddr.h" /* required for Curl_sockaddr_storage */
#include "../multiif.h"