blob: 31094ba594eda521c24180be3bc6f339760fd7ad [file] [log] [blame]
Igor Sysoev42feecb2002-12-15 06:25:09 +00001
Igor Sysoevd90282d2004-09-28 08:34:51 +00002/*
Igor Sysoevff8da912004-09-29 16:00:49 +00003 * Copyright (C) Igor Sysoev
Igor Sysoevd90282d2004-09-28 08:34:51 +00004 */
5
6
Igor Sysoev42feecb2002-12-15 06:25:09 +00007#include <ngx_config.h>
Igor Sysoev1c104622003-06-03 15:42:58 +00008#include <ngx_core.h>
Igor Sysoev42feecb2002-12-15 06:25:09 +00009
10
Igor Sysoev1b735832004-11-11 14:07:14 +000011/*
12 * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as
Igor Sysoevc31a9bb2005-11-26 10:11:11 +000013 * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", however,
14 * they had been implemented long before the ngx_sprintf() had appeared
Igor Sysoev1b735832004-11-11 14:07:14 +000015 * and they are faster by 1.5-2.5 times, so it is worth to keep them.
16 *
17 * By the way, the implementation using ngx_sprintf() is faster by 2.5-3 times
Igor Sysoev02025fd2005-01-18 13:03:58 +000018 * than using FreeBSD libc's snprintf().
Igor Sysoev1b735832004-11-11 14:07:14 +000019 */
20
21
Igor Sysoev94e32ce2006-04-07 14:08:04 +000022static ngx_inline size_t
23ngx_sprint_uchar(u_char *text, u_char c, size_t len)
Igor Sysoev9c610952004-03-16 13:35:20 +000024{
25 size_t n;
26 ngx_uint_t c1, c2;
27
28 n = 0;
29
30 if (len == n) {
31 return n;
32 }
33
34 c1 = c / 100;
35
36 if (c1) {
37 *text++ = (u_char) (c1 + '0');
38 n++;
39
40 if (len == n) {
41 return n;
42 }
43 }
44
45 c2 = (c % 100) / 10;
46
47 if (c1 || c2) {
48 *text++ = (u_char) (c2 + '0');
49 n++;
50
51 if (len == n) {
52 return n;
53 }
54 }
55
56 c2 = c % 10;
57
58 *text++ = (u_char) (c2 + '0');
59 n++;
60
61 return n;
62}
63
64
Igor Sysoev86de4cb2003-01-30 07:28:09 +000065/* AF_INET only */
66
Igor Sysoev899b44e2005-05-12 14:58:06 +000067size_t
68ngx_sock_ntop(int family, struct sockaddr *sa, u_char *text, size_t len)
Igor Sysoev86de4cb2003-01-30 07:28:09 +000069{
Igor Sysoev10a543a2004-03-16 07:10:12 +000070 u_char *p;
Igor Sysoev9c610952004-03-16 13:35:20 +000071 size_t n;
72 ngx_uint_t i;
Igor Sysoev02025fd2005-01-18 13:03:58 +000073 struct sockaddr_in *sin;
Igor Sysoev86de4cb2003-01-30 07:28:09 +000074
Igor Sysoev9c610952004-03-16 13:35:20 +000075 if (len == 0) {
76 return 0;
77 }
78
Igor Sysoev86de4cb2003-01-30 07:28:09 +000079 if (family != AF_INET) {
80 return 0;
81 }
82
Igor Sysoev02025fd2005-01-18 13:03:58 +000083 sin = (struct sockaddr_in *) sa;
84 p = (u_char *) &sin->sin_addr;
Igor Sysoev86de4cb2003-01-30 07:28:09 +000085
Igor Sysoev9c610952004-03-16 13:35:20 +000086 if (len > INET_ADDRSTRLEN) {
87 len = INET_ADDRSTRLEN;
88 }
89
90 n = ngx_sprint_uchar(text, p[0], len);
91
92 i = 1;
93
94 do {
95 if (len == n) {
96 text[n - 1] = '\0';
97 return n;
98 }
99
100 text[n++] = '.';
101
102 if (len == n) {
103 text[n - 1] = '\0';
104 return n;
105 }
106
107 n += ngx_sprint_uchar(&text[n], p[i++], len - n);
108
109 } while (i < 4);
110
111 if (len == n) {
112 text[n] = '\0';
113 return n;
114 }
115
116 text[n] = '\0';
117
118 return n;
Igor Sysoev86de4cb2003-01-30 07:28:09 +0000119}
120
Igor Sysoev899b44e2005-05-12 14:58:06 +0000121size_t
122ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
Igor Sysoev42feecb2002-12-15 06:25:09 +0000123{
Igor Sysoev9c610952004-03-16 13:35:20 +0000124 u_char *p;
125 size_t n;
126 ngx_uint_t i;
127
128 if (len == 0) {
129 return 0;
130 }
131
Igor Sysoev86de4cb2003-01-30 07:28:09 +0000132 if (family != AF_INET) {
Igor Sysoev42feecb2002-12-15 06:25:09 +0000133 return 0;
Igor Sysoev86de4cb2003-01-30 07:28:09 +0000134 }
Igor Sysoev42feecb2002-12-15 06:25:09 +0000135
Igor Sysoev9c610952004-03-16 13:35:20 +0000136 p = (u_char *) addr;
137
138 if (len > INET_ADDRSTRLEN) {
139 len = INET_ADDRSTRLEN;
140 }
141
142 n = ngx_sprint_uchar(text, p[0], len);
143
144 i = 1;
145
146 do {
147 if (len == n) {
148 text[n - 1] = '\0';
149 return n;
150 }
151
152 text[n++] = '.';
153
154 if (len == n) {
155 text[n - 1] = '\0';
156 return n;
157 }
158
159 n += ngx_sprint_uchar(&text[n], p[i++], len - n);
160
161 } while (i < 4);
162
163 if (len == n) {
164 text[n] = '\0';
165 return n;
166 }
167
168 text[n] = '\0';
169
170 return n;
Igor Sysoev42feecb2002-12-15 06:25:09 +0000171}
Igor Sysoev822834e2004-05-25 15:28:46 +0000172
173
174/* AF_INET only */
175
Igor Sysoev899b44e2005-05-12 14:58:06 +0000176ngx_int_t
177ngx_ptocidr(ngx_str_t *text, void *cidr)
Igor Sysoev822834e2004-05-25 15:28:46 +0000178{
Igor Sysoev59f3aa32004-06-24 16:07:04 +0000179 ngx_int_t m;
Igor Sysoev822834e2004-05-25 15:28:46 +0000180 ngx_uint_t i;
181 ngx_inet_cidr_t *in_cidr;
182
183 in_cidr = cidr;
184
185 for (i = 0; i < text->len; i++) {
186 if (text->data[i] == '/') {
187 break;
188 }
189 }
190
191 if (i == text->len) {
192 return NGX_ERROR;
193 }
194
195 text->data[i] = '\0';
196 in_cidr->addr = inet_addr((char *) text->data);
197 text->data[i] = '/';
198 if (in_cidr->addr == INADDR_NONE) {
199 return NGX_ERROR;
200 }
201
Igor Sysoev59f3aa32004-06-24 16:07:04 +0000202 m = ngx_atoi(&text->data[i + 1], text->len - (i + 1));
203 if (m == NGX_ERROR) {
Igor Sysoev822834e2004-05-25 15:28:46 +0000204 return NGX_ERROR;
205 }
206
Igor Sysoev59f3aa32004-06-24 16:07:04 +0000207 if (m == 0) {
208
209 /* the x86 compilers use the shl instruction that shifts by modulo 32 */
210
211 in_cidr->mask = 0;
212 return NGX_OK;
213 }
214
Igor Sysoev6deb0412004-07-30 17:05:14 +0000215 in_cidr->mask = htonl((ngx_uint_t) (0 - (1 << (32 - m))));
Igor Sysoev59f3aa32004-06-24 16:07:04 +0000216
Igor Sysoev845f6d52007-08-10 13:13:28 +0000217 if (in_cidr->addr == (in_cidr->addr & in_cidr->mask)) {
218 return NGX_OK;
219 }
220
221 in_cidr->addr &= in_cidr->mask;
222
223 return NGX_DONE;
Igor Sysoev822834e2004-05-25 15:28:46 +0000224}
Igor Sysoeve2ff3ea2004-09-14 15:55:24 +0000225
226
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000227ngx_int_t
228ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u)
229{
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000230 u_char *p, *host, *port_start;
231 size_t len, port_len;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000232 ngx_int_t port;
233 ngx_uint_t i;
Igor Sysoev20bf47b2006-10-24 13:06:55 +0000234 struct hostent *h;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000235#if (NGX_HAVE_UNIX_DOMAIN)
236 struct sockaddr_un *saun;
237#endif
238
239 len = u->url.len;
240 p = u->url.data;
241
Igor Sysoev722231f2007-02-14 18:51:19 +0000242 if (ngx_strncasecmp(p, (u_char *) "unix:", 5) == 0) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000243
244#if (NGX_HAVE_UNIX_DOMAIN)
245
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000246 p += 5;
247 len -= 5;
248
Igor Sysoev7c20ed82006-09-24 14:45:37 +0000249 u->uri.len = len;
250 u->uri.data = p;
251
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000252 if (u->uri_part) {
253 for (i = 0; i < len; i++) {
254
255 if (p[i] == ':') {
256 len = i;
257
258 u->uri.len -= len + 1;
259 u->uri.data += len + 1;
260
261 break;
262 }
263 }
264 }
265
266 if (len == 0) {
267 u->err = "no path in the unix domain socket";
268 return NGX_ERROR;
269 }
270
271 if (len + 1 > sizeof(saun->sun_path)) {
272 u->err = "too long path in the unix domain socket";
273 return NGX_ERROR;
274 }
275
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000276 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
277 if (u->addrs == NULL) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000278 return NGX_ERROR;
279 }
280
281 saun = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_un));
282 if (saun == NULL) {
283 return NGX_ERROR;
284 }
285
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000286 u->naddrs = 1;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000287
288 saun->sun_family = AF_UNIX;
289 (void) ngx_cpystrn((u_char *) saun->sun_path, p, len + 1);
290
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000291 u->addrs[0].sockaddr = (struct sockaddr *) saun;
292 u->addrs[0].socklen = sizeof(struct sockaddr_un);
293 u->addrs[0].name.len = len + 5;
294 u->addrs[0].name.data = u->url.data;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000295
Igor Sysoevadf9c7f2006-12-06 15:39:08 +0000296 u->host.len = len;
297 u->host.data = p;
298
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000299 u->unix_socket = 1;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000300
301 return NGX_OK;
302
303#else
304 u->err = "the unix domain sockets are not supported on this platform";
305
306 return NGX_ERROR;
307
308#endif
309 }
310
311 if ((p[0] == ':' || p[0] == '/') && !u->listen) {
312 u->err = "invalid host";
313 return NGX_ERROR;
314 }
315
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000316 u->host.data = p;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000317
318 port_start = NULL;
319 port_len = 0;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000320
321 for (i = 0; i < len; i++) {
322
323 if (p[i] == ':') {
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000324 port_start = &p[i + 1];
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000325 u->host.len = i;
326
327 if (!u->uri_part) {
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000328 port_len = len - (i + 1);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000329 break;
330 }
331 }
332
333 if (p[i] == '/') {
334 u->uri.len = len - i;
335 u->uri.data = &p[i];
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000336
337 if (u->host.len == 0) {
338 u->host.len = i;
339 }
340
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000341 if (port_start == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000342 u->no_port = 1;
343 goto no_port;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000344 }
345
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000346 port_len = &p[i] - port_start;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000347
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000348 if (port_len == 0) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000349 u->err = "invalid port";
350 return NGX_ERROR;
351 }
352
353 break;
354 }
355 }
356
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000357 if (port_start) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000358
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000359 if (port_len == 0) {
360 port_len = &p[i] - port_start;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000361
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000362 if (port_len == 0) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000363 u->err = "invalid port";
364 return NGX_ERROR;
365 }
366 }
367
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000368 port = ngx_atoi(port_start, port_len);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000369
370 if (port == NGX_ERROR || port < 1 || port > 65536) {
371 u->err = "invalid port";
372 return NGX_ERROR;
373 }
374
375 } else {
376 port = ngx_atoi(p, len);
377
378 if (port == NGX_ERROR) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000379 u->host.len = len;
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000380 u->no_port = 1;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000381
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000382 goto no_port;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000383 }
384
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000385 u->wildcard = 1;
386 }
387
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000388 u->port = (in_port_t) port;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000389
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000390no_port:
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000391
392 if (u->listen) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000393
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000394 if (u->port == 0) {
395 if (u->default_port == 0) {
Igor Sysoev20bf47b2006-10-24 13:06:55 +0000396 u->err = "no port";
397 return NGX_ERROR;
398 }
399
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000400 u->port = u->default_port;
Igor Sysoev20bf47b2006-10-24 13:06:55 +0000401 }
402
403 if (u->host.len == 1 && u->host.data[0] == '*') {
404 u->host.len = 0;
405 }
406
407 /* AF_INET only */
408
409 if (u->host.len) {
410
411 host = ngx_palloc(cf->temp_pool, u->host.len + 1);
412 if (host == NULL) {
413 return NGX_ERROR;
414 }
415
416 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
417
418 u->addr.in_addr = inet_addr((const char *) host);
419
420 if (u->addr.in_addr == INADDR_NONE) {
421 h = gethostbyname((const char *) host);
422
423 if (h == NULL || h->h_addr_list[0] == NULL) {
424 u->err = "host not found";
425 return NGX_ERROR;
426 }
427
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000428 u->addr.in_addr = *(in_addr_t *) (h->h_addr_list[0]);
Igor Sysoev20bf47b2006-10-24 13:06:55 +0000429 }
430
431 } else {
432 u->addr.in_addr = INADDR_ANY;
433 }
434
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000435 return NGX_OK;
436 }
437
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000438 if (u->host.len == 0) {
439 u->err = "no host";
440 return NGX_ERROR;
441 }
442
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000443 if (u->no_resolve) {
444 return NGX_OK;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000445 }
446
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000447 if (u->no_port) {
448 u->port = u->default_port;
449 }
450
451 if (u->port == 0) {
452 u->err = "no port";
453 return NGX_ERROR;
454 }
455
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000456 if (ngx_inet_resolve_host(cf, u) != NGX_OK) {
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000457 return NGX_ERROR;
458 }
459
460 return NGX_OK;
461}
462
463
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000464ngx_int_t
465ngx_inet_resolve_host(ngx_conf_t *cf, ngx_url_t *u)
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000466{
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000467 u_char *p, *host;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000468 size_t len;
469 in_addr_t in_addr;
470 ngx_uint_t i;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000471 struct hostent *h;
472 struct sockaddr_in *sin;
473
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000474 host = ngx_palloc(cf->temp_pool, u->host.len + 1);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000475 if (host == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000476 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000477 }
478
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000479 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000480
481 /* AF_INET only */
482
483 in_addr = inet_addr((char *) host);
484
485 if (in_addr == INADDR_NONE) {
486 h = gethostbyname((char *) host);
487
488 if (h == NULL || h->h_addr_list[0] == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000489 u->err = "host not found";
490 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000491 }
492
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000493 if (u->one_addr == 0) {
494 for (i = 0; h->h_addr_list[i] != NULL; i++) { /* void */ }
495
496 } else {
497 i = 1;
498 }
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000499
500 /* MP: ngx_shared_palloc() */
501
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000502 u->addrs = ngx_pcalloc(cf->pool, i * sizeof(ngx_peer_addr_t));
503 if (u->addrs == NULL) {
504 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000505 }
506
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000507 u->naddrs = i;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000508
509 for (i = 0; h->h_addr_list[i] != NULL; i++) {
510
511 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
512 if (sin == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000513 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000514 }
515
516 sin->sin_family = AF_INET;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000517 sin->sin_port = htons(u->port);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000518 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);
519
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000520 u->addrs[i].sockaddr = (struct sockaddr *) sin;
521 u->addrs[i].socklen = sizeof(struct sockaddr_in);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000522
523 len = INET_ADDRSTRLEN - 1 + 1 + sizeof(":65536") - 1;
524
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000525 p = ngx_palloc(cf->pool, len);
526 if (p == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000527 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000528 }
529
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000530 len = ngx_sock_ntop(AF_INET, (struct sockaddr *) sin, p, len);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000531
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000532 u->addrs[i].name.len = ngx_sprintf(&p[len], ":%d", u->port) - p;
533 u->addrs[i].name.data = p;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000534 }
535
536 } else {
537
538 /* MP: ngx_shared_palloc() */
539
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000540 u->addrs = ngx_pcalloc(cf->pool, sizeof(ngx_peer_addr_t));
541 if (u->addrs == NULL) {
542 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000543 }
544
545 sin = ngx_pcalloc(cf->pool, sizeof(struct sockaddr_in));
546 if (sin == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000547 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000548 }
549
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000550 u->naddrs = 1;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000551
552 sin->sin_family = AF_INET;
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000553 sin->sin_port = htons(u->port);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000554 sin->sin_addr.s_addr = in_addr;
555
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000556 u->addrs[0].sockaddr = (struct sockaddr *) sin;
557 u->addrs[0].socklen = sizeof(struct sockaddr_in);
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000558
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000559 p = ngx_palloc(cf->pool, u->host.len + sizeof(":65536") - 1);
560 if (p == NULL) {
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000561 return NGX_ERROR;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000562 }
563
Igor Sysoevbf3aaac2006-12-12 16:46:16 +0000564 u->addrs[0].name.len = ngx_sprintf(p, "%V:%d", &u->host, u->port) - p;
565 u->addrs[0].name.data = p;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000566 }
567
Igor Sysoev3d2fd182006-12-04 16:46:13 +0000568 return NGX_OK;
Igor Sysoev6f134cc2006-05-23 14:54:58 +0000569}