nxt_sockaddr.c (4:76c63e9b6322) nxt_sockaddr.c (10:a8e68ed06863)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10#if (NXT_INET6)
11static u_char *nxt_inet6_ntop(u_char *addr, u_char *buf, u_char *end);
12#endif
13
14static nxt_int_t nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs);
15static nxt_int_t nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs);
16static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
17
18
19nxt_sockaddr_t *
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10#if (NXT_INET6)
11static u_char *nxt_inet6_ntop(u_char *addr, u_char *buf, u_char *end);
12#endif
13
14static nxt_int_t nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs);
15static nxt_int_t nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs);
16static nxt_int_t nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs);
17
18
19nxt_sockaddr_t *
20nxt_sockaddr_alloc(nxt_mem_pool_t *mp, socklen_t len)
20nxt_sockaddr_alloc(nxt_mem_pool_t *mp, socklen_t length)
21{
22 nxt_sockaddr_t *sa;
23
24 /*
25 * The current struct sockaddr's define 32-bit fields at maximum
26 * and may define 64-bit AF_INET6 fields in the future. Alignment
27 * of memory allocated by nxt_mem_zalloc() is enough for these fields.
28 * If 128-bit alignment will be required then nxt_mem_malloc() and
29 * nxt_memzero() should be used instead.
30 */
21{
22 nxt_sockaddr_t *sa;
23
24 /*
25 * The current struct sockaddr's define 32-bit fields at maximum
26 * and may define 64-bit AF_INET6 fields in the future. Alignment
27 * of memory allocated by nxt_mem_zalloc() is enough for these fields.
28 * If 128-bit alignment will be required then nxt_mem_malloc() and
29 * nxt_memzero() should be used instead.
30 */
31 sa = nxt_mem_zalloc(mp, offsetof(nxt_sockaddr_t, u) + len);
31 sa = nxt_mem_zalloc(mp, offsetof(nxt_sockaddr_t, u) + length);
32
33 if (nxt_fast_path(sa != NULL)) {
32
33 if (nxt_fast_path(sa != NULL)) {
34 nxt_socklen_set(sa, len);
34 nxt_socklen_set(sa, length);
35 }
36
37 return sa;
38}
39
40
41nxt_sockaddr_t *
42nxt_sockaddr_create(nxt_mem_pool_t *mp, struct sockaddr *sockaddr,
35 }
36
37 return sa;
38}
39
40
41nxt_sockaddr_t *
42nxt_sockaddr_create(nxt_mem_pool_t *mp, struct sockaddr *sockaddr,
43 socklen_t len)
43 socklen_t length)
44{
45 size_t size, copy;
46 nxt_sockaddr_t *sa;
47
44{
45 size_t size, copy;
46 nxt_sockaddr_t *sa;
47
48 size = len;
49 copy = len;
48 size = length;
49 copy = length;
50
51#if (NXT_HAVE_UNIX_DOMAIN)
52
53 /*
54 * Unspecified Unix domain sockaddr_un form and length are very
55 * platform depended (see comment in unix/socket.h). Here they are
56 * normalized to the sockaddr_un with single zero byte sun_path[].
57 */

--- 47 unchanged lines hidden (view full) ---

105
106 /* Update shortcut sockaddr length overwritten by nxt_memcpy(). */
107 nxt_socklen_set(sa, size);
108
109#endif
110
111#if (NXT_HAVE_UNIX_DOMAIN && NXT_OPENBSD)
112
50
51#if (NXT_HAVE_UNIX_DOMAIN)
52
53 /*
54 * Unspecified Unix domain sockaddr_un form and length are very
55 * platform depended (see comment in unix/socket.h). Here they are
56 * normalized to the sockaddr_un with single zero byte sun_path[].
57 */

--- 47 unchanged lines hidden (view full) ---

105
106 /* Update shortcut sockaddr length overwritten by nxt_memcpy(). */
107 nxt_socklen_set(sa, size);
108
109#endif
110
111#if (NXT_HAVE_UNIX_DOMAIN && NXT_OPENBSD)
112
113 if (len == 0) {
113 if (length == 0) {
114 sa->u.sockaddr.sa_family = AF_UNIX;
115 }
116
117#endif
118 }
119
120 return sa;
121}
122
123
124nxt_sockaddr_t *
125nxt_sockaddr_copy(nxt_mem_pool_t *mp, nxt_sockaddr_t *src)
126{
114 sa->u.sockaddr.sa_family = AF_UNIX;
115 }
116
117#endif
118 }
119
120 return sa;
121}
122
123
124nxt_sockaddr_t *
125nxt_sockaddr_copy(nxt_mem_pool_t *mp, nxt_sockaddr_t *src)
126{
127 size_t len;
127 size_t length;
128 nxt_sockaddr_t *dst;
129
128 nxt_sockaddr_t *dst;
129
130 len = offsetof(nxt_sockaddr_t, u) + nxt_socklen(src);
130 length = offsetof(nxt_sockaddr_t, u) + nxt_socklen(src);
131
131
132 dst = nxt_mem_alloc(mp, len);
132 dst = nxt_mem_alloc(mp, length);
133
134 if (nxt_fast_path(dst != NULL)) {
133
134 if (nxt_fast_path(dst != NULL)) {
135 nxt_memcpy(dst, src, len);
135 nxt_memcpy(dst, src, length);
136 }
137
138 return dst;
139}
140
141
142nxt_sockaddr_t *
143nxt_getsockname(nxt_mem_pool_t *mp, nxt_socket_t s)

--- 15 unchanged lines hidden (view full) ---

159
160 return NULL;
161}
162
163
164nxt_int_t
165nxt_sockaddr_text(nxt_mem_pool_t *mp, nxt_sockaddr_t *sa, nxt_bool_t port)
166{
136 }
137
138 return dst;
139}
140
141
142nxt_sockaddr_t *
143nxt_getsockname(nxt_mem_pool_t *mp, nxt_socket_t s)

--- 15 unchanged lines hidden (view full) ---

159
160 return NULL;
161}
162
163
164nxt_int_t
165nxt_sockaddr_text(nxt_mem_pool_t *mp, nxt_sockaddr_t *sa, nxt_bool_t port)
166{
167 size_t len;
167 size_t length;
168 u_char *p;
169 u_char buf[NXT_SOCKADDR_STR_LEN + NXT_SOCKPORT_STR_LEN];
170
168 u_char *p;
169 u_char buf[NXT_SOCKADDR_STR_LEN + NXT_SOCKPORT_STR_LEN];
170
171 len = NXT_SOCKADDR_STR_LEN + NXT_SOCKPORT_STR_LEN;
171 length = NXT_SOCKADDR_STR_LEN + NXT_SOCKPORT_STR_LEN;
172
172
173 len = nxt_sockaddr_ntop(sa, buf, buf + len, port);
173 length = nxt_sockaddr_ntop(sa, buf, buf + length, port);
174
174
175 p = nxt_mem_alloc(mp, len);
175 p = nxt_mem_alloc(mp, length);
176
177 if (nxt_fast_path(p != NULL)) {
178
179 sa->text = p;
176
177 if (nxt_fast_path(p != NULL)) {
178
179 sa->text = p;
180 sa->text_len = len;
181 nxt_memcpy(p, buf, len);
180 sa->text_len = length;
181 nxt_memcpy(p, buf, length);
182
183 return NXT_OK;
184 }
185
186 return NXT_ERROR;
187}
188
189

--- 67 unchanged lines hidden (view full) ---

257 return 1;
258
259#endif
260
261#if (NXT_HAVE_UNIX_DOMAIN)
262
263 case AF_UNIX:
264 {
182
183 return NXT_OK;
184 }
185
186 return NXT_ERROR;
187}
188
189

--- 67 unchanged lines hidden (view full) ---

257 return 1;
258
259#endif
260
261#if (NXT_HAVE_UNIX_DOMAIN)
262
263 case AF_UNIX:
264 {
265 size_t len;
265 size_t length;
266
266
267 len = nxt_socklen(sa1) - offsetof(struct sockaddr_un, sun_path);
267 length = nxt_socklen(sa1) - offsetof(struct sockaddr_un, sun_path);
268
269 if (nxt_memcmp(&sa1->u.sockaddr_un.sun_path,
268
269 if (nxt_memcmp(&sa1->u.sockaddr_un.sun_path,
270 &sa2->u.sockaddr_un.sun_path, len)
270 &sa2->u.sockaddr_un.sun_path, length)
271 != 0)
272 {
273 return 0;
274 }
275
276 return 1;
277 }
278

--- 59 unchanged lines hidden (view full) ---

338
339 case AF_UNIX:
340
341#if (NXT_LINUX)
342
343 p = (u_char *) sa->u.sockaddr_un.sun_path;
344
345 if (p[0] == '\0') {
271 != 0)
272 {
273 return 0;
274 }
275
276 return 1;
277 }
278

--- 59 unchanged lines hidden (view full) ---

338
339 case AF_UNIX:
340
341#if (NXT_LINUX)
342
343 p = (u_char *) sa->u.sockaddr_un.sun_path;
344
345 if (p[0] == '\0') {
346 int len;
346 int length;
347
348 /* Linux abstract socket address has no trailing zero. */
349
347
348 /* Linux abstract socket address has no trailing zero. */
349
350 len = nxt_socklen(sa) - offsetof(struct sockaddr_un, sun_path) - 1;
351 p = nxt_sprintf(buf, end, "unix:\\0%*s", len, p + 1);
350 length = nxt_socklen(sa)
351 - offsetof(struct sockaddr_un, sun_path) - 1;
352 p = nxt_sprintf(buf, end, "unix:\\0%*s", length, p + 1);
352
353 } else {
354 p = nxt_sprintf(buf, end, "unix:%s", p);
355 }
356
357#else /* !(NXT_LINUX) */
358
359 p = nxt_sprintf(buf, end, "unix:%s", sa->u.sockaddr_un.sun_path);

--- 97 unchanged lines hidden (view full) ---

457
458#endif
459
460
461void
462nxt_job_sockaddr_parse(nxt_job_sockaddr_parse_t *jbs)
463{
464 u_char *p;
353
354 } else {
355 p = nxt_sprintf(buf, end, "unix:%s", p);
356 }
357
358#else /* !(NXT_LINUX) */
359
360 p = nxt_sprintf(buf, end, "unix:%s", sa->u.sockaddr_un.sun_path);

--- 97 unchanged lines hidden (view full) ---

458
459#endif
460
461
462void
463nxt_job_sockaddr_parse(nxt_job_sockaddr_parse_t *jbs)
464{
465 u_char *p;
465 size_t len;
466 size_t length;
466 nxt_int_t ret;
467 nxt_work_handler_t handler;
468
469 nxt_job_set_name(&jbs->resolve.job, "job sockaddr parse");
470
467 nxt_int_t ret;
468 nxt_work_handler_t handler;
469
470 nxt_job_set_name(&jbs->resolve.job, "job sockaddr parse");
471
471 len = jbs->addr.len;
472 p = jbs->addr.data;
472 length = jbs->addr.length;
473 p = jbs->addr.start;
473
474
474 if (len > 6 && nxt_memcmp(p, (u_char *) "unix:", 5) == 0) {
475 if (length > 6 && nxt_memcmp(p, (u_char *) "unix:", 5) == 0) {
475 ret = nxt_job_sockaddr_unix_parse(jbs);
476
476 ret = nxt_job_sockaddr_unix_parse(jbs);
477
477 } else if (len != 0 && *p == '[') {
478 } else if (length != 0 && *p == '[') {
478 ret = nxt_job_sockaddr_inet6_parse(jbs);
479
480 } else {
481 ret = nxt_job_sockaddr_inet_parse(jbs);
482 }
483
484 switch (ret) {
485

--- 12 unchanged lines hidden (view full) ---

498 nxt_job_return(jbs->resolve.job.task, &jbs->resolve.job, handler);
499}
500
501
502static nxt_int_t
503nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs)
504{
505#if (NXT_HAVE_UNIX_DOMAIN)
479 ret = nxt_job_sockaddr_inet6_parse(jbs);
480
481 } else {
482 ret = nxt_job_sockaddr_inet_parse(jbs);
483 }
484
485 switch (ret) {
486

--- 12 unchanged lines hidden (view full) ---

499 nxt_job_return(jbs->resolve.job.task, &jbs->resolve.job, handler);
500}
501
502
503static nxt_int_t
504nxt_job_sockaddr_unix_parse(nxt_job_sockaddr_parse_t *jbs)
505{
506#if (NXT_HAVE_UNIX_DOMAIN)
506 size_t len, socklen;
507 size_t length, socklen;
507 u_char *path;
508 nxt_mem_pool_t *mp;
509 nxt_sockaddr_t *sa;
510
511 /*
512 * Actual sockaddr_un length can be lesser or even larger than defined
513 * struct sockaddr_un length (see comment in unix/nxt_socket.h). So
514 * limit maximum Unix domain socket address length by defined sun_path[]
515 * length because some OSes accept addresses twice larger than defined
516 * struct sockaddr_un. Also reserve space for a trailing zero to avoid
517 * ambiguity, since many OSes accept Unix domain socket addresses
518 * without a trailing zero.
519 */
520 const size_t max_len = sizeof(struct sockaddr_un)
521 - offsetof(struct sockaddr_un, sun_path) - 1;
522
523 /* cutting "unix:" */
508 u_char *path;
509 nxt_mem_pool_t *mp;
510 nxt_sockaddr_t *sa;
511
512 /*
513 * Actual sockaddr_un length can be lesser or even larger than defined
514 * struct sockaddr_un length (see comment in unix/nxt_socket.h). So
515 * limit maximum Unix domain socket address length by defined sun_path[]
516 * length because some OSes accept addresses twice larger than defined
517 * struct sockaddr_un. Also reserve space for a trailing zero to avoid
518 * ambiguity, since many OSes accept Unix domain socket addresses
519 * without a trailing zero.
520 */
521 const size_t max_len = sizeof(struct sockaddr_un)
522 - offsetof(struct sockaddr_un, sun_path) - 1;
523
524 /* cutting "unix:" */
524 len = jbs->addr.len - 5;
525 path = jbs->addr.data + 5;
525 length = jbs->addr.length - 5;
526 path = jbs->addr.start + 5;
526
527
527 if (len > max_len) {
528 if (length > max_len) {
528 nxt_thread_log_error(jbs->resolve.log_level,
529 "unix domain socket \"%V\" name is too long",
530 &jbs->addr);
531 return NXT_ERROR;
532 }
533
529 nxt_thread_log_error(jbs->resolve.log_level,
530 "unix domain socket \"%V\" name is too long",
531 &jbs->addr);
532 return NXT_ERROR;
533 }
534
534 socklen = offsetof(struct sockaddr_un, sun_path) + len + 1;
535 socklen = offsetof(struct sockaddr_un, sun_path) + length + 1;
535
536#if (NXT_LINUX)
537
538 /*
539 * Linux unix(7):
540 *
541 * abstract: an abstract socket address is distinguished by the fact
542 * that sun_path[0] is a null byte ('\0'). The socket's address in

--- 14 unchanged lines hidden (view full) ---

557 if (nxt_fast_path(jbs->resolve.sockaddrs != NULL)) {
558 sa = nxt_sockaddr_alloc(mp, socklen);
559
560 if (nxt_fast_path(sa != NULL)) {
561 jbs->resolve.count = 1;
562 jbs->resolve.sockaddrs[0] = sa;
563
564 sa->u.sockaddr_un.sun_family = AF_UNIX;
536
537#if (NXT_LINUX)
538
539 /*
540 * Linux unix(7):
541 *
542 * abstract: an abstract socket address is distinguished by the fact
543 * that sun_path[0] is a null byte ('\0'). The socket's address in

--- 14 unchanged lines hidden (view full) ---

558 if (nxt_fast_path(jbs->resolve.sockaddrs != NULL)) {
559 sa = nxt_sockaddr_alloc(mp, socklen);
560
561 if (nxt_fast_path(sa != NULL)) {
562 jbs->resolve.count = 1;
563 jbs->resolve.sockaddrs[0] = sa;
564
565 sa->u.sockaddr_un.sun_family = AF_UNIX;
565 nxt_memcpy(sa->u.sockaddr_un.sun_path, path, len);
566 nxt_memcpy(sa->u.sockaddr_un.sun_path, path, length);
566
567 return NXT_OK;
568 }
569 }
570
571 return NXT_ERROR;
572
573#else /* !(NXT_HAVE_UNIX_DOMAIN) */

--- 7 unchanged lines hidden (view full) ---

581}
582
583
584static nxt_int_t
585nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs)
586{
587#if (NXT_INET6)
588 u_char *p, *addr, *addr_end;
567
568 return NXT_OK;
569 }
570 }
571
572 return NXT_ERROR;
573
574#else /* !(NXT_HAVE_UNIX_DOMAIN) */

--- 7 unchanged lines hidden (view full) ---

582}
583
584
585static nxt_int_t
586nxt_job_sockaddr_inet6_parse(nxt_job_sockaddr_parse_t *jbs)
587{
588#if (NXT_INET6)
589 u_char *p, *addr, *addr_end;
589 size_t len;
590 size_t length;
590 nxt_int_t port;
591 nxt_mem_pool_t *mp;
592 nxt_sockaddr_t *sa;
593 struct in6_addr *in6_addr;
594
591 nxt_int_t port;
592 nxt_mem_pool_t *mp;
593 nxt_sockaddr_t *sa;
594 struct in6_addr *in6_addr;
595
595 len = jbs->addr.len - 1;
596 addr = jbs->addr.data + 1;
596 length = jbs->addr.length - 1;
597 addr = jbs->addr.start + 1;
597
598
598 addr_end = nxt_memchr(addr, ']', len);
599 addr_end = nxt_memchr(addr, ']', length);
599
600 if (addr_end == NULL) {
601 goto invalid_address;
602 }
603
604 mp = jbs->resolve.job.mem_pool;
605
606 jbs->resolve.sockaddrs = nxt_mem_alloc(mp, sizeof(void *));

--- 13 unchanged lines hidden (view full) ---

620
621 in6_addr = &sa->u.sockaddr_in6.sin6_addr;
622
623 if (nxt_inet6_addr(in6_addr, addr, addr_end - addr) != NXT_OK) {
624 goto invalid_address;
625 }
626
627 p = addr_end + 1;
600
601 if (addr_end == NULL) {
602 goto invalid_address;
603 }
604
605 mp = jbs->resolve.job.mem_pool;
606
607 jbs->resolve.sockaddrs = nxt_mem_alloc(mp, sizeof(void *));

--- 13 unchanged lines hidden (view full) ---

621
622 in6_addr = &sa->u.sockaddr_in6.sin6_addr;
623
624 if (nxt_inet6_addr(in6_addr, addr, addr_end - addr) != NXT_OK) {
625 goto invalid_address;
626 }
627
628 p = addr_end + 1;
628 len = (addr + len) - p;
629 length = (addr + length) - p;
629
630
630 if (len == 0) {
631 if (length == 0) {
631 jbs->no_port = 1;
632 port = jbs->resolve.port;
633 goto found;
634 }
635
636 if (*p == ':') {
632 jbs->no_port = 1;
633 port = jbs->resolve.port;
634 goto found;
635 }
636
637 if (*p == ':') {
637 port = nxt_int_parse(p + 1, len - 1);
638 port = nxt_int_parse(p + 1, length - 1);
638
639 if (port >= 1 && port <= 65535) {
640 port = htons((in_port_t) port);
641 goto found;
642 }
643 }
644
645 nxt_thread_log_error(jbs->resolve.log_level,

--- 27 unchanged lines hidden (view full) ---

673#endif
674}
675
676
677static nxt_int_t
678nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs)
679{
680 u_char *p, *host;
639
640 if (port >= 1 && port <= 65535) {
641 port = htons((in_port_t) port);
642 goto found;
643 }
644 }
645
646 nxt_thread_log_error(jbs->resolve.log_level,

--- 27 unchanged lines hidden (view full) ---

674#endif
675}
676
677
678static nxt_int_t
679nxt_job_sockaddr_inet_parse(nxt_job_sockaddr_parse_t *jbs)
680{
681 u_char *p, *host;
681 size_t len;
682 size_t length;
682 in_addr_t addr;
683 nxt_int_t port;
684 nxt_mem_pool_t *mp;
685 nxt_sockaddr_t *sa;
686
687 addr = INADDR_ANY;
688
683 in_addr_t addr;
684 nxt_int_t port;
685 nxt_mem_pool_t *mp;
686 nxt_sockaddr_t *sa;
687
688 addr = INADDR_ANY;
689
689 len = jbs->addr.len;
690 host = jbs->addr.data;
690 length = jbs->addr.length;
691 host = jbs->addr.start;
691
692
692 p = nxt_memchr(host, ':', len);
693 p = nxt_memchr(host, ':', length);
693
694 if (p == NULL) {
695
696 /* single value port, address, or host name */
697
694
695 if (p == NULL) {
696
697 /* single value port, address, or host name */
698
698 port = nxt_int_parse(host, len);
699 port = nxt_int_parse(host, length);
699
700 if (port > 0) {
701 if (port < 1 || port > 65535) {
702 goto invalid_port;
703 }
704
705 /* "*:XX" */
706 port = htons((in_port_t) port);
707 jbs->resolve.port = (in_port_t) port;
708
709 } else {
710 jbs->no_port = 1;
711
700
701 if (port > 0) {
702 if (port < 1 || port > 65535) {
703 goto invalid_port;
704 }
705
706 /* "*:XX" */
707 port = htons((in_port_t) port);
708 jbs->resolve.port = (in_port_t) port;
709
710 } else {
711 jbs->no_port = 1;
712
712 addr = nxt_inet_addr(host, len);
713 addr = nxt_inet_addr(host, length);
713
714 if (addr == INADDR_NONE) {
714
715 if (addr == INADDR_NONE) {
715 jbs->resolve.name.len = len;
716 jbs->resolve.name.data = host;
716 jbs->resolve.name.length = length;
717 jbs->resolve.name.start = host;
717
718 nxt_job_resolve(&jbs->resolve);
719 return NXT_AGAIN;
720 }
721
722 /* "x.x.x.x" */
723 port = jbs->resolve.port;
724 }
725
726 } else {
727
728 /* x.x.x.x:XX or host:XX */
729
730 p++;
718
719 nxt_job_resolve(&jbs->resolve);
720 return NXT_AGAIN;
721 }
722
723 /* "x.x.x.x" */
724 port = jbs->resolve.port;
725 }
726
727 } else {
728
729 /* x.x.x.x:XX or host:XX */
730
731 p++;
731 len = (host + len) - p;
732 port = nxt_int_parse(p, len);
732 length = (host + length) - p;
733 port = nxt_int_parse(p, length);
733
734 if (port < 1 || port > 65535) {
735 goto invalid_port;
736 }
737
738 port = htons((in_port_t) port);
739
734
735 if (port < 1 || port > 65535) {
736 goto invalid_port;
737 }
738
739 port = htons((in_port_t) port);
740
740 len = (p - 1) - host;
741 length = (p - 1) - host;
741
742
742 if (len != 1 || host[0] != '*') {
743 addr = nxt_inet_addr(host, len);
743 if (length != 1 || host[0] != '*') {
744 addr = nxt_inet_addr(host, length);
744
745 if (addr == INADDR_NONE) {
745
746 if (addr == INADDR_NONE) {
746 jbs->resolve.name.len = len;
747 jbs->resolve.name.data = host;
747 jbs->resolve.name.length = length;
748 jbs->resolve.name.start = host;
748 jbs->resolve.port = (in_port_t) port;
749
750 nxt_job_resolve(&jbs->resolve);
751 return NXT_AGAIN;
752 }
753
754 /* "x.x.x.x:XX" */
755 }

--- 28 unchanged lines hidden (view full) ---

784 nxt_thread_log_error(jbs->resolve.log_level,
785 "invalid port in \"%V\"", &jbs->addr);
786
787 return NXT_ERROR;
788}
789
790
791in_addr_t
749 jbs->resolve.port = (in_port_t) port;
750
751 nxt_job_resolve(&jbs->resolve);
752 return NXT_AGAIN;
753 }
754
755 /* "x.x.x.x:XX" */
756 }

--- 28 unchanged lines hidden (view full) ---

785 nxt_thread_log_error(jbs->resolve.log_level,
786 "invalid port in \"%V\"", &jbs->addr);
787
788 return NXT_ERROR;
789}
790
791
792in_addr_t
792nxt_inet_addr(u_char *buf, size_t len)
793nxt_inet_addr(u_char *buf, size_t length)
793{
794 u_char c, *end;
795 in_addr_t addr;
796 nxt_uint_t digit, octet, dots;
797
798 addr = 0;
799 octet = 0;
800 dots = 0;
801
794{
795 u_char c, *end;
796 in_addr_t addr;
797 nxt_uint_t digit, octet, dots;
798
799 addr = 0;
800 octet = 0;
801 dots = 0;
802
802 end = buf + len;
803 end = buf + length;
803
804 while (buf < end) {
805
806 c = *buf++;
807
808 digit = c - '0';
809 /* values below '0' become large unsigned integers */
810

--- 19 unchanged lines hidden (view full) ---

830
831 return INADDR_NONE;
832}
833
834
835#if (NXT_INET6)
836
837nxt_int_t
804
805 while (buf < end) {
806
807 c = *buf++;
808
809 digit = c - '0';
810 /* values below '0' become large unsigned integers */
811

--- 19 unchanged lines hidden (view full) ---

831
832 return INADDR_NONE;
833}
834
835
836#if (NXT_INET6)
837
838nxt_int_t
838nxt_inet6_addr(struct in6_addr *in6_addr, u_char *buf, size_t len)
839nxt_inet6_addr(struct in6_addr *in6_addr, u_char *buf, size_t length)
839{
840 u_char c, *addr, *zero_start, *ipv4, *dst, *src, *end;
841 nxt_uint_t digit, group, nibbles, groups_left;
842
840{
841 u_char c, *addr, *zero_start, *ipv4, *dst, *src, *end;
842 nxt_uint_t digit, group, nibbles, groups_left;
843
843 if (len == 0) {
844 if (length == 0) {
844 return NXT_ERROR;
845 }
846
845 return NXT_ERROR;
846 }
847
847 end = buf + len;
848 end = buf + length;
848
849 if (buf[0] == ':') {
850 buf++;
851 }
852
853 addr = in6_addr->s6_addr;
854 zero_start = NULL;
855 groups_left = 8;

--- 118 unchanged lines hidden ---
849
850 if (buf[0] == ':') {
851 buf++;
852 }
853
854 addr = in6_addr->s6_addr;
855 zero_start = NULL;
856 groups_left = 8;

--- 118 unchanged lines hidden ---