ngx_int_t
ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
    size_t len)
{
    u_char     *p, *last;
    size_t      plen;
    ngx_int_t   rc, port;
    rc = ngx_parse_addr(pool, addr, text, len);
    if (rc != NGX_DECLINED) {
        return rc;
    }
    last = text + len;
#if (NGX_HAVE_INET6)
    if (len && text[0] == '[') {
        p = ngx_strlchr(text, last, ']');
        if (p == NULL || p == last - 1 || *++p != ':') {
            return NGX_DECLINED;
        }
        text++;
        len -= 2;
    } else
#endif
    {
        p = ngx_strlchr(text, last, ':');
        if (p == NULL) {
            return NGX_DECLINED;
        }
    }
    p++;
    plen = last - p;
    port = ngx_atoi(p, plen);
    if (port < 1 || port > 65535) {
        return NGX_DECLINED;
    }
    len -= plen + 1;
    rc = ngx_parse_addr(pool, addr, text, len);
    if (rc != NGX_OK) {
        return rc;
    }
    ngx_inet_set_port(addr->sockaddr, (in_port_t) port);
    return NGX_OK;
}
["static ngx_int_t\nngx_http_get_forwarded_addr_internal(ngx_http_request_t *r, ngx_addr_t *addr,\n    u_char *xff, size_t xfflen, ngx_array_t *proxies, int recursive)\n{\n    u_char      *p;\n    ngx_addr_t   paddr;\n    ngx_uint_t   found;\n    found = 0;\n    do {\n        if (ngx_cidr_match(addr->sockaddr, proxies) != NGX_OK) {\n            return found ? NGX_DONE : NGX_DECLINED;\n        }\n        for (p = xff + xfflen - 1; p > xff; p--, xfflen--) {\n            if (*p != ' ' && *p != ',') {\n                break;\n            }\n        }\n        for (   ; p > xff; p--) {\n            if (*p == ' ' || *p == ',') {\n                p++;\n                break;\n            }\n        }\n        if (ngx_parse_addr_port(r->pool, &paddr, p, xfflen - (p - xff))\n            != NGX_OK)\n        {\n            return found ? NGX_DONE : NGX_DECLINED;\n        }\n        *addr = paddr;\n        found = 1;\n        xfflen = p - 1 - xff;\n    } while (recursive && p > xff);\n    return NGX_OK;\n}", "ngx_int_t\nngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,\n    size_t len)\n{\n    u_char     *p, *last;\n    size_t      plen;\n    ngx_int_t   rc, port;\n    rc = ngx_parse_addr(pool, addr, text, len);\n    if (rc != NGX_DECLINED) {\n        return rc;\n    }\n    last = text + len;\n#if (NGX_HAVE_INET6)\n    if (len && text[0] == '[') {\n        p = ngx_strlchr(text, last, ']');\n        if (p == NULL || p == last - 1 || *++p != ':') {\n            return NGX_DECLINED;\n        }\n        text++;\n        len -= 2;\n    } else\n#endif\n    {\n        p = ngx_strlchr(text, last, ':');\n        if (p == NULL) {\n            return NGX_DECLINED;\n        }\n    }\n    p++;\n    plen = last - p;\n    port = ngx_atoi(p, plen);\n    if (port < 1 || port > 65535) {\n        return NGX_DECLINED;\n    }\n    len -= plen + 1;\n    rc = ngx_parse_addr(pool, addr, text, len);\n    if (rc != NGX_OK) {\n        return rc;\n    }\n    ngx_inet_set_port(addr->sockaddr, (in_port_t) port);\n    return NGX_OK;\n}"]