8231
|
1 /**
|
|
2 * @file network.h Network API
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #ifndef _GAIM_NETWORK_H_
|
|
26 #define _GAIM_NETWORK_H_
|
|
27
|
|
28 #ifdef __cplusplus
|
|
29 extern "C" {
|
|
30 #endif
|
|
31
|
|
32 /**************************************************************************/
|
8834
|
33 /** @name Network API */
|
8231
|
34 /**************************************************************************/
|
|
35 /*@{*/
|
|
36
|
|
37 /**
|
8838
|
38 * Converts a dot-decimal IP address to an array of unsigned
|
|
39 * chars. For example, converts 192.168.0.1 to a 4 byte
|
|
40 * array containing 192, 168, 0 and 1.
|
|
41 *
|
|
42 * @param ip An IP address in dot-decimal notiation.
|
|
43 * @return An array of 4 bytes containing an IP addresses
|
|
44 * equivalent to the given parameter, or NULL if
|
|
45 * the given IP address is invalid. This value
|
|
46 * is statically allocated and should not be
|
|
47 * freed.
|
|
48 */
|
|
49 const unsigned char *gaim_network_ip_atoi(const char *ip);
|
|
50
|
|
51 /**
|
8834
|
52 * Sets the IP address of the local system in preferences. This
|
|
53 * is the IP address that should be used for incoming connections
|
|
54 * (file transfer, direct IM, etc.) and should therefore be
|
|
55 * publicly accessible.
|
8231
|
56 *
|
|
57 * @param ip The local IP address.
|
|
58 */
|
8834
|
59 void gaim_network_set_public_ip(const char *ip);
|
8231
|
60
|
|
61 /**
|
|
62 * Returns the IP address of the local system set in preferences.
|
|
63 *
|
8834
|
64 * This returns the value set via gaim_network_set_public_ip().
|
8838
|
65 * You probably want to use gaim_network_get_my_ip() instead.
|
8231
|
66 *
|
|
67 * @return The local IP address set in preferences.
|
|
68 */
|
8834
|
69 const char *gaim_network_get_public_ip(void);
|
8231
|
70
|
|
71 /**
|
|
72 * Returns the IP address of the local system.
|
|
73 *
|
8838
|
74 * You probably want to use gaim_network_get_my_ip() instead.
|
8231
|
75 *
|
|
76 * @note The returned string is a pointer to a static buffer. If this
|
|
77 * function is called twice, it may be important to make a copy
|
|
78 * of the returned string.
|
|
79 *
|
|
80 * @param fd The fd to use to help figure out the IP, or else -1.
|
|
81 * @return The local IP address.
|
|
82 */
|
|
83 const char *gaim_network_get_local_system_ip(int fd);
|
|
84
|
|
85 /**
|
8834
|
86 * Returns the IP address that should be used anywhere a
|
|
87 * public IP addresses is needed (listening for an incoming
|
|
88 * file transfer, etc).
|
8231
|
89 *
|
8834
|
90 * If the user has manually specified an IP address via
|
|
91 * preferences, then this IP is returned. Otherwise the
|
|
92 * IP address returned by gaim_network_get_local_system_ip()
|
|
93 * is returned.
|
8231
|
94 *
|
|
95 * @note The returned string is a pointer to a static buffer. If this
|
|
96 * function is called twice, it may be important to make a copy
|
|
97 * of the returned string.
|
|
98 *
|
|
99 * @param fd The fd to use to help figure out the IP, or -1.
|
|
100 * @return The local IP address to be used.
|
|
101 */
|
8838
|
102 const char *gaim_network_get_my_ip(int fd);
|
8231
|
103
|
|
104 /**
|
8250
|
105 * Attempts to open a listening port ONLY on the specified port number.
|
|
106 * You probably want to use gaim_network_listen_range() instead of this.
|
|
107 * This function is useful, for example, if you wanted to write a telnet
|
|
108 * server as a Gaim plugin, and you HAD to listen on port 23. Why anyone
|
8248
|
109 * would want to do that is beyond me.
|
8231
|
110 *
|
|
111 * This opens a listening port. The caller will want to set up a watcher
|
|
112 * of type GAIM_INPUT_READ on the returned fd. It will probably call
|
|
113 * accept in the callback, and then possibly remove the watcher and close
|
|
114 * the listening socket, and add a new watcher on the new socket accept
|
|
115 * returned.
|
|
116 *
|
8250
|
117 * @param port The port number to bind to. Must be greater than 0.
|
8246
|
118 *
|
|
119 * @return The file descriptor of the listening socket, or -1 if
|
8240
|
120 * no socket could be established.
|
8231
|
121 */
|
8250
|
122 int gaim_network_listen(unsigned short port);
|
8246
|
123
|
|
124 /**
|
8250
|
125 * Opens a listening port selected from a range of ports. The range of
|
8248
|
126 * ports used is chosen in the following manner:
|
|
127 * If a range is specified in preferences, these values are used.
|
8250
|
128 * If a non-0 values are passed to the function as parameters, these
|
8248
|
129 * values are used.
|
|
130 * Otherwise a port is chosen at random by the kernel.
|
8246
|
131 *
|
|
132 * This opens a listening port. The caller will want to set up a watcher
|
|
133 * of type GAIM_INPUT_READ on the returned fd. It will probably call
|
|
134 * accept in the callback, and then possibly remove the watcher and close
|
|
135 * the listening socket, and add a new watcher on the new socket accept
|
|
136 * returned.
|
|
137 *
|
8248
|
138 * @param start The port number to bind to, or 0 to pick a random port.
|
8246
|
139 * Users are allowed to override this arg in prefs.
|
|
140 * @param end The highest possible port in the range of ports to listen on,
|
8248
|
141 * or 0 to pick a random port. Users are allowed to override this
|
8246
|
142 * arg in prefs.
|
8250
|
143 *
|
8246
|
144 * @return The file descriptor of the listening socket, or -1 if
|
|
145 * no socket could be established.
|
|
146 */
|
8250
|
147 int gaim_network_listen_range(unsigned short start, unsigned short end);
|
8231
|
148
|
|
149 /**
|
|
150 * Gets a port number from a file descriptor.
|
|
151 *
|
|
152 * @param fd The file descriptor. This should be a tcp socket. The current
|
|
153 * implementation probably dies on anything but IPv4. Perhaps this
|
|
154 * possible bug will inspire new and valuable contributors to Gaim.
|
|
155 * @return The port number, in host byte order.
|
|
156 */
|
8834
|
157 unsigned short gaim_network_get_port_from_fd(int fd);
|
8231
|
158
|
|
159 /**
|
|
160 * Initializes the network subsystem.
|
|
161 */
|
|
162 void gaim_network_init(void);
|
|
163
|
|
164 /*@}*/
|
|
165
|
|
166 #ifdef __cplusplus
|
|
167 }
|
|
168 #endif
|
|
169
|
|
170 #endif /* _GAIM_NETWORK_H_ */
|