#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "uv.h"
#include "uv-common.h"
Go to the source code of this file.
|
static int | inet_ntop4 (const unsigned char *src, char *dst, size_t size) |
|
static int | inet_ntop6 (const unsigned char *src, char *dst, size_t size) |
|
static int | inet_pton4 (const char *src, unsigned char *dst) |
|
static int | inet_pton6 (const char *src, unsigned char *dst) |
|
int | uv_inet_ntop (int af, const void *src, char *dst, size_t size) |
|
int | uv_inet_pton (int af, const char *src, void *dst) |
|
◆ UV__INET6_ADDRSTRLEN
#define UV__INET6_ADDRSTRLEN 46 |
◆ UV__INET_ADDRSTRLEN
#define UV__INET_ADDRSTRLEN 16 |
◆ inet_ntop4()
◆ inet_ntop6()
Definition at line 67 of file inet.c.
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))
#define UV__INET6_ADDRSTRLEN
static int inet_ntop4(const unsigned char *src, char *dst, size_t size)
return memset(p, 0, total)
References ARRAY_SIZE, dst, err, i, inet_ntop4(), int, len, memset(), sprintf, src, autogen_x86imm::tmp, UV__INET6_ADDRSTRLEN, and uv__strscpy().
Referenced by uv_inet_ntop().
◆ inet_pton4()
Definition at line 179 of file inet.c.
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) {
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
References dst, memcpy(), NULL, src, and autogen_x86imm::tmp.
Referenced by inet_pton6(), and uv_inet_pton().
◆ inet_pton6()
Definition at line 218 of file inet.c.
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];
static int inet_pton4(const char *src, unsigned char *dst)
References dst, err, i, inet_pton4(), memcpy(), memset(), n, NULL, src, autogen_x86imm::tmp, and val.
Referenced by uv_inet_pton().
◆ uv_inet_ntop()
◆ uv_inet_pton()
int uv_inet_pton |
( |
int |
af, |
|
|
const char * |
src, |
|
|
void * |
dst |
|
) |
| |
Definition at line 150 of file inet.c.
161 p = strchr(
src,
'%');
173 return UV_EAFNOSUPPORT;
static int inet_pton6(const char *src, unsigned char *dst)
References AF_INET, AF_INET6, dst, inet_pton4(), inet_pton6(), len, memcpy(), NULL, p, s, src, autogen_x86imm::tmp, and UV__INET6_ADDRSTRLEN.
Referenced by uv__udp_set_membership4(), uv__udp_set_source_membership4(), uv_ip4_addr(), and uv_ip6_addr().