]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: net_get_ip_any[46]() to struct net_ip[46]_any
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Mon, 9 May 2016 12:24:28 +0000 (15:24 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 3 Jun 2016 11:36:01 +0000 (14:36 +0300)
Also add struct net_ip[46]_loopback.

src/director/director.c
src/lib-http/test-http-server.c
src/lib/net.c
src/lib/net.h
src/master/service.c

index 11089b5cf70315f2d34669b6fa2a0a7b270cdb5a..e041d84904e11f5df9233b76243433b131e0f837 100644 (file)
@@ -26,14 +26,10 @@ bool director_debug;
 
 static bool director_is_self_ip_set(struct director *dir)
 {
-       struct ip_addr ip;
-
-       net_get_ip_any4(&ip);
-       if (net_ip_compare(&dir->self_ip, &ip))
+       if (net_ip_compare(&dir->self_ip, &net_ip4_any))
                return FALSE;
 
-       net_get_ip_any6(&ip);
-       if (net_ip_compare(&dir->self_ip, &ip))
+       if (net_ip_compare(&dir->self_ip, &net_ip6_any))
                return FALSE;
 
        return TRUE;
index 8721b0bee3bf3369d9170ed5ebf70cbe78c99995..b134f094b68213b07dc636c105bc410f1f7c43e8 100644 (file)
@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
        if (argc < 2 || net_str2port(argv[1], &port) < 0)
                i_fatal("Port parameter missing");
        if (argc < 3)
-               net_get_ip_any4(&my_ip);
+               my_ip = net_ip4_any;
        else if (net_addr2ip(argv[2], &my_ip) < 0)
                i_fatal("Invalid IP parameter");
 
index 33186791e5ae798f1d6aaf84efab1dae8f8709ce..06034eb4c4989ee681d62ded642e4752c3321f46 100644 (file)
@@ -375,17 +375,25 @@ int net_set_recv_buffer_size(int fd, size_t size)
        return setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &opt, sizeof(opt));
 }
 
-void net_get_ip_any4(struct ip_addr *ip)
-{
-       ip->family = AF_INET;
-       ip->u.ip4.s_addr = INADDR_ANY;
-}
+const struct ip_addr net_ip4_any = {
+       .family = AF_INET,
+       .u.ip4.s_addr = INADDR_ANY
+};
 
-void net_get_ip_any6(struct ip_addr *ip)
-{
-       ip->family = AF_INET6;
-       ip->u.ip6 = in6addr_any;
-}
+const struct ip_addr net_ip6_any = {
+       .family = AF_INET6,
+       .u.ip6 = IN6ADDR_ANY_INIT
+};
+
+const struct ip_addr net_ip4_loopback = {
+       .family = AF_INET,
+       .u.ip4.s_addr = INADDR_LOOPBACK
+};
+
+const struct ip_addr net_ip6_loopback = {
+       .family = AF_INET6,
+       .u.ip6 = IN6ADDR_LOOPBACK_INIT
+};
 
 int net_listen(const struct ip_addr *my_ip, in_port_t *port, int backlog)
 {
index a56a7a63052849668539454bc0649249714a5eff..3b0c9c768498ecf5ccf20f16f4c470fb35e3f950 100644 (file)
@@ -48,6 +48,14 @@ enum net_listen_flags {
        NET_LISTEN_FLAG_REUSEPORT       = 0x01
 };
 
+/* INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
+   include IPv4 depending on the system (Linux yes, BSD no). */
+extern const struct ip_addr net_ip4_any;
+extern const struct ip_addr net_ip6_any;
+
+extern const struct ip_addr net_ip4_loopback;
+extern const struct ip_addr net_ip6_loopback;
+
 /* Returns TRUE if IPs are the same */
 bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2);
 /* Returns 0 if IPs are the same, -1 or 1 otherwise. */
@@ -84,11 +92,6 @@ int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;
 int net_set_send_buffer_size(int fd, size_t size);
 int net_set_recv_buffer_size(int fd, size_t size);
 
-/* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may
-   include IPv4 depending on the system (Linux yes, BSD no). */
-void net_get_ip_any4(struct ip_addr *ip);
-void net_get_ip_any6(struct ip_addr *ip);
-
 /* Listen for connections on a socket */
 int net_listen(const struct ip_addr *my_ip, in_port_t *port, int backlog);
 int net_listen_full(const struct ip_addr *my_ip, in_port_t *port,
index d9f49d6bb721a52edfaf63d2e64986bbe2f16e63..1bae79f8c7375c55675531220125bdb0060b480a 100644 (file)
@@ -79,7 +79,7 @@ resolve_ip(const char *address, const struct ip_addr **ips_r,
        if (address == NULL || strcmp(address, "*") == 0) {
                /* IPv4 any */
                ip_list = t_new(struct ip_addr, 1);
-               net_get_ip_any4(ip_list);
+               *ip_list = net_ip4_any;
                *ips_r = ip_list;
                *ips_count_r = 1;
                return 0;
@@ -88,7 +88,7 @@ resolve_ip(const char *address, const struct ip_addr **ips_r,
        if (strcmp(address, "::") == 0 || strcmp(address, "[::]") == 0) {
                /* IPv6 any */
                ip_list = t_new(struct ip_addr, 1);
-               net_get_ip_any6(ip_list);
+               *ip_list = net_ip6_any;
                *ips_r = ip_list;
                *ips_count_r = 1;
                return 0;