Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_INET_H_INCLUDED_
0009 #define _NGX_INET_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 
0016 #define NGX_INET_ADDRSTRLEN   (sizeof("255.255.255.255") - 1)
0017 #define NGX_INET6_ADDRSTRLEN                                                 \
0018     (sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") - 1)
0019 #define NGX_UNIX_ADDRSTRLEN                                                  \
0020     (sizeof("unix:") - 1 +                                                   \
0021      sizeof(struct sockaddr_un) - offsetof(struct sockaddr_un, sun_path))
0022 
0023 #if (NGX_HAVE_UNIX_DOMAIN)
0024 #define NGX_SOCKADDR_STRLEN   NGX_UNIX_ADDRSTRLEN
0025 #elif (NGX_HAVE_INET6)
0026 #define NGX_SOCKADDR_STRLEN   (NGX_INET6_ADDRSTRLEN + sizeof("[]:65535") - 1)
0027 #else
0028 #define NGX_SOCKADDR_STRLEN   (NGX_INET_ADDRSTRLEN + sizeof(":65535") - 1)
0029 #endif
0030 
0031 /* compatibility */
0032 #define NGX_SOCKADDRLEN       sizeof(ngx_sockaddr_t)
0033 
0034 
0035 typedef union {
0036     struct sockaddr           sockaddr;
0037     struct sockaddr_in        sockaddr_in;
0038 #if (NGX_HAVE_INET6)
0039     struct sockaddr_in6       sockaddr_in6;
0040 #endif
0041 #if (NGX_HAVE_UNIX_DOMAIN)
0042     struct sockaddr_un        sockaddr_un;
0043 #endif
0044 } ngx_sockaddr_t;
0045 
0046 
0047 typedef struct {
0048     in_addr_t                 addr;
0049     in_addr_t                 mask;
0050 } ngx_in_cidr_t;
0051 
0052 
0053 #if (NGX_HAVE_INET6)
0054 
0055 typedef struct {
0056     struct in6_addr           addr;
0057     struct in6_addr           mask;
0058 } ngx_in6_cidr_t;
0059 
0060 #endif
0061 
0062 
0063 typedef struct {
0064     ngx_uint_t                family;
0065     union {
0066         ngx_in_cidr_t         in;
0067 #if (NGX_HAVE_INET6)
0068         ngx_in6_cidr_t        in6;
0069 #endif
0070     } u;
0071 } ngx_cidr_t;
0072 
0073 
0074 typedef struct {
0075     struct sockaddr          *sockaddr;
0076     socklen_t                 socklen;
0077     ngx_str_t                 name;
0078 } ngx_addr_t;
0079 
0080 
0081 typedef struct {
0082     ngx_str_t                 url;
0083     ngx_str_t                 host;
0084     ngx_str_t                 port_text;
0085     ngx_str_t                 uri;
0086 
0087     in_port_t                 port;
0088     in_port_t                 default_port;
0089     int                       family;
0090 
0091     unsigned                  listen:1;
0092     unsigned                  uri_part:1;
0093     unsigned                  no_resolve:1;
0094 
0095     unsigned                  no_port:1;
0096     unsigned                  wildcard:1;
0097 
0098     socklen_t                 socklen;
0099     ngx_sockaddr_t            sockaddr;
0100 
0101     ngx_addr_t               *addrs;
0102     ngx_uint_t                naddrs;
0103 
0104     char                     *err;
0105 } ngx_url_t;
0106 
0107 
0108 in_addr_t ngx_inet_addr(u_char *text, size_t len);
0109 #if (NGX_HAVE_INET6)
0110 ngx_int_t ngx_inet6_addr(u_char *p, size_t len, u_char *addr);
0111 size_t ngx_inet6_ntop(u_char *p, u_char *text, size_t len);
0112 #endif
0113 size_t ngx_sock_ntop(struct sockaddr *sa, socklen_t socklen, u_char *text,
0114     size_t len, ngx_uint_t port);
0115 size_t ngx_inet_ntop(int family, void *addr, u_char *text, size_t len);
0116 ngx_int_t ngx_ptocidr(ngx_str_t *text, ngx_cidr_t *cidr);
0117 ngx_int_t ngx_cidr_match(struct sockaddr *sa, ngx_array_t *cidrs);
0118 ngx_int_t ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
0119     size_t len);
0120 ngx_int_t ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr,
0121     u_char *text, size_t len);
0122 ngx_int_t ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u);
0123 ngx_int_t ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u);
0124 ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,
0125     struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port);
0126 in_port_t ngx_inet_get_port(struct sockaddr *sa);
0127 void ngx_inet_set_port(struct sockaddr *sa, in_port_t port);
0128 
0129 
0130 #endif /* _NGX_INET_H_INCLUDED_ */