21 #if defined(_MSC_VER) && _MSC_VER < 1600
30 #define UV__INET_ADDRSTRLEN 16
31 #define UV__INET6_ADDRSTRLEN 46
47 return UV_EAFNOSUPPORT;
54 static const char fmt[] =
"%u.%u.%u.%u";
59 if (l <= 0 || (
size_t) l >=
size) {
76 struct {
int base,
len; } best, cur;
85 memset(words,
'\0',
sizeof words);
87 words[
i / 2] |= (
src[
i] << ((1 - (
i % 2)) << 3));
95 cur.base =
i, cur.len = 1;
100 if (best.base == -1 || cur.len > best.len)
106 if (cur.base != -1) {
107 if (best.base == -1 || cur.len > best.len)
110 if (best.base != -1 && best.len < 2)
119 if (best.base != -1 &&
i >= best.base &&
120 i < (best.base + best.len)) {
129 if (
i == 6 && best.base == 0 && (best.len == 6 ||
130 (best.len == 7 && words[7] != 0x0001) ||
131 (best.len == 5 && words[5] == 0xffff))) {
141 if (best.base != -1 && (best.base + best.len) ==
ARRAY_SIZE(words))
161 p = strchr(
src,
'%');
173 return UV_EAFNOSUPPORT;
180 static const char digits[] =
"0123456789";
181 int saw_digit, octets, ch;
182 unsigned char tmp[
sizeof(
struct in_addr)], *tp;
187 while ((ch = *
src++) !=
'\0') {
190 if ((pch = strchr(digits, ch)) !=
NULL) {
191 unsigned int nw = *tp * 10 + (pch - digits);
193 if (saw_digit && *tp == 0)
203 }
else if (ch ==
'.' && saw_digit) {
219 static const char xdigits_l[] =
"0123456789abcdef",
220 xdigits_u[] =
"0123456789ABCDEF";
221 unsigned char tmp[
sizeof(
struct in6_addr)], *tp, *endp, *colonp;
222 const char *xdigits, *curtok;
223 int ch, seen_xdigits;
227 endp = tp +
sizeof tmp;
236 while ((ch = *
src++) !=
'\0') {
239 if ((pch = strchr((xdigits = xdigits_l), ch)) ==
NULL)
240 pch = strchr((xdigits = xdigits_u), ch);
243 val |= (pch - xdigits);
244 if (++seen_xdigits > 4)
255 }
else if (*
src ==
'\0') {
260 *tp++ = (
unsigned char) (
val >> 8) & 0xff;
261 *tp++ = (
unsigned char)
val & 0xff;
266 if (ch ==
'.' && ((tp +
sizeof(
struct in_addr)) <= endp)) {
279 *tp++ = (
unsigned char) (
val >> 8) & 0xff;
280 *tp++ = (
unsigned char)
val & 0xff;
282 if (colonp !=
NULL) {
287 const int n = tp - colonp;
292 for (
i = 1;
i <=
n;
i++) {
293 endp[-
i] = colonp[
n -
i];
int uv_inet_ntop(int af, const void *src, char *dst, size_t size)
static int inet_pton6(const char *src, unsigned char *dst)
static int inet_ntop6(const unsigned char *src, char *dst, size_t size)
#define UV__INET6_ADDRSTRLEN
int uv_inet_pton(int af, const char *src, void *dst)
#define UV__INET_ADDRSTRLEN
static int inet_ntop4(const unsigned char *src, char *dst, size_t size)
static int inet_pton4(const char *src, unsigned char *dst)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
ssize_t uv__strscpy(char *d, const char *s, size_t n)