[dovecot-cvs] dovecot/src/lib network.c,1.11,1.12 network.h,1.5,1.6

cras at procontrol.fi cras at procontrol.fi
Thu Dec 12 20:33:34 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv16373/src/lib

Modified Files:
	network.c network.h 
Log Message:
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.



Index: network.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- network.c	26 Nov 2002 13:27:13 -0000	1.11
+++ network.c	12 Dec 2002 18:33:32 -0000	1.12
@@ -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))

Index: network.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/network.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- network.h	26 Nov 2002 13:27:13 -0000	1.5
+++ network.h	12 Dec 2002 18:33:32 -0000	1.6
@@ -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);
 




More information about the dovecot-cvs mailing list