Mercurial > pidgin.yaz
annotate src/network.h @ 12882:e1603fd610fa
[gaim-migrate @ 15234]
I give you perl /cmd support. I only tested this a little bit but it seemed to
work for me, let me know if anything breaks.
committer: Tailor Script <tailor@pidgin.im>
author | Etan Reisner <pidgin@unreliablesource.net> |
---|---|
date | Sun, 15 Jan 2006 07:56:58 +0000 |
parents | d5b8f4dc1622 |
children | 8e3b85fe4a55 |
rev | line source |
---|---|
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. |
12730
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
118 * @param socket_type The type of socket to open for listening. |
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
119 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
8246 | 120 * |
121 * @return The file descriptor of the listening socket, or -1 if | |
8240 | 122 * no socket could be established. |
8231 | 123 */ |
12730
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
124 int gaim_network_listen(unsigned short port, int socket_type); |
8246 | 125 |
126 /** | |
8250 | 127 * Opens a listening port selected from a range of ports. The range of |
8248 | 128 * ports used is chosen in the following manner: |
129 * If a range is specified in preferences, these values are used. | |
8250 | 130 * If a non-0 values are passed to the function as parameters, these |
8248 | 131 * values are used. |
132 * Otherwise a port is chosen at random by the kernel. | |
8246 | 133 * |
134 * This opens a listening port. The caller will want to set up a watcher | |
135 * of type GAIM_INPUT_READ on the returned fd. It will probably call | |
136 * accept in the callback, and then possibly remove the watcher and close | |
137 * the listening socket, and add a new watcher on the new socket accept | |
138 * returned. | |
139 * | |
8248 | 140 * @param start The port number to bind to, or 0 to pick a random port. |
8246 | 141 * Users are allowed to override this arg in prefs. |
142 * @param end The highest possible port in the range of ports to listen on, | |
8248 | 143 * or 0 to pick a random port. Users are allowed to override this |
8246 | 144 * arg in prefs. |
12730
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
145 * @param socket_type The type of socket to open for listening. |
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
146 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP. |
8250 | 147 * |
8246 | 148 * @return The file descriptor of the listening socket, or -1 if |
149 * no socket could be established. | |
150 */ | |
12730
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
151 int gaim_network_listen_range(unsigned short start, unsigned short end, |
d5b8f4dc1622
[gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
8915
diff
changeset
|
152 int socket_type); |
8231 | 153 |
154 /** | |
155 * Gets a port number from a file descriptor. | |
156 * | |
157 * @param fd The file descriptor. This should be a tcp socket. The current | |
158 * implementation probably dies on anything but IPv4. Perhaps this | |
159 * possible bug will inspire new and valuable contributors to Gaim. | |
160 * @return The port number, in host byte order. | |
161 */ | |
8834 | 162 unsigned short gaim_network_get_port_from_fd(int fd); |
8231 | 163 |
164 /** | |
165 * Initializes the network subsystem. | |
166 */ | |
167 void gaim_network_init(void); | |
168 | |
169 /*@}*/ | |
170 | |
171 #ifdef __cplusplus | |
172 } | |
173 #endif | |
174 | |
175 #endif /* _GAIM_NETWORK_H_ */ |