Mercurial > dovecot > core-2.2
changeset 780:1cc947617c8b HEAD
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
"::" as "all IPv6 interfaces, plus all IPv4 interfaces if supported by OS".
Added a few consts to network API and added functions to get inaddr_any for
ipv4/ipv6.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 12 Dec 2002 20:33:32 +0200 |
parents | f126b666859e |
children | 9cb7022749e7 |
files | dovecot-example.conf src/lib/network.c src/lib/network.h src/master/main.c src/master/settings.c |
diffstat | 5 files changed, 52 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/dovecot-example.conf Thu Dec 12 08:04:29 2002 +0200 +++ b/dovecot-example.conf Thu Dec 12 20:33:32 2002 +0200 @@ -13,9 +13,11 @@ # Port to listen in for SSL IMAP connections. Setting it to 0 disables it. #imaps_port = 993 -# IP or host address where to listen in for IMAP connections. Empty means to -# listen in all interfaces. It's not possible to specify multiple. -#imap_listen = +# IP or host address where to listen in for IMAP connections. It's not +# possible to specify multiple addresses. "*" listens in all IPv4 interfaces. +# "::" listens in all IPv6 interfaces, but may also listen in all IPv4 +# interfaces depending on the operating system. +#imap_listen = * # IP or host address where to listen in for SSL IMAP connections. Defaults # to imap_listen if not specified.
--- a/src/lib/network.c Thu Dec 12 08:04:29 2002 +0200 +++ b/src/lib/network.c Thu Dec 12 20:33:32 2002 +0200 @@ -49,7 +49,7 @@ # define SIZEOF_SOCKADDR(so) (sizeof(so.sin)) #endif -int net_ip_compare(IPADDR *ip1, IPADDR *ip2) +int net_ip_compare(const IPADDR *ip1, const IPADDR *ip2) { if (ip1->family != ip2->family) return 0; @@ -125,7 +125,7 @@ } /* Connect to socket with ip address */ -int net_connect_ip(IPADDR *ip, unsigned int port, IPADDR *my_ip) +int net_connect_ip(const IPADDR *ip, unsigned int port, const IPADDR *my_ip) { union sockaddr_union so; int fd, ret, opt = 1; @@ -235,9 +235,27 @@ #endif } +void net_get_ip_any4(IPADDR *ip) +{ + struct in_addr *in_ip = (struct in_addr *) &ip->ip; + + ip->family = AF_INET; + in_ip->s_addr = INADDR_ANY; +} + +void net_get_ip_any6(IPADDR *ip) +{ +#ifdef HAVE_IPV6 + ip->family = AF_INET6; + ip->ip = in6addr_any; +#else + memset(ip, 0, sizeof(IPADDR)); +#endif +} + /* Listen for connections on a socket. if `my_ip' is NULL, listen in any address. */ -int net_listen(IPADDR *my_ip, unsigned int *port) +int net_listen(const IPADDR *my_ip, unsigned int *port) { union sockaddr_union so; int ret, fd, opt = 1; @@ -477,7 +495,7 @@ return 0; } -int net_ip2host(IPADDR *ip, char *host) +int net_ip2host(const IPADDR *ip, char *host) { #ifdef HAVE_IPV6 if (!inet_ntop(ip->family, &ip->ip, host, MAX_IP_LEN))
--- a/src/lib/network.h Thu Dec 12 08:04:29 2002 +0200 +++ b/src/lib/network.h Thu Dec 12 20:33:32 2002 +0200 @@ -40,10 +40,10 @@ #define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6) /* returns 1 if IPADDRs are the same */ -int net_ip_compare(IPADDR *ip1, IPADDR *ip2); +int net_ip_compare(const IPADDR *ip1, const IPADDR *ip2); /* Connect to socket with ip address */ -int net_connect_ip(IPADDR *ip, unsigned int port, IPADDR *my_ip); +int net_connect_ip(const IPADDR *ip, unsigned int port, const IPADDR *my_ip); /* Connect to named UNIX socket */ int net_connect_unix(const char *path); /* Disconnect socket */ @@ -58,8 +58,13 @@ Returns 0 if ok, -1 if failed. */ int net_set_cork(int fd, int cork); +/* 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(IPADDR *ip); +void net_get_ip_any6(IPADDR *ip); + /* Listen for connections on a socket */ -int net_listen(IPADDR *my_ip, unsigned int *port); +int net_listen(const IPADDR *my_ip, unsigned int *port); /* Listen for connections on an UNIX socket */ int net_listen_unix(const char *path); /* Accept a connection on a socket. Returns -1 for temporary failure, @@ -84,7 +89,7 @@ int net_getsockname(int fd, IPADDR *addr, unsigned int *port); /* IPADDR -> char* translation. `host' must be at least MAX_IP_LEN bytes */ -int net_ip2host(IPADDR *ip, char *host); +int net_ip2host(const IPADDR *ip, char *host); /* char* -> IPADDR translation. */ int net_host2ip(const char *host, IPADDR *ip);
--- a/src/master/main.c Thu Dec 12 08:04:29 2002 +0200 +++ b/src/master/main.c Thu Dec 12 20:33:32 2002 +0200 @@ -124,7 +124,21 @@ int ret, ips_count; if (name == NULL || *name == '\0') - return NULL; + return NULL; /* defaults to "*" or "::" */ + + if (strcmp(name, "*") == 0) { + /* IPv4 any */ + ip = t_new(IPADDR, 1); + net_get_ip_any4(ip); + return ip; + } + + if (strcmp(name, "::") == 0) { + /* IPv6 any */ + ip = t_new(IPADDR, 1); + net_get_ip_any6(ip); + return ip; + } ret = net_gethostbyname(name, &ip, &ips_count); if (ret != 0)
--- a/src/master/settings.c Thu Dec 12 08:04:29 2002 +0200 +++ b/src/master/settings.c Thu Dec 12 20:33:32 2002 +0200 @@ -90,7 +90,7 @@ /* general */ unsigned int set_imap_port = 143; unsigned int set_imaps_port = 993; -char *set_imap_listen = NULL; +char *set_imap_listen = "*"; char *set_imaps_listen = NULL; int set_ssl_disable = FALSE;