Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/network.h @ 1329:ae229b7acb4c HEAD
Mailbox names are now sent through imap-quoter instead of just escaping it.
This means that mailbox names that would require escapes are instead sent
as literals now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 02 Apr 2003 05:05:38 +0300 |
parents | fd8888f6f037 |
children | 8c28289a15a1 |
rev | line source |
---|---|
0 | 1 #ifndef __NETWORK_H |
2 #define __NETWORK_H | |
3 | |
4 #ifndef WIN32 | |
5 # include <sys/socket.h> | |
6 # include <netinet/in.h> | |
7 # include <netdb.h> | |
8 # include <arpa/inet.h> | |
9 #endif | |
10 | |
11 #ifdef HAVE_SOCKS_H | |
12 #include <socks.h> | |
13 #endif | |
14 | |
15 #ifndef AF_INET6 | |
16 # ifdef PF_INET6 | |
17 # define AF_INET6 PF_INET6 | |
18 # else | |
19 # define AF_INET6 10 | |
20 # endif | |
21 #endif | |
22 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
23 struct ip_addr { |
0 | 24 unsigned short family; |
25 #ifdef HAVE_IPV6 | |
26 struct in6_addr ip; | |
27 #else | |
28 struct in_addr ip; | |
29 #endif | |
30 }; | |
31 | |
32 /* maxmimum string length of IP address */ | |
33 #ifdef HAVE_IPV6 | |
34 # define MAX_IP_LEN INET6_ADDRSTRLEN | |
35 #else | |
36 # define MAX_IP_LEN 20 | |
37 #endif | |
38 | |
39 #define IPADDR_IS_V4(ip) ((ip)->family == AF_INET) | |
40 #define IPADDR_IS_V6(ip) ((ip)->family == AF_INET6) | |
41 | |
42 /* returns 1 if IPADDRs are the same */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
43 int net_ip_compare(const struct ip_addr *ip1, const struct ip_addr *ip2); |
0 | 44 |
45 /* Connect to socket with ip address */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
46 int net_connect_ip(const struct ip_addr *ip, unsigned int port, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
47 const struct ip_addr *my_ip); |
0 | 48 /* Connect to named UNIX socket */ |
49 int net_connect_unix(const char *path); | |
50 /* Disconnect socket */ | |
51 void net_disconnect(int fd); | |
52 /* Try to let the other side close the connection, if it still isn't | |
53 disconnected after certain amount of time, close it ourself */ | |
54 void net_disconnect_later(int fd); | |
55 | |
56 /* Set socket blocking/nonblocking */ | |
57 void net_set_nonblock(int fd, int nonblock); | |
410
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
349
diff
changeset
|
58 /* Set TCP_CORK if supported, ie. don't send out partial frames. |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
349
diff
changeset
|
59 Returns 0 if ok, -1 if failed. */ |
1f0e7229ee58
Split IOBuffer into mmaped IBuffer, file IBuffer, memory data IBuffer and
Timo Sirainen <tss@iki.fi>
parents:
349
diff
changeset
|
60 int net_set_cork(int fd, int cork); |
0 | 61 |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
680
diff
changeset
|
62 /* Set IP to contain INADDR_ANY for IPv4 or IPv6. The IPv6 any address may |
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
680
diff
changeset
|
63 include IPv4 depending on the system (Linux yes, BSD no). */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
64 void net_get_ip_any4(struct ip_addr *ip); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
65 void net_get_ip_any6(struct ip_addr *ip); |
780
1cc947617c8b
imap_listen and imaps_listen accepts now "*" as "all IPv4 interfaces" and
Timo Sirainen <tss@iki.fi>
parents:
680
diff
changeset
|
66 |
0 | 67 /* Listen for connections on a socket */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
68 int net_listen(const struct ip_addr *my_ip, unsigned int *port); |
0 | 69 /* Listen for connections on an UNIX socket */ |
70 int net_listen_unix(const char *path); | |
680
84e398270f7f
net_accept() returns now -2 for fatal failures.
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
71 /* Accept a connection on a socket. Returns -1 for temporary failure, |
84e398270f7f
net_accept() returns now -2 for fatal failures.
Timo Sirainen <tss@iki.fi>
parents:
410
diff
changeset
|
72 -2 for fatal failure */ |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
73 int net_accept(int fd, struct ip_addr *addr, unsigned int *port); |
0 | 74 |
781
9cb7022749e7
net_receive, net_transmit: Return -2 for regular disconnection errors. Don't
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
75 /* Read data from socket, return number of bytes read, |
9cb7022749e7
net_receive, net_transmit: Return -2 for regular disconnection errors. Don't
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
76 -1 = error, -2 = disconnected */ |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
77 ssize_t net_receive(int fd, void *buf, size_t len); |
781
9cb7022749e7
net_receive, net_transmit: Return -2 for regular disconnection errors. Don't
Timo Sirainen <tss@iki.fi>
parents:
780
diff
changeset
|
78 /* Transmit data, return number of bytes sent, -1 = error, -2 = disconnected */ |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
79 ssize_t net_transmit(int fd, const void *data, size_t len); |
0 | 80 |
81 /* Get IP addresses for host. ips contains ips_count of IPs, they don't need | |
82 to be free'd. Returns 0 = ok, others = error code for net_gethosterror() */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
83 int net_gethostbyname(const char *addr, struct ip_addr **ips, int *ips_count); |
0 | 84 /* get error of net_gethostname() */ |
85 const char *net_gethosterror(int error); | |
86 /* return TRUE if host lookup failed because it didn't exist (ie. not | |
87 some error with name server) */ | |
88 int net_hosterror_notfound(int error); | |
89 | |
90 /* Get socket address/port */ | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
91 int net_getsockname(int fd, struct ip_addr *addr, unsigned int *port); |
0 | 92 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
93 /* Returns ip_addr as string, or NULL if ip is invalid. */ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
94 const char *net_ip2host(const struct ip_addr *ip); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
95 /* char* -> struct ip_addr translation. */ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
805
diff
changeset
|
96 int net_host2ip(const char *host, struct ip_addr *ip); |
0 | 97 |
98 /* Get socket error */ | |
99 int net_geterror(int fd); | |
100 | |
101 /* Get name of TCP service */ | |
349 | 102 char *net_getservbyport(unsigned short port); |
0 | 103 |
104 int is_ipv4_address(const char *host); | |
105 int is_ipv6_address(const char *host); | |
106 | |
107 #endif |