changeset 15187:02451e967a06

Renamed network.[ch] to net.[ch]. The function prefixes already started with net_ instead of network_. And icecap wants to use network.h for other purpose. :)
author Timo Sirainen <tss@iki.fi>
date Wed, 03 Oct 2012 18:17:26 +0300
parents 559718e321a2
children d66421812d2a
files src/auth/auth-client-connection.c src/auth/auth-master-connection.c src/auth/auth-penalty.c src/auth/auth-postfix-connection.c src/auth/auth-request-handler.c src/auth/auth-request.h src/auth/auth-worker-client.c src/auth/auth-worker-server.c src/auth/db-ldap.c src/auth/main.c src/auth/passdb-pam.c src/config/config-filter.h src/config/settings-get.pl src/director/auth-connection.c src/director/director-connection.c src/director/director-host.h src/director/director.h src/director/doveadm-connection.c src/director/login-connection.c src/director/mail-host.h src/doveadm/doveadm-director.c src/doveadm/doveadm-kick.c src/doveadm/doveadm-mail-index.c src/doveadm/doveadm-penalty.c src/doveadm/doveadm-stats.c src/doveadm/doveadm-util.c src/doveadm/doveadm-who.c src/doveadm/server-connection.c src/imap-login/client-authenticate.c src/imap-login/client.h src/imap-urlauth/imap-urlauth-client.c src/imap-urlauth/imap-urlauth-login.c src/imap-urlauth/imap-urlauth-worker.c src/imap/cmd-idle.c src/imap/cmd-urlfetch.c src/imap/imap-client.c src/lib-auth/auth-client.h src/lib-auth/auth-master.c src/lib-auth/auth-master.h src/lib-auth/auth-server-connection.c src/lib-dict/dict-client.c src/lib-dns/dns-lookup.c src/lib-imap-client/imapc-connection.c src/lib-imap-storage/imap-msgpart-url.c src/lib-imap-urlauth/imap-urlauth-connection.c src/lib-imap-urlauth/imap-urlauth-fetch.c src/lib-imap/imap-url.c src/lib-imap/test-imap-url.c src/lib-lda/lmtp-client.c src/lib-lda/lmtp-client.h src/lib-master/anvil-client.c src/lib-master/ipc-client.c src/lib-master/ipc-server.c src/lib-master/master-auth.h src/lib-master/master-login-auth.c src/lib-master/master-service-settings.h src/lib-master/master-service.h src/lib-settings/settings-parser.c src/lib-storage/index/pop3c/pop3c-client.c src/lib-storage/mail-storage-service.h src/lib-storage/mail-user.c src/lib/Makefile.am src/lib/connection.c src/lib/connection.h src/lib/failures.c src/lib/fd-close-on-exec.c src/lib/ioloop-notify-inotify.c src/lib/istream-file.c src/lib/net.c src/lib/net.h src/lib/network.c src/lib/network.h src/lib/ostream-file.c src/lib/sendfile-util.c src/lib/test-network.c src/lib/unix-socket-create.c src/lib/uri-util.c src/lmtp/client.h src/lmtp/lmtp-proxy.h src/login-common/access-lookup.c src/login-common/client-common.h src/login-common/login-proxy-state.c src/login-common/login-proxy.h src/login-common/ssl-proxy-gnutls.c src/login-common/ssl-proxy-openssl.c src/master/master-settings.c src/master/service-listen.c src/master/service.h src/plugins/fts/fts-indexer.c src/plugins/fts/fts-parser-script.c src/plugins/quota/quota.c src/plugins/replication/replication-plugin.c src/plugins/stats/stats-connection.c src/plugins/zlib/doveadm-zlib.c src/pop3-login/client.h src/pop3/pop3-client.c src/replication/aggregator/notify-connection.c src/replication/aggregator/replicator-connection.c src/replication/replicator/doveadm-connection.c src/stats/client-export.c src/stats/mail-stats.h src/util/rawlog.c
diffstat 102 files changed, 1274 insertions(+), 1274 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-client-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-client-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
-#include "network.h"
+#include "net.h"
 #include "hex-binary.h"
 #include "hostpid.h"
 #include "llist.h"
--- a/src/auth/auth-master-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-master-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -10,7 +10,7 @@
 #include "hostpid.h"
 #include "hex-binary.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "ipwd.h"
--- a/src/auth/auth-penalty.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-penalty.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "crc32.h"
 #include "master-service.h"
 #include "anvil-client.h"
--- a/src/auth/auth-postfix-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-postfix-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "auth-common.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "llist.h"
--- a/src/auth/auth-request-handler.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-request-handler.c	Wed Oct 03 18:17:26 2012 +0300
@@ -6,7 +6,7 @@
 #include "aqueue.h"
 #include "base64.h"
 #include "hash.h"
-#include "network.h"
+#include "net.h"
 #include "str.h"
 #include "str-sanitize.h"
 #include "master-interface.h"
--- a/src/auth/auth-request.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-request.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef AUTH_REQUEST_H
 #define AUTH_REQUEST_H
 
-#include "network.h"
+#include "net.h"
 #include "var-expand.h"
 #include "mech.h"
 #include "userdb.h"
--- a/src/auth/auth-worker-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-worker-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "auth-common.h"
 #include "base64.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "hex-binary.h"
--- a/src/auth/auth-worker-server.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/auth-worker-server.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "ioloop.h"
 #include "array.h"
 #include "aqueue.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "hex-binary.h"
--- a/src/auth/db-ldap.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/db-ldap.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 
 #if defined(BUILTIN_LDAP) || defined(PLUGIN_BUILD)
 
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "array.h"
 #include "hash.h"
--- a/src/auth/main.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/main.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "auth-common.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "lib-signals.h"
 #include "restrict-access.h"
 #include "child-wait.h"
--- a/src/auth/passdb-pam.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/auth/passdb-pam.c	Wed Oct 03 18:17:26 2012 +0300
@@ -15,7 +15,7 @@
 #include "lib-signals.h"
 #include "str.h"
 #include "var-expand.h"
-#include "network.h"
+#include "net.h"
 #include "safe-memset.h"
 #include "auth-cache.h"
 
--- a/src/config/config-filter.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/config/config-filter.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CONFIG_FILTER_H
 #define CONFIG_FILTER_H
 
-#include "network.h"
+#include "net.h"
 
 struct master_service_settings_output;
 
--- a/src/config/settings-get.pl	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/config/settings-get.pl	Wed Oct 03 18:17:26 2012 +0300
@@ -8,7 +8,7 @@
 print '#include "file-lock.h"'."\n";
 print '#include "fsync-mode.h"'."\n";
 print '#include "hash-format.h"'."\n";
-print '#include "network.h"'."\n";
+print '#include "net.h"'."\n";
 print '#include "unichar.h"'."\n";
 print '#include "settings-parser.h"'."\n";
 print '#include "all-settings.h"'."\n";
--- a/src/director/auth-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/auth-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
-#include "network.h"
+#include "net.h"
 #include "llist.h"
 #include "safe-memset.h"
 #include "auth-client-interface.h"
--- a/src/director/director-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/director-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -31,7 +31,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
--- a/src/director/director-host.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/director-host.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef DIRECTOR_HOST_H
 #define DIRECTOR_HOST_H
 
-#include "network.h"
+#include "net.h"
 
 struct director;
 
--- a/src/director/director.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/director.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef DIRECTOR_H
 #define DIRECTOR_H
 
-#include "network.h"
+#include "net.h"
 #include "director-settings.h"
 
 #define DIRECTOR_VERSION_NAME "director"
--- a/src/director/doveadm-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/doveadm-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "array.h"
--- a/src/director/login-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/login-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "ostream.h"
 #include "llist.h"
 #include "master-service.h"
--- a/src/director/mail-host.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/director/mail-host.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MAIL_HOST_H
 #define MAIL_HOST_H
 
-#include "network.h"
+#include "net.h"
 
 struct mail_host_list;
 
--- a/src/doveadm/doveadm-director.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-director.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "md5.h"
 #include "hash.h"
 #include "str.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "write-full.h"
 #include "master-service.h"
--- a/src/doveadm/doveadm-kick.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-kick.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "hash.h"
 #include "doveadm.h"
 #include "doveadm-who.h"
--- a/src/doveadm/doveadm-mail-index.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-mail-index.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "str.h"
 #include "strescape.h"
-#include "network.h"
+#include "net.h"
 #include "write-full.h"
 #include "mail-namespace.h"
 #include "mail-storage.h"
--- a/src/doveadm/doveadm-penalty.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-penalty.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "hash.h"
 #include "doveadm.h"
--- a/src/doveadm/doveadm-stats.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-stats.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "istream.h"
 #include "hash.h"
--- a/src/doveadm/doveadm-util.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-util.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "time-util.h"
 #include "master-service.h"
 #include "module-dir.h"
--- a/src/doveadm/doveadm-who.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/doveadm-who.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "wildcard-match.h"
 #include "hash.h"
--- a/src/doveadm/server-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/doveadm/server-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "array.h"
 #include "base64.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
--- a/src/imap-login/client-authenticate.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap-login/client-authenticate.c	Wed Oct 03 18:17:26 2012 +0300
@@ -9,7 +9,7 @@
 #include "safe-memset.h"
 #include "str.h"
 #include "str-sanitize.h"
-#include "network.h"
+#include "net.h"
 #include "imap-resp-code.h"
 #include "imap-parser.h"
 #include "imap-url.h"
--- a/src/imap-login/client.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap-login/client.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CLIENT_H
 #define CLIENT_H
 
-#include "network.h"
+#include "net.h"
 #include "client-common.h"
 
 /* Master prefix is: <1|0><imap tag><NUL> */
--- a/src/imap-urlauth/imap-urlauth-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "imap-urlauth-common.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "fdpass.h"
 #include "istream.h"
 #include "ostream.h"
--- a/src/imap-urlauth/imap-urlauth-login.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-login.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "str.h"
 #include "strescape.h"
 #include "base64.h"
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
--- a/src/imap-urlauth/imap-urlauth-worker.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap-urlauth/imap-urlauth-worker.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "fdpass.h"
 #include "istream.h"
 #include "ostream.h"
--- a/src/imap/cmd-idle.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap/cmd-idle.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
 
 #include "imap-common.h"
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
--- a/src/imap/cmd-urlfetch.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap/cmd-urlfetch.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "strfuncs.h"
 #include "str.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "imap-url.h"
--- a/src/imap/imap-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/imap/imap-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -5,7 +5,7 @@
 #include "llist.h"
 #include "str.h"
 #include "hostpid.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "time-util.h"
--- a/src/lib-auth/auth-client.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-auth/auth-client.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef AUTH_CLIENT_H
 #define AUTH_CLIENT_H
 
-#include "network.h"
+#include "net.h"
 #include "auth-client-interface.h"
 
 struct auth_client;
--- a/src/lib-auth/auth-master.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-auth/auth-master.c	Wed Oct 03 18:17:26 2012 +0300
@@ -5,7 +5,7 @@
 #include "array.h"
 #include "ioloop.h"
 #include "eacces-error.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
--- a/src/lib-auth/auth-master.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-auth/auth-master.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef AUTH_MASTER_H
 #define AUTH_MASTER_H
 
-#include "network.h"
+#include "net.h"
 
 enum auth_master_flags {
 	/* Enable logging debug information */
--- a/src/lib-auth/auth-server-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-auth/auth-server-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -7,7 +7,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
-#include "network.h"
+#include "net.h"
 #include "eacces-error.h"
 #include "auth-client-private.h"
 #include "auth-client-request.h"
--- a/src/lib-dict/dict-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-dict/dict-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "llist.h"
 #include "str.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "eacces-error.h"
--- a/src/lib-dns/dns-lookup.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-dns/dns-lookup.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "write-full.h"
 #include "time-util.h"
--- a/src/lib-imap-client/imapc-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap-client/imapc-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "base64.h"
--- a/src/lib-imap-storage/imap-msgpart-url.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap-storage/imap-msgpart-url.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "message-parser.h"
 #include "mail-storage.h"
--- a/src/lib-imap-urlauth/imap-urlauth-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -8,7 +8,7 @@
 #include "ioloop.h"
 #include "safe-mkstemp.h"
 #include "hostpid.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "write-full.h"
--- a/src/lib-imap-urlauth/imap-urlauth-fetch.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap-urlauth/imap-urlauth-fetch.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "llist.h"
 #include "array.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "mail-user.h"
 #include "mail-error.h"
--- a/src/lib-imap/imap-url.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap/imap-url.c	Wed Oct 03 18:17:26 2012 +0300
@@ -6,7 +6,7 @@
 #include "strfuncs.h"
 #include "str-sanitize.h"
 #include "hex-binary.h"
-#include "network.h"
+#include "net.h"
 #include "iso8601-date.h"
 #include "uri-util.h"
 
--- a/src/lib-imap/test-imap-url.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-imap/test-imap-url.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "imap-url.h"
 #include "test-common.h"
 
--- a/src/lib-lda/lmtp-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-lda/lmtp-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
--- a/src/lib-lda/lmtp-client.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-lda/lmtp-client.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef LMTP_CLIENT_H
 #define LMTP_CLIENT_H
 
-#include "network.h"
+#include "net.h"
 
 #define ERRSTR_TEMP_REMOTE_FAILURE "451 4.4.0 Remote server not answering"
 
--- a/src/lib-master/anvil-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/anvil-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "array.h"
--- a/src/lib-master/ipc-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/ipc-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "hostpid.h"
--- a/src/lib-master/ipc-server.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/ipc-server.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "hostpid.h"
--- a/src/lib-master/master-auth.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/master-auth.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MASTER_AUTH_H
 #define MASTER_AUTH_H
 
-#include "network.h"
+#include "net.h"
 
 struct master_service;
 
--- a/src/lib-master/master-login-auth.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/master-login-auth.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "hostpid.h"
 #include "istream.h"
--- a/src/lib-master/master-service-settings.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/master-service-settings.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MASTER_SERVICE_SETTINGS_H
 #define MASTER_SERVICE_SETTINGS_H
 
-#include "network.h"
+#include "net.h"
 
 struct setting_parser_info;
 struct setting_parser_context;
--- a/src/lib-master/master-service.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-master/master-service.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MASTER_SERVICE_H
 #define MASTER_SERVICE_H
 
-#include "network.h"
+#include "net.h"
 
 enum master_service_flags {
 	/* stdin/stdout already contains a client which we want to serve */
--- a/src/lib-settings/settings-parser.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-settings/settings-parser.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "hash.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "env-util.h"
 #include "execv-const.h"
--- a/src/lib-storage/index/pop3c/pop3c-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-storage/index/pop3c/pop3c-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "istream-dot.h"
 #include "istream-seekable.h"
--- a/src/lib-storage/mail-storage-service.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-storage/mail-storage-service.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MAIL_STORAGE_SERVICE_H
 #define MAIL_STORAGE_SERVICE_H
 
-#include "network.h"
+#include "net.h"
 
 struct master_service;
 struct mail_user;
--- a/src/lib-storage/mail-user.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib-storage/mail-user.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "hostpid.h"
-#include "network.h"
+#include "net.h"
 #include "module-dir.h"
 #include "home-expand.h"
 #include "safe-mkstemp.h"
--- a/src/lib/Makefile.am	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/Makefile.am	Wed Oct 03 18:17:26 2012 +0300
@@ -93,7 +93,7 @@
 	mmap-util.c \
 	module-dir.c \
 	mountpoint.c \
-	network.c \
+	net.c \
 	nfs-workarounds.c \
 	numpack.c \
 	ostream.c \
@@ -207,7 +207,7 @@
 	module-context.h \
 	module-dir.h \
 	mountpoint.h \
-	network.h \
+	net.h \
 	nfs-workarounds.h \
 	numpack.h \
 	ostream.h \
--- a/src/lib/connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "ioloop.h"
 #include "istream.h"
 #include "ostream.h"
-#include "network.h"
+#include "net.h"
 #include "strescape.h"
 #include "llist.h"
 #include "connection.h"
--- a/src/lib/connection.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/connection.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CONNECTION_H
 #define CONNECTION_H
 
-#include "network.h"
+#include "net.h"
 
 struct connection;
 
--- a/src/lib/failures.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/failures.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "ioloop.h"
 #include "str.h"
 #include "hostpid.h"
-#include "network.h"
+#include "net.h"
 #include "lib-signals.h"
 #include "backtrace-string.h"
 #include "printf-format-fix.h"
--- a/src/lib/fd-close-on-exec.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/fd-close-on-exec.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "fd-close-on-exec.h"
 
 #include <unistd.h>
--- a/src/lib/ioloop-notify-inotify.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/ioloop-notify-inotify.c	Wed Oct 03 18:17:26 2012 +0300
@@ -10,7 +10,7 @@
 #include "ioloop-private.h"
 #include "ioloop-notify-fd.h"
 #include "buffer.h"
-#include "network.h"
+#include "net.h"
 #include "ipwd.h"
 
 #include <stdio.h>
--- a/src/lib/istream-file.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/istream-file.c	Wed Oct 03 18:17:26 2012 +0300
@@ -5,7 +5,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "istream-private.h"
-#include "network.h"
+#include "net.h"
 
 #include <time.h>
 #include <unistd.h>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/net.c	Wed Oct 03 18:17:26 2012 +0300
@@ -0,0 +1,1023 @@
+/* Copyright (c) 1999-2012 Dovecot authors, see the included COPYING file */
+
+#define _GNU_SOURCE /* For Linux's struct ucred */
+#include "lib.h"
+#include "fd-set-nonblock.h"
+#include "time-util.h"
+#include "net.h"
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <sys/un.h>
+#include <netinet/tcp.h>
+#if defined(HAVE_UCRED_H)
+#  include <ucred.h> /* for getpeerucred() */
+#elif defined(HAVE_SYS_UCRED_H)
+#  include <sys/ucred.h> /* for FreeBSD struct xucred */
+#endif
+
+union sockaddr_union {
+	struct sockaddr sa;
+	struct sockaddr_in sin;
+#ifdef HAVE_IPV6
+	struct sockaddr_in6 sin6;
+#endif
+};
+
+union sockaddr_union_unix {
+	struct sockaddr sa;
+	struct sockaddr_un un;
+};
+
+#ifdef HAVE_IPV6
+#  define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \
+	sizeof(so.sin6) : sizeof(so.sin))
+#else
+#  define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
+#endif
+
+bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2)
+{
+	return net_ip_cmp(ip1, ip2) == 0;
+}
+
+int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
+{
+	if (ip1->family != ip2->family)
+		return ip1->family - ip2->family;
+
+#ifdef HAVE_IPV6
+	if (ip1->family == AF_INET6)
+		return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));
+#endif
+
+	return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
+}
+
+unsigned int net_ip_hash(const struct ip_addr *ip)
+{
+        const unsigned char *p;
+	unsigned int len, g, h = 0;
+
+#ifdef HAVE_IPV6
+	if (ip->family == AF_INET6) {
+		p = ip->u.ip6.s6_addr;
+		len = sizeof(ip->u.ip6);
+	} else
+#endif
+	{
+		return ip->u.ip4.s_addr;
+	}
+
+	for (; len > 0; len--, p++) {
+		h = (h << 4) + *p;
+		if ((g = h & 0xf0000000UL)) {
+			h = h ^ (g >> 24);
+			h = h ^ g;
+		}
+	}
+
+	return h;
+}
+
+/* copy IP to sockaddr */
+static inline void
+sin_set_ip(union sockaddr_union *so, const struct ip_addr *ip)
+{
+	if (ip == NULL) {
+#ifdef HAVE_IPV6
+		so->sin6.sin6_family = AF_INET6;
+		so->sin6.sin6_addr = in6addr_any;
+#else
+		so->sin.sin_family = AF_INET;
+		so->sin.sin_addr.s_addr = INADDR_ANY;
+#endif
+		return;
+	}
+
+	so->sin.sin_family = ip->family;
+#ifdef HAVE_IPV6
+	if (ip->family == AF_INET6)
+		memcpy(&so->sin6.sin6_addr, &ip->u.ip6, sizeof(ip->u.ip6));
+	else
+#endif
+		memcpy(&so->sin.sin_addr, &ip->u.ip4, sizeof(ip->u.ip4));
+}
+
+static inline void
+sin_get_ip(const union sockaddr_union *so, struct ip_addr *ip)
+{
+	/* IP structs may be sent across processes. Clear the whole struct
+	   first to make sure it won't leak any data across processes. */
+	memset(ip, 0, sizeof(*ip));
+
+	ip->family = so->sin.sin_family;
+
+#ifdef HAVE_IPV6
+	if (ip->family == AF_INET6)
+		memcpy(&ip->u.ip6, &so->sin6.sin6_addr, sizeof(ip->u.ip6));
+	else
+#endif
+	if (ip->family == AF_INET)
+		memcpy(&ip->u.ip4, &so->sin.sin_addr, sizeof(ip->u.ip4));
+	else
+		memset(&ip->u, 0, sizeof(ip->u));
+}
+
+static inline void sin_set_port(union sockaddr_union *so, unsigned int port)
+{
+#ifdef HAVE_IPV6
+	if (so->sin.sin_family == AF_INET6)
+                so->sin6.sin6_port = htons((unsigned short) port);
+	else
+#endif
+		so->sin.sin_port = htons((unsigned short) port);
+}
+
+static inline unsigned int sin_get_port(union sockaddr_union *so)
+{
+#ifdef HAVE_IPV6
+	if (so->sin.sin_family == AF_INET6)
+		return ntohs(so->sin6.sin6_port);
+#endif
+	if (so->sin.sin_family == AF_INET)
+		return ntohs(so->sin.sin_port);
+
+	return 0;
+}
+
+#ifdef __FreeBSD__
+static int
+net_connect_ip_full_freebsd(const struct ip_addr *ip, unsigned int port,
+			    const struct ip_addr *my_ip, bool blocking);
+
+static int net_connect_ip_full(const struct ip_addr *ip, unsigned int port,
+			       const struct ip_addr *my_ip, bool blocking)
+{
+	int fd, try;
+
+	for (try = 0;;) {
+		fd = net_connect_ip_full_freebsd(ip, port, my_ip, blocking);
+		if (fd != -1 || ++try == 5 ||
+		    (errno != EADDRINUSE && errno != EACCES))
+			break;
+		/*
+		   This may be just a temporary problem:
+
+		   EADDRINUSE: busy
+		   EACCES: pf may cause this if another connection used
+		           the same port recently
+		*/
+	}
+	return fd;
+}
+/* then some kludging: */
+#define net_connect_ip_full net_connect_ip_full_freebsd
+#endif
+
+static int net_connect_ip_full(const struct ip_addr *ip, unsigned int port,
+			       const struct ip_addr *my_ip, bool blocking)
+{
+	union sockaddr_union so;
+	int fd, ret, opt = 1;
+
+	if (my_ip != NULL && ip->family != my_ip->family) {
+		i_warning("net_connect_ip(): ip->family != my_ip->family");
+                my_ip = NULL;
+	}
+
+	/* create the socket */
+	memset(&so, 0, sizeof(so));
+        so.sin.sin_family = ip->family;
+	fd = socket(ip->family, SOCK_STREAM, 0);
+
+	if (fd == -1) {
+		i_error("socket() failed: %m");
+		return -1;
+	}
+
+	/* set socket options */
+	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+	setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
+	if (!blocking)
+		net_set_nonblock(fd, TRUE);
+
+	/* set our own address */
+	if (my_ip != NULL) {
+		sin_set_ip(&so, my_ip);
+		if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
+			i_error("bind(%s) failed: %m", net_ip2addr(my_ip));
+			i_close_fd(&fd);
+			return -1;
+		}
+	}
+
+	/* connect */
+	sin_set_ip(&so, ip);
+	sin_set_port(&so, port);
+	ret = connect(fd, &so.sa, SIZEOF_SOCKADDR(so));
+
+#ifndef WIN32
+	if (ret < 0 && errno != EINPROGRESS)
+#else
+	if (ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK)
+#endif
+	{
+                i_close_fd(&fd);
+		return -1;
+	}
+
+	return fd;
+}
+#ifdef __FreeBSD__
+#  undef net_connect_ip_full
+#endif
+
+int net_connect_ip(const struct ip_addr *ip, unsigned int port,
+		   const struct ip_addr *my_ip)
+{
+	return net_connect_ip_full(ip, port, my_ip, FALSE);
+}
+
+int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port,
+			    const struct ip_addr *my_ip)
+{
+	return net_connect_ip_full(ip, port, my_ip, TRUE);
+}
+
+int net_try_bind(const struct ip_addr *ip)
+{
+	union sockaddr_union so;
+	int fd;
+
+	/* create the socket */
+	memset(&so, 0, sizeof(so));
+        so.sin.sin_family = ip->family;
+	fd = socket(ip->family, SOCK_STREAM, 0);
+	if (fd == -1) {
+		i_error("socket() failed: %m");
+		return -1;
+	}
+
+	sin_set_ip(&so, ip);
+	if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
+		i_close_fd(&fd);
+		return -1;
+	}
+	i_close_fd(&fd);
+	return 0;
+}
+
+int net_connect_unix(const char *path)
+{
+	union sockaddr_union_unix sa;
+	int fd, ret;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.un.sun_family = AF_UNIX;
+	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
+		/* too long path */
+		errno = EINVAL;
+		return -1;
+	}
+
+	/* create the socket */
+	fd = socket(PF_UNIX, SOCK_STREAM, 0);
+	if (fd == -1) {
+		i_error("socket(%s) failed: %m", path);
+		return -1;
+	}
+
+	net_set_nonblock(fd, TRUE);
+
+	/* connect */
+	ret = connect(fd, &sa.sa, sizeof(sa));
+	if (ret < 0 && errno != EINPROGRESS) {
+                i_close_fd(&fd);
+		return -1;
+	}
+
+	return fd;
+}
+
+int net_connect_unix_with_retries(const char *path, unsigned int msecs)
+{
+	struct timeval start, now;
+	int fd;
+
+	if (gettimeofday(&start, NULL) < 0)
+		i_panic("gettimeofday() failed: %m");
+
+	do {
+		fd = net_connect_unix(path);
+		if (fd != -1 || (errno != EAGAIN && errno != ECONNREFUSED))
+			break;
+
+		/* busy. wait for a while. */
+		usleep(((rand() % 10) + 1) * 10000);
+		if (gettimeofday(&now, NULL) < 0)
+			i_panic("gettimeofday() failed: %m");
+	} while (timeval_diff_msecs(&now, &start) < (int)msecs);
+	return fd;
+}
+
+void net_disconnect(int fd)
+{
+	/* FreeBSD's close() fails with ECONNRESET if socket still has unsent
+	   data in transmit buffer. We don't care. */
+	if (close(fd) < 0 && errno != ECONNRESET)
+		i_error("net_disconnect() failed: %m");
+}
+
+void net_set_nonblock(int fd, bool nonblock)
+{
+	fd_set_nonblock(fd, nonblock);
+}
+
+int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED)
+{
+#ifdef TCP_CORK
+	int val = cork;
+
+	return setsockopt(fd, IPPROTO_TCP, TCP_CORK, &val, sizeof(val));
+#else
+	errno = ENOPROTOOPT;
+	return -1;
+#endif
+}
+
+void net_get_ip_any4(struct ip_addr *ip)
+{
+	ip->family = AF_INET;
+	ip->u.ip4.s_addr = INADDR_ANY;
+}
+
+void net_get_ip_any6(struct ip_addr *ip)
+{
+#ifdef HAVE_IPV6
+	ip->family = AF_INET6;
+	ip->u.ip6 = in6addr_any;
+#else
+	memset(ip, 0, sizeof(struct ip_addr));
+#endif
+}
+
+int net_listen(const struct ip_addr *my_ip, unsigned int *port, int backlog)
+{
+	union sockaddr_union so;
+	int ret, fd, opt = 1;
+	socklen_t len;
+
+	memset(&so, 0, sizeof(so));
+	sin_set_port(&so, *port);
+	sin_set_ip(&so, my_ip);
+
+	/* create the socket */
+	fd = socket(so.sin.sin_family, SOCK_STREAM, 0);
+#ifdef HAVE_IPV6
+	if (fd == -1 && my_ip == NULL &&
+	    (errno == EINVAL || errno == EAFNOSUPPORT)) {
+		/* IPv6 is not supported by OS */
+		so.sin.sin_family = AF_INET;
+		so.sin.sin_addr.s_addr = INADDR_ANY;
+
+		fd = socket(AF_INET, SOCK_STREAM, 0);
+	}
+#endif
+	if (fd == -1) {
+		i_error("socket() failed: %m");
+		return -1;
+	}
+
+	/* set socket options */
+	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
+	setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
+
+	/* If using IPv6, bind only to IPv6 if possible. This avoids
+	   ambiguities with IPv4-mapped IPv6 addresses. */
+#ifdef IPV6_V6ONLY
+	if (so.sin.sin_family == AF_INET6) {
+		opt = 1;
+		setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
+	}
+#endif
+	/* specify the address/port we want to listen in */
+	ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so));
+	if (ret < 0) {
+		if (errno != EADDRINUSE) {
+			i_error("bind(%s, %u) failed: %m",
+				my_ip == NULL ? "" : net_ip2addr(my_ip), *port);
+		}
+	} else {
+		/* get the actual port we started listen */
+		len = SIZEOF_SOCKADDR(so);
+		ret = getsockname(fd, &so.sa, &len);
+		if (ret >= 0) {
+			*port = sin_get_port(&so);
+
+			/* start listening */
+			if (listen(fd, backlog) >= 0)
+				return fd;
+
+			if (errno != EADDRINUSE)
+				i_error("listen() failed: %m");
+		}
+	}
+
+        /* error */
+	i_close_fd(&fd);
+	return -1;
+}
+
+int net_listen_unix(const char *path, int backlog)
+{
+	union {
+		struct sockaddr sa;
+		struct sockaddr_un un;
+	} sa;
+	int fd;
+
+	memset(&sa, 0, sizeof(sa));
+	sa.un.sun_family = AF_UNIX;
+	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
+		/* too long path */
+		errno = EINVAL;
+		return -1;
+	}
+
+	/* create the socket */
+	fd = socket(PF_UNIX, SOCK_STREAM, 0);
+	if (fd == -1) {
+		i_error("socket() failed: %m");
+		return -1;
+	}
+
+	/* bind */
+	if (bind(fd, &sa.sa, sizeof(sa)) < 0) {
+		if (errno != EADDRINUSE)
+			i_error("bind(%s) failed: %m", path);
+	} else {
+		/* start listening */
+		if (listen(fd, backlog) == 0)
+			return fd;
+
+		if (errno != EADDRINUSE)
+			i_error("listen() failed: %m");
+	}
+
+	i_close_fd(&fd);
+	return -1;
+}
+
+int net_listen_unix_unlink_stale(const char *path, int backlog)
+{
+	unsigned int i = 0;
+	int fd;
+
+	while ((fd = net_listen_unix(path, backlog)) == -1) {
+		if (errno != EADDRINUSE || ++i == 2)
+			return -1;
+
+		/* see if it really exists */
+		fd = net_connect_unix(path);
+		if (fd != -1 || errno != ECONNREFUSED) {
+			if (fd != -1) i_close_fd(&fd);
+			errno = EADDRINUSE;
+			return -1;
+		}
+
+		/* delete and try again */
+		if (unlink(path) < 0 && errno != ENOENT) {
+			i_error("unlink(%s) failed: %m", path);
+			errno = EADDRINUSE;
+			return -1;
+		}
+	}
+	return fd;
+}
+
+int net_accept(int fd, struct ip_addr *addr_r, unsigned int *port_r)
+{
+	union sockaddr_union so;
+	int ret;
+	socklen_t addrlen;
+
+	i_assert(fd >= 0);
+
+	addrlen = sizeof(so);
+	ret = accept(fd, &so.sa, &addrlen);
+
+	if (ret < 0) {
+		if (errno == EAGAIN || errno == ECONNABORTED)
+			return -1;
+		else
+			return -2;
+	}
+	if (so.sin.sin_family == AF_UNIX) {
+		if (addr_r != NULL)
+			memset(addr_r, 0, sizeof(*addr_r));
+		if (port_r != NULL) *port_r = 0;
+	} else {
+		if (addr_r != NULL) sin_get_ip(&so, addr_r);
+		if (port_r != NULL) *port_r = sin_get_port(&so);
+	}
+	return ret;
+}
+
+ssize_t net_receive(int fd, void *buf, size_t len)
+{
+	ssize_t ret;
+
+	i_assert(fd >= 0);
+	i_assert(len <= SSIZE_T_MAX);
+
+	ret = read(fd, buf, len);
+	if (ret == 0) {
+		/* disconnected */
+		errno = 0;
+		return -2;
+	}
+
+	if (unlikely(ret < 0)) {
+		if (errno == EINTR || errno == EAGAIN)
+			return 0;
+
+		if (errno == ECONNRESET || errno == ETIMEDOUT) {
+                        /* treat as disconnection */
+			return -2;
+		}
+	}
+
+	return ret;
+}
+
+ssize_t net_transmit(int fd, const void *data, size_t len)
+{
+        ssize_t ret;
+
+	i_assert(fd >= 0);
+	i_assert(len <= SSIZE_T_MAX);
+
+	ret = send(fd, data, len, 0);
+	if (unlikely(ret == -1 && (errno == EINTR || errno == EAGAIN)))
+		return 0;
+
+	if (unlikely(errno == EPIPE))
+		return -2;
+
+        return ret;
+}
+
+int net_gethostbyname(const char *addr, struct ip_addr **ips,
+		      unsigned int *ips_count)
+{
+	/* @UNSAFE */
+#ifdef HAVE_IPV6
+	union sockaddr_union *so;
+	struct addrinfo hints, *ai, *origai;
+	int host_error;
+#else
+	struct hostent *hp;
+#endif
+        int count;
+
+	*ips = NULL;
+        *ips_count = 0;
+
+#ifdef HAVE_IPV6
+	memset(&hints, 0, sizeof(struct addrinfo));
+	hints.ai_socktype = SOCK_STREAM;
+
+	/* save error to host_error for later use */
+	host_error = getaddrinfo(addr, NULL, &hints, &ai);
+	if (host_error != 0)
+		return host_error;
+
+        /* get number of IPs */
+        origai = ai;
+	for (count = 0; ai != NULL; ai = ai->ai_next)
+                count++;
+
+        *ips_count = count;
+        *ips = t_malloc(sizeof(struct ip_addr) * count);
+
+        count = 0;
+	for (ai = origai; ai != NULL; ai = ai->ai_next, count++) {
+		so = (union sockaddr_union *) ai->ai_addr;
+
+		sin_get_ip(so, &(*ips)[count]);
+	}
+	freeaddrinfo(origai);
+#else
+	hp = gethostbyname(addr);
+	if (hp == NULL)
+		return h_errno;
+
+        /* get number of IPs */
+	count = 0;
+	while (hp->h_addr_list[count] != NULL)
+		count++;
+
+        *ips_count = count;
+        *ips = t_malloc(sizeof(struct ip_addr) * count);
+
+	while (count > 0) {
+		count--;
+
+		(*ips)[count].family = AF_INET;
+		memcpy(&(*ips)[count].u.ip4, hp->h_addr_list[count],
+		       sizeof((*ips)[count].u.ip4));
+	}
+#endif
+
+	return 0;
+}
+
+int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
+{
+	union sockaddr_union so;
+	socklen_t addrlen;
+
+	i_assert(fd >= 0);
+
+	addrlen = sizeof(so);
+	if (getsockname(fd, &so.sa, &addrlen) == -1)
+		return -1;
+	if (so.sin.sin_family == AF_UNIX) {
+		if (addr != NULL)
+			memset(addr, 0, sizeof(*addr));
+		if (port != NULL) *port = 0;
+	} else {
+		if (addr != NULL) sin_get_ip(&so, addr);
+		if (port != NULL) *port = sin_get_port(&so);
+	}
+	return 0;
+}
+
+int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port)
+{
+	union sockaddr_union so;
+	socklen_t addrlen;
+
+	i_assert(fd >= 0);
+
+	addrlen = sizeof(so);
+	if (getpeername(fd, &so.sa, &addrlen) == -1)
+		return -1;
+	if (so.sin.sin_family == AF_UNIX) {
+		if (addr != NULL)
+			memset(addr, 0, sizeof(*addr));
+		if (port != NULL) *port = 0;
+	} else {
+		if (addr != NULL) sin_get_ip(&so, addr);
+		if (port != NULL) *port = sin_get_port(&so);
+	}
+	return 0;
+}
+
+int net_getunixname(int fd, const char **name_r)
+{
+	union sockaddr_union_unix so;
+	socklen_t addrlen = sizeof(so);
+
+	if (getsockname(fd, &so.sa, &addrlen) < 0)
+		return -1;
+	if (so.un.sun_family != AF_UNIX) {
+		errno = ENOTSOCK;
+		return -1;
+	}
+	*name_r = t_strdup(so.un.sun_path);
+	return 0;
+}
+
+int net_getunixcred(int fd, struct net_unix_cred *cred_r)
+{
+#if defined(SO_PEERCRED)
+# if defined(HAVE_STRUCT_SOCKPEERCRED)
+	/* OpenBSD (may also provide getpeereid, but we also want pid) */
+	struct sockpeercred ucred;
+# else
+	/* Linux */
+	struct ucred ucred;
+# endif
+	socklen_t len = sizeof(ucred);
+
+	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) {
+		i_error("getsockopt(SO_PEERCRED) failed: %m");
+		return -1;
+	}
+	cred_r->uid = ucred.uid;
+	cred_r->gid = ucred.gid;
+	cred_r->pid = ucred.pid;
+	return 0;
+#elif defined(LOCAL_PEEREID)
+	/* NetBSD (may also provide getpeereid, but we also want pid) */
+	struct unpcbid ucred;
+	socklen_t len = sizeof(ucred);
+
+	if (getsockopt(s, 0, LOCAL_PEEREID, &ucred, &len) < 0) {
+		i_error("getsockopt(LOCAL_PEEREID) failed: %m");
+		return -1;
+	}
+	
+	cred_r->uid = ucred.unp_euid;
+	cred_r->gid = ucred.unp_egid;
+	cred_r->pid = ucred.unp_pid;
+	return 0;
+#elif defined(HAVE_GETPEEREID)
+	/* OSX 10.4+, FreeBSD 4.6+, OpenBSD 3.0+, NetBSD 5.0+ */
+	if (getpeereid(fd, &cred_r->uid, &cred_r->gid) < 0) {
+		i_error("getpeereid() failed: %m");
+		return -1;
+	}
+	cred_r->pid = (pid_t)-1;
+	return 0;
+#elif defined(LOCAL_PEERCRED)
+	/* Older FreeBSD */
+	struct xucred ucred;
+	socklen_t len = sizeof(ucred);
+
+	if (getsockopt(fd, 0, LOCAL_PEERCRED, &ucred, &len) < 0) {
+		i_error("getsockopt(LOCAL_PEERCRED) failed: %m");
+		return -1;
+	}
+
+	if (ucred.cr_version != XUCRED_VERSION) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	cred_r->uid = ucred.cr_uid;
+	cred_r->gid = ucred.cr_gid;
+	cred_r->pid = (pid_t)-1;
+	return 0;
+#elif defined(HAVE_GETPEERUCRED)
+	/* Solaris */
+	ucred_t *ucred = NULL;
+
+	if (getpeerucred(fd, &ucred) < 0) {
+		i_error("getpeerucred() failed: %m");
+		return -1;
+	}
+	cred_r->uid = ucred_geteuid(ucred);
+	cred_r->gid = ucred_getrgid(ucred);
+	cred_r->pid = ucred_getpid(ucred);
+	ucred_free(ucred);
+
+	if (cred_r->uid == (uid_t)-1 ||
+	    cred_r->gid == (gid_t)-1) {
+		errno = EINVAL;
+		return -1;
+	}
+	return 0;
+#else
+	errno = EINVAL;
+	return -1;
+#endif
+}
+
+const char *net_ip2addr(const struct ip_addr *ip)
+{
+#ifdef HAVE_IPV6
+	char addr[MAX_IP_LEN+1];
+
+	addr[MAX_IP_LEN] = '\0';
+	if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL)
+		return NULL;
+
+	return t_strdup(addr);
+#else
+	unsigned long ip4;
+
+	if (ip->family != AF_INET)
+		return NULL;
+
+	ip4 = ntohl(ip->u.ip4.s_addr);
+	return t_strdup_printf("%lu.%lu.%lu.%lu",
+			       (ip4 & 0xff000000UL) >> 24,
+			       (ip4 & 0x00ff0000) >> 16,
+			       (ip4 & 0x0000ff00) >> 8,
+			       (ip4 & 0x000000ff));
+#endif
+}
+
+int net_addr2ip(const char *addr, struct ip_addr *ip)
+{
+	int ret;
+
+	if (strchr(addr, ':') != NULL) {
+		/* IPv6 */
+		ip->family = AF_INET6;
+#ifdef HAVE_IPV6
+		T_BEGIN {
+			if (addr[0] == '[') {
+				/* allow [ipv6 addr] */
+				unsigned int len = strlen(addr);
+				if (addr[len-1] == ']')
+					addr = t_strndup(addr+1, len-2);
+			}
+			ret = inet_pton(AF_INET6, addr, &ip->u.ip6);
+		} T_END;
+		if (ret == 0)
+			return -1;
+#else
+		ip->u.ip4.s_addr = 0;
+#endif
+ 	} else {
+		/* IPv4 */
+		ip->family = AF_INET;
+		if (inet_aton(addr, &ip->u.ip4) == 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
+				 struct ip_addr *dest)
+{
+#ifdef HAVE_IPV6
+	static uint8_t v4_prefix[] =
+		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
+
+	if (!IPADDR_IS_V6(src))
+		return -1;
+	if (memcmp(src->u.ip6.s6_addr, v4_prefix, sizeof(v4_prefix)) != 0)
+		return -1;
+
+	dest->family = AF_INET;
+	memcpy(&dest->u.ip6, &src->u.ip6.s6_addr[3*4], 4);
+	return 0;
+#else
+	return -1;
+#endif
+}
+
+int net_geterror(int fd)
+{
+	int data;
+	socklen_t len = sizeof(data);
+
+	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1)
+		return -1;
+
+	return data;
+}
+
+const char *net_gethosterror(int error)
+{
+#ifdef HAVE_IPV6
+	i_assert(error != 0);
+
+	return gai_strerror(error);
+#else
+	switch (error) {
+	case HOST_NOT_FOUND:
+		return "Host not found";
+	case NO_ADDRESS:
+		return "No IP address found for name";
+	case NO_RECOVERY:
+		return "A non-recoverable name server error occurred";
+	case TRY_AGAIN:
+		return "A temporary error on an authoritative name server";
+	}
+
+	/* unknown error */
+	return NULL;
+#endif
+}
+
+int net_hosterror_notfound(int error)
+{
+#ifdef HAVE_IPV6
+#ifdef EAI_NODATA /* NODATA is depricated */
+	return error != 1 && (error == EAI_NONAME || error == EAI_NODATA);
+#else
+	return error != 1 && (error == EAI_NONAME);
+#endif
+#else
+	return error == HOST_NOT_FOUND || error == NO_ADDRESS;
+#endif
+}
+
+const char *net_getservbyport(unsigned short port)
+{
+	struct servent *entry;
+
+	entry = getservbyport(htons(port), "tcp");
+	return entry == NULL ? NULL : entry->s_name;
+}
+
+bool is_ipv4_address(const char *addr)
+{
+	while (*addr != '\0') {
+		if (*addr != '.' && !i_isdigit(*addr))
+			return FALSE;
+                addr++;
+	}
+
+	return TRUE;
+}
+
+bool is_ipv6_address(const char *addr)
+{
+	bool have_prefix = FALSE;
+
+	if (*addr == '[') {
+		have_prefix = TRUE;
+		addr++;
+	}
+	while (*addr != '\0') {
+		if (*addr != ':' && !i_isxdigit(*addr)) {
+			if (have_prefix && *addr == ']' && addr[1] == '\0')
+				break;
+			return FALSE;
+		}
+                addr++;
+	}
+
+	return TRUE;
+}
+
+int net_parse_range(const char *network, struct ip_addr *ip_r,
+		    unsigned int *bits_r)
+{
+	const char *p;
+	unsigned int bits, max_bits;
+
+	p = strchr(network, '/');
+	if (p != NULL)
+		network = t_strdup_until(network, p++);
+
+	if (net_addr2ip(network, ip_r) < 0)
+		return -1;
+
+	max_bits = IPADDR_BITS(ip_r);
+	if (p == NULL) {
+		/* full IP address must match */
+		bits = max_bits;
+	} else {
+		/* get the network mask */
+		if (str_to_uint(p, &bits) < 0 || bits > max_bits)
+			return -1;
+	}
+	*bits_r = bits;
+	return 0;
+}
+
+bool net_is_in_network(const struct ip_addr *ip,
+		       const struct ip_addr *net_ip, unsigned int bits)
+{
+	struct ip_addr tmp_ip;
+	const uint32_t *ip1, *ip2;
+	uint32_t mask, i1, i2;
+	unsigned int pos, i;
+
+	if (net_ipv6_mapped_ipv4_convert(ip, &tmp_ip) == 0) {
+		/* IPv4 address mapped disguised as IPv6 address */
+		ip = &tmp_ip;
+	}
+
+	if (IPADDR_IS_V4(ip) != IPADDR_IS_V4(net_ip)) {
+		/* one is IPv6 and one is IPv4 */
+		return FALSE;
+	}
+	i_assert(IPADDR_IS_V6(ip) == IPADDR_IS_V6(net_ip));
+
+	if (IPADDR_IS_V4(ip)) {
+		ip1 = &ip->u.ip4.s_addr;
+		ip2 = &net_ip->u.ip4.s_addr;
+	} else {
+#ifdef HAVE_IPV6
+		ip1 = (const void *)&ip->u.ip6;
+		ip2 = (const void *)&net_ip->u.ip6;
+#else
+		/* shouldn't get here */
+		return FALSE;
+#endif
+	}
+
+	/* check first the full 32bit ints */
+	for (pos = 0, i = 0; pos + 32 <= bits; pos += 32, i++) {
+		if (ip1[i] != ip2[i])
+			return FALSE;
+	}
+	i1 = htonl(ip1[i]);
+	i2 = htonl(ip2[i]);
+
+	/* check the last full bytes */
+	for (mask = 0xff000000; pos + 8 <= bits; pos += 8, mask >>= 8) {
+		if ((i1 & mask) != (i2 & mask))
+			return FALSE;
+	}
+
+	/* check the last bits, they're reversed in bytes */
+	bits -= pos;
+	for (mask = 0x80000000 >> (pos % 32); bits > 0; bits--, mask >>= 1) {
+		if ((i1 & mask) != (i2 & mask))
+			return FALSE;
+	}
+	return TRUE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib/net.h	Wed Oct 03 18:17:26 2012 +0300
@@ -0,0 +1,152 @@
+#ifndef NET_H
+#define NET_H
+
+#ifndef WIN32
+#  include <sys/socket.h>
+#  include <netinet/in.h>
+#  include <netdb.h>
+#  include <arpa/inet.h>
+#endif
+
+#ifdef HAVE_SOCKS_H
+#include <socks.h>
+#endif
+
+#ifndef AF_INET6
+#  ifdef PF_INET6
+#    define AF_INET6 PF_INET6
+#  else
+#    define AF_INET6 10
+#  endif
+#endif
+
+struct ip_addr {
+	unsigned short family;
+	union {
+#ifdef HAVE_IPV6
+		struct in6_addr ip6;
+#endif
+		struct in_addr ip4;
+	} u;
+};
+ARRAY_DEFINE_TYPE(ip_addr, struct ip_addr);
+
+struct net_unix_cred {
+	uid_t uid;
+	gid_t gid;
+	pid_t pid;
+};
+
+/* maxmimum string length of IP address */
+#ifdef HAVE_IPV6
+#  define MAX_IP_LEN INET6_ADDRSTRLEN
+#else
+#  define MAX_IP_LEN 20
+#endif
+
+#define IPADDR_IS_V4(ip) ((ip)->family == AF_INET)
+#define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6)
+#define IPADDR_BITS(ip) (IPADDR_IS_V4(ip) ? 32 : 128)
+
+/* 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_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2);
+unsigned int net_ip_hash(const struct ip_addr *ip);
+
+/* Connect to socket with ip address. The socket and connect() is
+   non-blocking. */
+int net_connect_ip(const struct ip_addr *ip, unsigned int port,
+		   const struct ip_addr *my_ip) ATTR_NULL(3);
+/* Like net_connect_ip(), but do a blocking connect(). */
+int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port,
+			    const struct ip_addr *my_ip) ATTR_NULL(3);
+/* Returns 0 if we can bind() as given IP, -1 if not. */
+int net_try_bind(const struct ip_addr *ip);
+/* Connect to named UNIX socket */
+int net_connect_unix(const char *path);
+/* Try to connect to UNIX socket for give number of seconds when connect()
+   returns EAGAIN or ECONNREFUSED. */
+int net_connect_unix_with_retries(const char *path, unsigned int msecs);
+/* Disconnect socket */
+void net_disconnect(int fd);
+
+/* Set socket blocking/nonblocking */
+void net_set_nonblock(int fd, bool nonblock);
+/* Set TCP_CORK if supported, ie. don't send out partial frames.
+   Returns 0 if ok, -1 if failed. */
+int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;
+
+/* 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, unsigned int *port, int backlog);
+/* Listen for connections on an UNIX socket */
+int net_listen_unix(const char *path, int backlog);
+/* Like net_listen_unix(), but if socket already exists, try to connect to it.
+   If it fails with ECONNREFUSED, unlink the socket and try creating it
+   again. */
+int net_listen_unix_unlink_stale(const char *path, int backlog);
+/* Accept a connection on a socket. Returns -1 if the connection got closed,
+   -2 for other failures. For UNIX sockets addr_r->family=port=0. */
+int net_accept(int fd, struct ip_addr *addr_r, unsigned int *port_r)
+	ATTR_NULL(2, 3);
+
+/* Read data from socket, return number of bytes read,
+   -1 = error, -2 = disconnected */
+ssize_t net_receive(int fd, void *buf, size_t len);
+/* Transmit data, return number of bytes sent, -1 = error, -2 = disconnected */
+ssize_t net_transmit(int fd, const void *data, size_t len);
+
+/* Get IP addresses for host. ips contains ips_count of IPs, they don't need
+   to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
+int net_gethostbyname(const char *addr, struct ip_addr **ips,
+		      unsigned int *ips_count);
+/* get error of net_gethostname() */
+const char *net_gethosterror(int error) ATTR_CONST;
+/* return TRUE if host lookup failed because it didn't exist (ie. not
+   some error with name server) */
+int net_hosterror_notfound(int error) ATTR_CONST;
+
+/* Get socket local address/port. For UNIX sockets addr->family=port=0. */
+int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
+	ATTR_NULL(2, 3);
+/* Get socket remote address/port. For UNIX sockets addr->family=port=0. */
+int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port)
+	ATTR_NULL(2, 3);
+/* Get UNIX socket name. */
+int net_getunixname(int fd, const char **name_r);
+/* Get UNIX socket peer process's credentials. The pid may be (pid_t)-1 if
+   unavailable. */
+int net_getunixcred(int fd, struct net_unix_cred *cred_r);
+
+/* Returns ip_addr as string, or NULL if ip is invalid. */
+const char *net_ip2addr(const struct ip_addr *ip);
+/* char* -> struct ip_addr translation. */
+int net_addr2ip(const char *addr, struct ip_addr *ip);
+/* Convert IPv6 mapped IPv4 address to an actual IPv4 address. Returns 0 if
+   successful, -1 if the source address isn't IPv6 mapped IPv4 address. */
+int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
+				 struct ip_addr *dest);
+
+/* Get socket error */
+int net_geterror(int fd);
+
+/* Get name of TCP service */
+const char *net_getservbyport(unsigned short port) ATTR_CONST;
+
+bool is_ipv4_address(const char *addr) ATTR_PURE;
+bool is_ipv6_address(const char *addr) ATTR_PURE;
+
+/* Parse network as ip/bits. Returns 0 if successful, -1 if invalid input. */
+int net_parse_range(const char *network, struct ip_addr *ip_r,
+		    unsigned int *bits_r);
+/* Returns TRUE if ip is in net_ip/bits network. IPv6 mapped IPv4 addresses
+   are converted to plain IPv4 addresses before matching. */
+bool net_is_in_network(const struct ip_addr *ip, const struct ip_addr *net_ip,
+		       unsigned int bits) ATTR_PURE;
+
+#endif
--- a/src/lib/network.c	Wed Oct 03 16:57:28 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1023 +0,0 @@
-/* Copyright (c) 1999-2012 Dovecot authors, see the included COPYING file */
-
-#define _GNU_SOURCE /* For Linux's struct ucred */
-#include "lib.h"
-#include "fd-set-nonblock.h"
-#include "time-util.h"
-#include "network.h"
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <sys/un.h>
-#include <netinet/tcp.h>
-#if defined(HAVE_UCRED_H)
-#  include <ucred.h> /* for getpeerucred() */
-#elif defined(HAVE_SYS_UCRED_H)
-#  include <sys/ucred.h> /* for FreeBSD struct xucred */
-#endif
-
-union sockaddr_union {
-	struct sockaddr sa;
-	struct sockaddr_in sin;
-#ifdef HAVE_IPV6
-	struct sockaddr_in6 sin6;
-#endif
-};
-
-union sockaddr_union_unix {
-	struct sockaddr sa;
-	struct sockaddr_un un;
-};
-
-#ifdef HAVE_IPV6
-#  define SIZEOF_SOCKADDR(so) ((so).sa.sa_family == AF_INET6 ? \
-	sizeof(so.sin6) : sizeof(so.sin))
-#else
-#  define SIZEOF_SOCKADDR(so) (sizeof(so.sin))
-#endif
-
-bool net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2)
-{
-	return net_ip_cmp(ip1, ip2) == 0;
-}
-
-int net_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2)
-{
-	if (ip1->family != ip2->family)
-		return ip1->family - ip2->family;
-
-#ifdef HAVE_IPV6
-	if (ip1->family == AF_INET6)
-		return memcmp(&ip1->u.ip6, &ip2->u.ip6, sizeof(ip1->u.ip6));
-#endif
-
-	return memcmp(&ip1->u.ip4, &ip2->u.ip4, sizeof(ip1->u.ip4));
-}
-
-unsigned int net_ip_hash(const struct ip_addr *ip)
-{
-        const unsigned char *p;
-	unsigned int len, g, h = 0;
-
-#ifdef HAVE_IPV6
-	if (ip->family == AF_INET6) {
-		p = ip->u.ip6.s6_addr;
-		len = sizeof(ip->u.ip6);
-	} else
-#endif
-	{
-		return ip->u.ip4.s_addr;
-	}
-
-	for (; len > 0; len--, p++) {
-		h = (h << 4) + *p;
-		if ((g = h & 0xf0000000UL)) {
-			h = h ^ (g >> 24);
-			h = h ^ g;
-		}
-	}
-
-	return h;
-}
-
-/* copy IP to sockaddr */
-static inline void
-sin_set_ip(union sockaddr_union *so, const struct ip_addr *ip)
-{
-	if (ip == NULL) {
-#ifdef HAVE_IPV6
-		so->sin6.sin6_family = AF_INET6;
-		so->sin6.sin6_addr = in6addr_any;
-#else
-		so->sin.sin_family = AF_INET;
-		so->sin.sin_addr.s_addr = INADDR_ANY;
-#endif
-		return;
-	}
-
-	so->sin.sin_family = ip->family;
-#ifdef HAVE_IPV6
-	if (ip->family == AF_INET6)
-		memcpy(&so->sin6.sin6_addr, &ip->u.ip6, sizeof(ip->u.ip6));
-	else
-#endif
-		memcpy(&so->sin.sin_addr, &ip->u.ip4, sizeof(ip->u.ip4));
-}
-
-static inline void
-sin_get_ip(const union sockaddr_union *so, struct ip_addr *ip)
-{
-	/* IP structs may be sent across processes. Clear the whole struct
-	   first to make sure it won't leak any data across processes. */
-	memset(ip, 0, sizeof(*ip));
-
-	ip->family = so->sin.sin_family;
-
-#ifdef HAVE_IPV6
-	if (ip->family == AF_INET6)
-		memcpy(&ip->u.ip6, &so->sin6.sin6_addr, sizeof(ip->u.ip6));
-	else
-#endif
-	if (ip->family == AF_INET)
-		memcpy(&ip->u.ip4, &so->sin.sin_addr, sizeof(ip->u.ip4));
-	else
-		memset(&ip->u, 0, sizeof(ip->u));
-}
-
-static inline void sin_set_port(union sockaddr_union *so, unsigned int port)
-{
-#ifdef HAVE_IPV6
-	if (so->sin.sin_family == AF_INET6)
-                so->sin6.sin6_port = htons((unsigned short) port);
-	else
-#endif
-		so->sin.sin_port = htons((unsigned short) port);
-}
-
-static inline unsigned int sin_get_port(union sockaddr_union *so)
-{
-#ifdef HAVE_IPV6
-	if (so->sin.sin_family == AF_INET6)
-		return ntohs(so->sin6.sin6_port);
-#endif
-	if (so->sin.sin_family == AF_INET)
-		return ntohs(so->sin.sin_port);
-
-	return 0;
-}
-
-#ifdef __FreeBSD__
-static int
-net_connect_ip_full_freebsd(const struct ip_addr *ip, unsigned int port,
-			    const struct ip_addr *my_ip, bool blocking);
-
-static int net_connect_ip_full(const struct ip_addr *ip, unsigned int port,
-			       const struct ip_addr *my_ip, bool blocking)
-{
-	int fd, try;
-
-	for (try = 0;;) {
-		fd = net_connect_ip_full_freebsd(ip, port, my_ip, blocking);
-		if (fd != -1 || ++try == 5 ||
-		    (errno != EADDRINUSE && errno != EACCES))
-			break;
-		/*
-		   This may be just a temporary problem:
-
-		   EADDRINUSE: busy
-		   EACCES: pf may cause this if another connection used
-		           the same port recently
-		*/
-	}
-	return fd;
-}
-/* then some kludging: */
-#define net_connect_ip_full net_connect_ip_full_freebsd
-#endif
-
-static int net_connect_ip_full(const struct ip_addr *ip, unsigned int port,
-			       const struct ip_addr *my_ip, bool blocking)
-{
-	union sockaddr_union so;
-	int fd, ret, opt = 1;
-
-	if (my_ip != NULL && ip->family != my_ip->family) {
-		i_warning("net_connect_ip(): ip->family != my_ip->family");
-                my_ip = NULL;
-	}
-
-	/* create the socket */
-	memset(&so, 0, sizeof(so));
-        so.sin.sin_family = ip->family;
-	fd = socket(ip->family, SOCK_STREAM, 0);
-
-	if (fd == -1) {
-		i_error("socket() failed: %m");
-		return -1;
-	}
-
-	/* set socket options */
-	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
-	setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
-	if (!blocking)
-		net_set_nonblock(fd, TRUE);
-
-	/* set our own address */
-	if (my_ip != NULL) {
-		sin_set_ip(&so, my_ip);
-		if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
-			i_error("bind(%s) failed: %m", net_ip2addr(my_ip));
-			i_close_fd(&fd);
-			return -1;
-		}
-	}
-
-	/* connect */
-	sin_set_ip(&so, ip);
-	sin_set_port(&so, port);
-	ret = connect(fd, &so.sa, SIZEOF_SOCKADDR(so));
-
-#ifndef WIN32
-	if (ret < 0 && errno != EINPROGRESS)
-#else
-	if (ret < 0 && WSAGetLastError() != WSAEWOULDBLOCK)
-#endif
-	{
-                i_close_fd(&fd);
-		return -1;
-	}
-
-	return fd;
-}
-#ifdef __FreeBSD__
-#  undef net_connect_ip_full
-#endif
-
-int net_connect_ip(const struct ip_addr *ip, unsigned int port,
-		   const struct ip_addr *my_ip)
-{
-	return net_connect_ip_full(ip, port, my_ip, FALSE);
-}
-
-int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port,
-			    const struct ip_addr *my_ip)
-{
-	return net_connect_ip_full(ip, port, my_ip, TRUE);
-}
-
-int net_try_bind(const struct ip_addr *ip)
-{
-	union sockaddr_union so;
-	int fd;
-
-	/* create the socket */
-	memset(&so, 0, sizeof(so));
-        so.sin.sin_family = ip->family;
-	fd = socket(ip->family, SOCK_STREAM, 0);
-	if (fd == -1) {
-		i_error("socket() failed: %m");
-		return -1;
-	}
-
-	sin_set_ip(&so, ip);
-	if (bind(fd, &so.sa, SIZEOF_SOCKADDR(so)) == -1) {
-		i_close_fd(&fd);
-		return -1;
-	}
-	i_close_fd(&fd);
-	return 0;
-}
-
-int net_connect_unix(const char *path)
-{
-	union sockaddr_union_unix sa;
-	int fd, ret;
-
-	memset(&sa, 0, sizeof(sa));
-	sa.un.sun_family = AF_UNIX;
-	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
-		/* too long path */
-		errno = EINVAL;
-		return -1;
-	}
-
-	/* create the socket */
-	fd = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (fd == -1) {
-		i_error("socket(%s) failed: %m", path);
-		return -1;
-	}
-
-	net_set_nonblock(fd, TRUE);
-
-	/* connect */
-	ret = connect(fd, &sa.sa, sizeof(sa));
-	if (ret < 0 && errno != EINPROGRESS) {
-                i_close_fd(&fd);
-		return -1;
-	}
-
-	return fd;
-}
-
-int net_connect_unix_with_retries(const char *path, unsigned int msecs)
-{
-	struct timeval start, now;
-	int fd;
-
-	if (gettimeofday(&start, NULL) < 0)
-		i_panic("gettimeofday() failed: %m");
-
-	do {
-		fd = net_connect_unix(path);
-		if (fd != -1 || (errno != EAGAIN && errno != ECONNREFUSED))
-			break;
-
-		/* busy. wait for a while. */
-		usleep(((rand() % 10) + 1) * 10000);
-		if (gettimeofday(&now, NULL) < 0)
-			i_panic("gettimeofday() failed: %m");
-	} while (timeval_diff_msecs(&now, &start) < (int)msecs);
-	return fd;
-}
-
-void net_disconnect(int fd)
-{
-	/* FreeBSD's close() fails with ECONNRESET if socket still has unsent
-	   data in transmit buffer. We don't care. */
-	if (close(fd) < 0 && errno != ECONNRESET)
-		i_error("net_disconnect() failed: %m");
-}
-
-void net_set_nonblock(int fd, bool nonblock)
-{
-	fd_set_nonblock(fd, nonblock);
-}
-
-int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED)
-{
-#ifdef TCP_CORK
-	int val = cork;
-
-	return setsockopt(fd, IPPROTO_TCP, TCP_CORK, &val, sizeof(val));
-#else
-	errno = ENOPROTOOPT;
-	return -1;
-#endif
-}
-
-void net_get_ip_any4(struct ip_addr *ip)
-{
-	ip->family = AF_INET;
-	ip->u.ip4.s_addr = INADDR_ANY;
-}
-
-void net_get_ip_any6(struct ip_addr *ip)
-{
-#ifdef HAVE_IPV6
-	ip->family = AF_INET6;
-	ip->u.ip6 = in6addr_any;
-#else
-	memset(ip, 0, sizeof(struct ip_addr));
-#endif
-}
-
-int net_listen(const struct ip_addr *my_ip, unsigned int *port, int backlog)
-{
-	union sockaddr_union so;
-	int ret, fd, opt = 1;
-	socklen_t len;
-
-	memset(&so, 0, sizeof(so));
-	sin_set_port(&so, *port);
-	sin_set_ip(&so, my_ip);
-
-	/* create the socket */
-	fd = socket(so.sin.sin_family, SOCK_STREAM, 0);
-#ifdef HAVE_IPV6
-	if (fd == -1 && my_ip == NULL &&
-	    (errno == EINVAL || errno == EAFNOSUPPORT)) {
-		/* IPv6 is not supported by OS */
-		so.sin.sin_family = AF_INET;
-		so.sin.sin_addr.s_addr = INADDR_ANY;
-
-		fd = socket(AF_INET, SOCK_STREAM, 0);
-	}
-#endif
-	if (fd == -1) {
-		i_error("socket() failed: %m");
-		return -1;
-	}
-
-	/* set socket options */
-	setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
-	setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &opt, sizeof(opt));
-
-	/* If using IPv6, bind only to IPv6 if possible. This avoids
-	   ambiguities with IPv4-mapped IPv6 addresses. */
-#ifdef IPV6_V6ONLY
-	if (so.sin.sin_family == AF_INET6) {
-		opt = 1;
-		setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &opt, sizeof(opt));
-	}
-#endif
-	/* specify the address/port we want to listen in */
-	ret = bind(fd, &so.sa, SIZEOF_SOCKADDR(so));
-	if (ret < 0) {
-		if (errno != EADDRINUSE) {
-			i_error("bind(%s, %u) failed: %m",
-				my_ip == NULL ? "" : net_ip2addr(my_ip), *port);
-		}
-	} else {
-		/* get the actual port we started listen */
-		len = SIZEOF_SOCKADDR(so);
-		ret = getsockname(fd, &so.sa, &len);
-		if (ret >= 0) {
-			*port = sin_get_port(&so);
-
-			/* start listening */
-			if (listen(fd, backlog) >= 0)
-				return fd;
-
-			if (errno != EADDRINUSE)
-				i_error("listen() failed: %m");
-		}
-	}
-
-        /* error */
-	i_close_fd(&fd);
-	return -1;
-}
-
-int net_listen_unix(const char *path, int backlog)
-{
-	union {
-		struct sockaddr sa;
-		struct sockaddr_un un;
-	} sa;
-	int fd;
-
-	memset(&sa, 0, sizeof(sa));
-	sa.un.sun_family = AF_UNIX;
-	if (i_strocpy(sa.un.sun_path, path, sizeof(sa.un.sun_path)) < 0) {
-		/* too long path */
-		errno = EINVAL;
-		return -1;
-	}
-
-	/* create the socket */
-	fd = socket(PF_UNIX, SOCK_STREAM, 0);
-	if (fd == -1) {
-		i_error("socket() failed: %m");
-		return -1;
-	}
-
-	/* bind */
-	if (bind(fd, &sa.sa, sizeof(sa)) < 0) {
-		if (errno != EADDRINUSE)
-			i_error("bind(%s) failed: %m", path);
-	} else {
-		/* start listening */
-		if (listen(fd, backlog) == 0)
-			return fd;
-
-		if (errno != EADDRINUSE)
-			i_error("listen() failed: %m");
-	}
-
-	i_close_fd(&fd);
-	return -1;
-}
-
-int net_listen_unix_unlink_stale(const char *path, int backlog)
-{
-	unsigned int i = 0;
-	int fd;
-
-	while ((fd = net_listen_unix(path, backlog)) == -1) {
-		if (errno != EADDRINUSE || ++i == 2)
-			return -1;
-
-		/* see if it really exists */
-		fd = net_connect_unix(path);
-		if (fd != -1 || errno != ECONNREFUSED) {
-			if (fd != -1) i_close_fd(&fd);
-			errno = EADDRINUSE;
-			return -1;
-		}
-
-		/* delete and try again */
-		if (unlink(path) < 0 && errno != ENOENT) {
-			i_error("unlink(%s) failed: %m", path);
-			errno = EADDRINUSE;
-			return -1;
-		}
-	}
-	return fd;
-}
-
-int net_accept(int fd, struct ip_addr *addr_r, unsigned int *port_r)
-{
-	union sockaddr_union so;
-	int ret;
-	socklen_t addrlen;
-
-	i_assert(fd >= 0);
-
-	addrlen = sizeof(so);
-	ret = accept(fd, &so.sa, &addrlen);
-
-	if (ret < 0) {
-		if (errno == EAGAIN || errno == ECONNABORTED)
-			return -1;
-		else
-			return -2;
-	}
-	if (so.sin.sin_family == AF_UNIX) {
-		if (addr_r != NULL)
-			memset(addr_r, 0, sizeof(*addr_r));
-		if (port_r != NULL) *port_r = 0;
-	} else {
-		if (addr_r != NULL) sin_get_ip(&so, addr_r);
-		if (port_r != NULL) *port_r = sin_get_port(&so);
-	}
-	return ret;
-}
-
-ssize_t net_receive(int fd, void *buf, size_t len)
-{
-	ssize_t ret;
-
-	i_assert(fd >= 0);
-	i_assert(len <= SSIZE_T_MAX);
-
-	ret = read(fd, buf, len);
-	if (ret == 0) {
-		/* disconnected */
-		errno = 0;
-		return -2;
-	}
-
-	if (unlikely(ret < 0)) {
-		if (errno == EINTR || errno == EAGAIN)
-			return 0;
-
-		if (errno == ECONNRESET || errno == ETIMEDOUT) {
-                        /* treat as disconnection */
-			return -2;
-		}
-	}
-
-	return ret;
-}
-
-ssize_t net_transmit(int fd, const void *data, size_t len)
-{
-        ssize_t ret;
-
-	i_assert(fd >= 0);
-	i_assert(len <= SSIZE_T_MAX);
-
-	ret = send(fd, data, len, 0);
-	if (unlikely(ret == -1 && (errno == EINTR || errno == EAGAIN)))
-		return 0;
-
-	if (unlikely(errno == EPIPE))
-		return -2;
-
-        return ret;
-}
-
-int net_gethostbyname(const char *addr, struct ip_addr **ips,
-		      unsigned int *ips_count)
-{
-	/* @UNSAFE */
-#ifdef HAVE_IPV6
-	union sockaddr_union *so;
-	struct addrinfo hints, *ai, *origai;
-	int host_error;
-#else
-	struct hostent *hp;
-#endif
-        int count;
-
-	*ips = NULL;
-        *ips_count = 0;
-
-#ifdef HAVE_IPV6
-	memset(&hints, 0, sizeof(struct addrinfo));
-	hints.ai_socktype = SOCK_STREAM;
-
-	/* save error to host_error for later use */
-	host_error = getaddrinfo(addr, NULL, &hints, &ai);
-	if (host_error != 0)
-		return host_error;
-
-        /* get number of IPs */
-        origai = ai;
-	for (count = 0; ai != NULL; ai = ai->ai_next)
-                count++;
-
-        *ips_count = count;
-        *ips = t_malloc(sizeof(struct ip_addr) * count);
-
-        count = 0;
-	for (ai = origai; ai != NULL; ai = ai->ai_next, count++) {
-		so = (union sockaddr_union *) ai->ai_addr;
-
-		sin_get_ip(so, &(*ips)[count]);
-	}
-	freeaddrinfo(origai);
-#else
-	hp = gethostbyname(addr);
-	if (hp == NULL)
-		return h_errno;
-
-        /* get number of IPs */
-	count = 0;
-	while (hp->h_addr_list[count] != NULL)
-		count++;
-
-        *ips_count = count;
-        *ips = t_malloc(sizeof(struct ip_addr) * count);
-
-	while (count > 0) {
-		count--;
-
-		(*ips)[count].family = AF_INET;
-		memcpy(&(*ips)[count].u.ip4, hp->h_addr_list[count],
-		       sizeof((*ips)[count].u.ip4));
-	}
-#endif
-
-	return 0;
-}
-
-int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
-{
-	union sockaddr_union so;
-	socklen_t addrlen;
-
-	i_assert(fd >= 0);
-
-	addrlen = sizeof(so);
-	if (getsockname(fd, &so.sa, &addrlen) == -1)
-		return -1;
-	if (so.sin.sin_family == AF_UNIX) {
-		if (addr != NULL)
-			memset(addr, 0, sizeof(*addr));
-		if (port != NULL) *port = 0;
-	} else {
-		if (addr != NULL) sin_get_ip(&so, addr);
-		if (port != NULL) *port = sin_get_port(&so);
-	}
-	return 0;
-}
-
-int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port)
-{
-	union sockaddr_union so;
-	socklen_t addrlen;
-
-	i_assert(fd >= 0);
-
-	addrlen = sizeof(so);
-	if (getpeername(fd, &so.sa, &addrlen) == -1)
-		return -1;
-	if (so.sin.sin_family == AF_UNIX) {
-		if (addr != NULL)
-			memset(addr, 0, sizeof(*addr));
-		if (port != NULL) *port = 0;
-	} else {
-		if (addr != NULL) sin_get_ip(&so, addr);
-		if (port != NULL) *port = sin_get_port(&so);
-	}
-	return 0;
-}
-
-int net_getunixname(int fd, const char **name_r)
-{
-	union sockaddr_union_unix so;
-	socklen_t addrlen = sizeof(so);
-
-	if (getsockname(fd, &so.sa, &addrlen) < 0)
-		return -1;
-	if (so.un.sun_family != AF_UNIX) {
-		errno = ENOTSOCK;
-		return -1;
-	}
-	*name_r = t_strdup(so.un.sun_path);
-	return 0;
-}
-
-int net_getunixcred(int fd, struct net_unix_cred *cred_r)
-{
-#if defined(SO_PEERCRED)
-# if defined(HAVE_STRUCT_SOCKPEERCRED)
-	/* OpenBSD (may also provide getpeereid, but we also want pid) */
-	struct sockpeercred ucred;
-# else
-	/* Linux */
-	struct ucred ucred;
-# endif
-	socklen_t len = sizeof(ucred);
-
-	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) {
-		i_error("getsockopt(SO_PEERCRED) failed: %m");
-		return -1;
-	}
-	cred_r->uid = ucred.uid;
-	cred_r->gid = ucred.gid;
-	cred_r->pid = ucred.pid;
-	return 0;
-#elif defined(LOCAL_PEEREID)
-	/* NetBSD (may also provide getpeereid, but we also want pid) */
-	struct unpcbid ucred;
-	socklen_t len = sizeof(ucred);
-
-	if (getsockopt(s, 0, LOCAL_PEEREID, &ucred, &len) < 0) {
-		i_error("getsockopt(LOCAL_PEEREID) failed: %m");
-		return -1;
-	}
-	
-	cred_r->uid = ucred.unp_euid;
-	cred_r->gid = ucred.unp_egid;
-	cred_r->pid = ucred.unp_pid;
-	return 0;
-#elif defined(HAVE_GETPEEREID)
-	/* OSX 10.4+, FreeBSD 4.6+, OpenBSD 3.0+, NetBSD 5.0+ */
-	if (getpeereid(fd, &cred_r->uid, &cred_r->gid) < 0) {
-		i_error("getpeereid() failed: %m");
-		return -1;
-	}
-	cred_r->pid = (pid_t)-1;
-	return 0;
-#elif defined(LOCAL_PEERCRED)
-	/* Older FreeBSD */
-	struct xucred ucred;
-	socklen_t len = sizeof(ucred);
-
-	if (getsockopt(fd, 0, LOCAL_PEERCRED, &ucred, &len) < 0) {
-		i_error("getsockopt(LOCAL_PEERCRED) failed: %m");
-		return -1;
-	}
-
-	if (ucred.cr_version != XUCRED_VERSION) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	cred_r->uid = ucred.cr_uid;
-	cred_r->gid = ucred.cr_gid;
-	cred_r->pid = (pid_t)-1;
-	return 0;
-#elif defined(HAVE_GETPEERUCRED)
-	/* Solaris */
-	ucred_t *ucred = NULL;
-
-	if (getpeerucred(fd, &ucred) < 0) {
-		i_error("getpeerucred() failed: %m");
-		return -1;
-	}
-	cred_r->uid = ucred_geteuid(ucred);
-	cred_r->gid = ucred_getrgid(ucred);
-	cred_r->pid = ucred_getpid(ucred);
-	ucred_free(ucred);
-
-	if (cred_r->uid == (uid_t)-1 ||
-	    cred_r->gid == (gid_t)-1) {
-		errno = EINVAL;
-		return -1;
-	}
-	return 0;
-#else
-	errno = EINVAL;
-	return -1;
-#endif
-}
-
-const char *net_ip2addr(const struct ip_addr *ip)
-{
-#ifdef HAVE_IPV6
-	char addr[MAX_IP_LEN+1];
-
-	addr[MAX_IP_LEN] = '\0';
-	if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL)
-		return NULL;
-
-	return t_strdup(addr);
-#else
-	unsigned long ip4;
-
-	if (ip->family != AF_INET)
-		return NULL;
-
-	ip4 = ntohl(ip->u.ip4.s_addr);
-	return t_strdup_printf("%lu.%lu.%lu.%lu",
-			       (ip4 & 0xff000000UL) >> 24,
-			       (ip4 & 0x00ff0000) >> 16,
-			       (ip4 & 0x0000ff00) >> 8,
-			       (ip4 & 0x000000ff));
-#endif
-}
-
-int net_addr2ip(const char *addr, struct ip_addr *ip)
-{
-	int ret;
-
-	if (strchr(addr, ':') != NULL) {
-		/* IPv6 */
-		ip->family = AF_INET6;
-#ifdef HAVE_IPV6
-		T_BEGIN {
-			if (addr[0] == '[') {
-				/* allow [ipv6 addr] */
-				unsigned int len = strlen(addr);
-				if (addr[len-1] == ']')
-					addr = t_strndup(addr+1, len-2);
-			}
-			ret = inet_pton(AF_INET6, addr, &ip->u.ip6);
-		} T_END;
-		if (ret == 0)
-			return -1;
-#else
-		ip->u.ip4.s_addr = 0;
-#endif
- 	} else {
-		/* IPv4 */
-		ip->family = AF_INET;
-		if (inet_aton(addr, &ip->u.ip4) == 0)
-			return -1;
-	}
-
-	return 0;
-}
-
-int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
-				 struct ip_addr *dest)
-{
-#ifdef HAVE_IPV6
-	static uint8_t v4_prefix[] =
-		{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff };
-
-	if (!IPADDR_IS_V6(src))
-		return -1;
-	if (memcmp(src->u.ip6.s6_addr, v4_prefix, sizeof(v4_prefix)) != 0)
-		return -1;
-
-	dest->family = AF_INET;
-	memcpy(&dest->u.ip6, &src->u.ip6.s6_addr[3*4], 4);
-	return 0;
-#else
-	return -1;
-#endif
-}
-
-int net_geterror(int fd)
-{
-	int data;
-	socklen_t len = sizeof(data);
-
-	if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &data, &len) == -1)
-		return -1;
-
-	return data;
-}
-
-const char *net_gethosterror(int error)
-{
-#ifdef HAVE_IPV6
-	i_assert(error != 0);
-
-	return gai_strerror(error);
-#else
-	switch (error) {
-	case HOST_NOT_FOUND:
-		return "Host not found";
-	case NO_ADDRESS:
-		return "No IP address found for name";
-	case NO_RECOVERY:
-		return "A non-recoverable name server error occurred";
-	case TRY_AGAIN:
-		return "A temporary error on an authoritative name server";
-	}
-
-	/* unknown error */
-	return NULL;
-#endif
-}
-
-int net_hosterror_notfound(int error)
-{
-#ifdef HAVE_IPV6
-#ifdef EAI_NODATA /* NODATA is depricated */
-	return error != 1 && (error == EAI_NONAME || error == EAI_NODATA);
-#else
-	return error != 1 && (error == EAI_NONAME);
-#endif
-#else
-	return error == HOST_NOT_FOUND || error == NO_ADDRESS;
-#endif
-}
-
-const char *net_getservbyport(unsigned short port)
-{
-	struct servent *entry;
-
-	entry = getservbyport(htons(port), "tcp");
-	return entry == NULL ? NULL : entry->s_name;
-}
-
-bool is_ipv4_address(const char *addr)
-{
-	while (*addr != '\0') {
-		if (*addr != '.' && !i_isdigit(*addr))
-			return FALSE;
-                addr++;
-	}
-
-	return TRUE;
-}
-
-bool is_ipv6_address(const char *addr)
-{
-	bool have_prefix = FALSE;
-
-	if (*addr == '[') {
-		have_prefix = TRUE;
-		addr++;
-	}
-	while (*addr != '\0') {
-		if (*addr != ':' && !i_isxdigit(*addr)) {
-			if (have_prefix && *addr == ']' && addr[1] == '\0')
-				break;
-			return FALSE;
-		}
-                addr++;
-	}
-
-	return TRUE;
-}
-
-int net_parse_range(const char *network, struct ip_addr *ip_r,
-		    unsigned int *bits_r)
-{
-	const char *p;
-	unsigned int bits, max_bits;
-
-	p = strchr(network, '/');
-	if (p != NULL)
-		network = t_strdup_until(network, p++);
-
-	if (net_addr2ip(network, ip_r) < 0)
-		return -1;
-
-	max_bits = IPADDR_BITS(ip_r);
-	if (p == NULL) {
-		/* full IP address must match */
-		bits = max_bits;
-	} else {
-		/* get the network mask */
-		if (str_to_uint(p, &bits) < 0 || bits > max_bits)
-			return -1;
-	}
-	*bits_r = bits;
-	return 0;
-}
-
-bool net_is_in_network(const struct ip_addr *ip,
-		       const struct ip_addr *net_ip, unsigned int bits)
-{
-	struct ip_addr tmp_ip;
-	const uint32_t *ip1, *ip2;
-	uint32_t mask, i1, i2;
-	unsigned int pos, i;
-
-	if (net_ipv6_mapped_ipv4_convert(ip, &tmp_ip) == 0) {
-		/* IPv4 address mapped disguised as IPv6 address */
-		ip = &tmp_ip;
-	}
-
-	if (IPADDR_IS_V4(ip) != IPADDR_IS_V4(net_ip)) {
-		/* one is IPv6 and one is IPv4 */
-		return FALSE;
-	}
-	i_assert(IPADDR_IS_V6(ip) == IPADDR_IS_V6(net_ip));
-
-	if (IPADDR_IS_V4(ip)) {
-		ip1 = &ip->u.ip4.s_addr;
-		ip2 = &net_ip->u.ip4.s_addr;
-	} else {
-#ifdef HAVE_IPV6
-		ip1 = (const void *)&ip->u.ip6;
-		ip2 = (const void *)&net_ip->u.ip6;
-#else
-		/* shouldn't get here */
-		return FALSE;
-#endif
-	}
-
-	/* check first the full 32bit ints */
-	for (pos = 0, i = 0; pos + 32 <= bits; pos += 32, i++) {
-		if (ip1[i] != ip2[i])
-			return FALSE;
-	}
-	i1 = htonl(ip1[i]);
-	i2 = htonl(ip2[i]);
-
-	/* check the last full bytes */
-	for (mask = 0xff000000; pos + 8 <= bits; pos += 8, mask >>= 8) {
-		if ((i1 & mask) != (i2 & mask))
-			return FALSE;
-	}
-
-	/* check the last bits, they're reversed in bytes */
-	bits -= pos;
-	for (mask = 0x80000000 >> (pos % 32); bits > 0; bits--, mask >>= 1) {
-		if ((i1 & mask) != (i2 & mask))
-			return FALSE;
-	}
-	return TRUE;
-}
--- a/src/lib/network.h	Wed Oct 03 16:57:28 2012 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,152 +0,0 @@
-#ifndef NETWORK_H
-#define NETWORK_H
-
-#ifndef WIN32
-#  include <sys/socket.h>
-#  include <netinet/in.h>
-#  include <netdb.h>
-#  include <arpa/inet.h>
-#endif
-
-#ifdef HAVE_SOCKS_H
-#include <socks.h>
-#endif
-
-#ifndef AF_INET6
-#  ifdef PF_INET6
-#    define AF_INET6 PF_INET6
-#  else
-#    define AF_INET6 10
-#  endif
-#endif
-
-struct ip_addr {
-	unsigned short family;
-	union {
-#ifdef HAVE_IPV6
-		struct in6_addr ip6;
-#endif
-		struct in_addr ip4;
-	} u;
-};
-ARRAY_DEFINE_TYPE(ip_addr, struct ip_addr);
-
-struct net_unix_cred {
-	uid_t uid;
-	gid_t gid;
-	pid_t pid;
-};
-
-/* maxmimum string length of IP address */
-#ifdef HAVE_IPV6
-#  define MAX_IP_LEN INET6_ADDRSTRLEN
-#else
-#  define MAX_IP_LEN 20
-#endif
-
-#define IPADDR_IS_V4(ip) ((ip)->family == AF_INET)
-#define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6)
-#define IPADDR_BITS(ip) (IPADDR_IS_V4(ip) ? 32 : 128)
-
-/* 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_ip_cmp(const struct ip_addr *ip1, const struct ip_addr *ip2);
-unsigned int net_ip_hash(const struct ip_addr *ip);
-
-/* Connect to socket with ip address. The socket and connect() is
-   non-blocking. */
-int net_connect_ip(const struct ip_addr *ip, unsigned int port,
-		   const struct ip_addr *my_ip) ATTR_NULL(3);
-/* Like net_connect_ip(), but do a blocking connect(). */
-int net_connect_ip_blocking(const struct ip_addr *ip, unsigned int port,
-			    const struct ip_addr *my_ip) ATTR_NULL(3);
-/* Returns 0 if we can bind() as given IP, -1 if not. */
-int net_try_bind(const struct ip_addr *ip);
-/* Connect to named UNIX socket */
-int net_connect_unix(const char *path);
-/* Try to connect to UNIX socket for give number of seconds when connect()
-   returns EAGAIN or ECONNREFUSED. */
-int net_connect_unix_with_retries(const char *path, unsigned int msecs);
-/* Disconnect socket */
-void net_disconnect(int fd);
-
-/* Set socket blocking/nonblocking */
-void net_set_nonblock(int fd, bool nonblock);
-/* Set TCP_CORK if supported, ie. don't send out partial frames.
-   Returns 0 if ok, -1 if failed. */
-int net_set_cork(int fd, bool cork) ATTR_NOWARN_UNUSED_RESULT;
-
-/* 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, unsigned int *port, int backlog);
-/* Listen for connections on an UNIX socket */
-int net_listen_unix(const char *path, int backlog);
-/* Like net_listen_unix(), but if socket already exists, try to connect to it.
-   If it fails with ECONNREFUSED, unlink the socket and try creating it
-   again. */
-int net_listen_unix_unlink_stale(const char *path, int backlog);
-/* Accept a connection on a socket. Returns -1 if the connection got closed,
-   -2 for other failures. For UNIX sockets addr_r->family=port=0. */
-int net_accept(int fd, struct ip_addr *addr_r, unsigned int *port_r)
-	ATTR_NULL(2, 3);
-
-/* Read data from socket, return number of bytes read,
-   -1 = error, -2 = disconnected */
-ssize_t net_receive(int fd, void *buf, size_t len);
-/* Transmit data, return number of bytes sent, -1 = error, -2 = disconnected */
-ssize_t net_transmit(int fd, const void *data, size_t len);
-
-/* Get IP addresses for host. ips contains ips_count of IPs, they don't need
-   to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */
-int net_gethostbyname(const char *addr, struct ip_addr **ips,
-		      unsigned int *ips_count);
-/* get error of net_gethostname() */
-const char *net_gethosterror(int error) ATTR_CONST;
-/* return TRUE if host lookup failed because it didn't exist (ie. not
-   some error with name server) */
-int net_hosterror_notfound(int error) ATTR_CONST;
-
-/* Get socket local address/port. For UNIX sockets addr->family=port=0. */
-int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port)
-	ATTR_NULL(2, 3);
-/* Get socket remote address/port. For UNIX sockets addr->family=port=0. */
-int net_getpeername(int fd, struct ip_addr *addr, unsigned int *port)
-	ATTR_NULL(2, 3);
-/* Get UNIX socket name. */
-int net_getunixname(int fd, const char **name_r);
-/* Get UNIX socket peer process's credentials. The pid may be (pid_t)-1 if
-   unavailable. */
-int net_getunixcred(int fd, struct net_unix_cred *cred_r);
-
-/* Returns ip_addr as string, or NULL if ip is invalid. */
-const char *net_ip2addr(const struct ip_addr *ip);
-/* char* -> struct ip_addr translation. */
-int net_addr2ip(const char *addr, struct ip_addr *ip);
-/* Convert IPv6 mapped IPv4 address to an actual IPv4 address. Returns 0 if
-   successful, -1 if the source address isn't IPv6 mapped IPv4 address. */
-int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
-				 struct ip_addr *dest);
-
-/* Get socket error */
-int net_geterror(int fd);
-
-/* Get name of TCP service */
-const char *net_getservbyport(unsigned short port) ATTR_CONST;
-
-bool is_ipv4_address(const char *addr) ATTR_PURE;
-bool is_ipv6_address(const char *addr) ATTR_PURE;
-
-/* Parse network as ip/bits. Returns 0 if successful, -1 if invalid input. */
-int net_parse_range(const char *network, struct ip_addr *ip_r,
-		    unsigned int *bits_r);
-/* Returns TRUE if ip is in net_ip/bits network. IPv6 mapped IPv4 addresses
-   are converted to plain IPv4 addresses before matching. */
-bool net_is_in_network(const struct ip_addr *ip, const struct ip_addr *net_ip,
-		       unsigned int bits) ATTR_PURE;
-
-#endif
--- a/src/lib/ostream-file.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/ostream-file.c	Wed Oct 03 18:17:26 2012 +0300
@@ -5,7 +5,7 @@
 #include "lib.h"
 #include "ioloop.h"
 #include "write-full.h"
-#include "network.h"
+#include "net.h"
 #include "sendfile-util.h"
 #include "istream.h"
 #include "istream-private.h"
--- a/src/lib/sendfile-util.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/sendfile-util.c	Wed Oct 03 18:17:26 2012 +0300
@@ -93,7 +93,7 @@
 #elif defined (HAVE_SOLARIS_SENDFILE)
 
 #include <sys/sendfile.h>
-#include "network.h"
+#include "net.h"
 
 ssize_t safe_sendfile(int out_fd, int in_fd, uoff_t *offset, size_t count)
 {
--- a/src/lib/test-network.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/test-network.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */
 
 #include "test-lib.h"
-#include "network.h"
+#include "net.h"
 
 struct test_net_is_in_network_input {
 	const char *ip;
--- a/src/lib/unix-socket-create.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/unix-socket-create.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2005-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "unix-socket-create.h"
 
 #include <unistd.h>
--- a/src/lib/uri-util.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lib/uri-util.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "str.h"
-#include "network.h"
+#include "net.h"
 #include "uri-util.h"
 
 #include <ctype.h>
--- a/src/lmtp/client.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lmtp/client.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CLIENT_H
 #define CLIENT_H
 
-#include "network.h"
+#include "net.h"
 
 #define CLIENT_MAIL_DATA_MAX_INMEMORY_SIZE (1024*128)
 
--- a/src/lmtp/lmtp-proxy.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/lmtp/lmtp-proxy.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef LMTP_PROXY_H
 #define LMTP_PROXY_H
 
-#include "network.h"
+#include "net.h"
 #include "lmtp-client.h"
 
 #define LMTP_PROXY_DEFAULT_TTL 5
--- a/src/login-common/access-lookup.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/access-lookup.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "fdpass.h"
 #include "access-lookup.h"
 
--- a/src/login-common/client-common.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/client-common.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CLIENT_COMMON_H
 #define CLIENT_COMMON_H
 
-#include "network.h"
+#include "net.h"
 #include "login-proxy.h"
 #include "sasl-server.h"
 #include "master-login.h" /* for LOGIN_MAX_SESSION_ID_LEN */
--- a/src/login-common/login-proxy-state.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/login-proxy-state.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "ioloop.h"
 #include "hash.h"
 #include "strescape.h"
--- a/src/login-common/login-proxy.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/login-proxy.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef LOGIN_PROXY_H
 #define LOGIN_PROXY_H
 
-#include "network.h"
+#include "net.h"
 
 /* Max. number of embedded proxying connections until proxying fails.
    This is intended to avoid an accidental configuration where two proxies
--- a/src/login-common/ssl-proxy-gnutls.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/ssl-proxy-gnutls.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "login-common.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "hash.h"
 #include "ssl-proxy.h"
 
--- a/src/login-common/ssl-proxy-openssl.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/login-common/ssl-proxy-openssl.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "login-common.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "ostream.h"
 #include "read-full.h"
 #include "safe-memset.h"
--- a/src/master/master-settings.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/master/master-settings.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "array.h"
 #include "env-util.h"
 #include "istream.h"
-#include "network.h"
+#include "net.h"
 #include "str.h"
 #include "ipwd.h"
 #include "mkdir-parents.h"
--- a/src/master/service-listen.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/master/service-listen.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "array.h"
 #include "fd-set-nonblock.h"
 #include "fd-close-on-exec.h"
-#include "network.h"
+#include "net.h"
 #ifdef HAVE_SYSTEMD
 #include "sd-daemon.h"
 #endif
--- a/src/master/service.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/master/service.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef SERVICE_H
 #define SERVICE_H
 
-#include "network.h"
+#include "net.h"
 #include "master-settings.h"
 
 /* If a service process doesn't send its first status notification in
--- a/src/plugins/fts/fts-indexer.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/fts/fts-indexer.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "write-full.h"
 #include "strescape.h"
--- a/src/plugins/fts/fts-parser-script.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/fts/fts-parser-script.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "str.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "write-full.h"
 #include "module-context.h"
--- a/src/plugins/quota/quota.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/quota/quota.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 #include "array.h"
 #include "hash.h"
 #include "str.h"
-#include "network.h"
+#include "net.h"
 #include "write-full.h"
 #include "eacces-error.h"
 #include "mailbox-list-private.h"
--- a/src/plugins/replication/replication-plugin.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/replication/replication-plugin.c	Wed Oct 03 18:17:26 2012 +0300
@@ -6,7 +6,7 @@
 #include "strescape.h"
 #include "fd-set-nonblock.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "write-full.h"
 #include "mail-user.h"
 #include "mail-namespace.h"
--- a/src/plugins/stats/stats-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/stats/stats-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "hostpid.h"
-#include "network.h"
+#include "net.h"
 #include "str.h"
 #include "strescape.h"
 #include "mail-storage.h"
--- a/src/plugins/zlib/doveadm-zlib.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/plugins/zlib/doveadm-zlib.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "istream-zlib.h"
--- a/src/pop3-login/client.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/pop3-login/client.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef CLIENT_H
 #define CLIENT_H
 
-#include "network.h"
+#include "net.h"
 #include "client-common.h"
 #include "auth-client.h"
 
--- a/src/pop3/pop3-client.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/pop3/pop3-client.c	Wed Oct 03 18:17:26 2012 +0300
@@ -3,7 +3,7 @@
 #include "pop3-common.h"
 #include "array.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "crc32.h"
--- a/src/replication/aggregator/notify-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/replication/aggregator/notify-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "llist.h"
--- a/src/replication/aggregator/replicator-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/replication/aggregator/replicator-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "buffer.h"
--- a/src/replication/replicator/doveadm-connection.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/replication/replicator/doveadm-connection.c	Wed Oct 03 18:17:26 2012 +0300
@@ -2,7 +2,7 @@
 
 #include "lib.h"
 #include "ioloop.h"
-#include "network.h"
+#include "net.h"
 #include "istream.h"
 #include "ostream.h"
 #include "str.h"
--- a/src/stats/client-export.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/stats/client-export.c	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 /* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
-#include "network.h"
+#include "net.h"
 #include "ostream.h"
 #include "str.h"
 #include "strescape.h"
--- a/src/stats/mail-stats.h	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/stats/mail-stats.h	Wed Oct 03 18:17:26 2012 +0300
@@ -1,7 +1,7 @@
 #ifndef MAIL_STATS_H
 #define MAIL_STATS_H
 
-#include "network.h"
+#include "net.h"
 #include "guid.h"
 
 struct mail_stats {
--- a/src/util/rawlog.c	Wed Oct 03 16:57:28 2012 +0300
+++ b/src/util/rawlog.c	Wed Oct 03 18:17:26 2012 +0300
@@ -4,7 +4,7 @@
 
 #include "ioloop.h"
 #include "fd-set-nonblock.h"
-#include "network.h"
+#include "net.h"
 #include "str.h"
 #include "write-full.h"
 #include "istream.h"