Also add struct net_ip[46]_loopback.
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;
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");
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)
{
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. */
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,
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;
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;