annotate src/network.h @ 13815:724e4c08391a

[gaim-migrate @ 16247] This cleans up a few missed account and conversation cases, and moves GaimConnections to the typed pointer references. committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Sat, 10 Jun 2006 19:16:58 +0000
parents b7b31c69ade6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file network.h Network API
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 * @ingroup core
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * source distribution.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * (at your option) any later version.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * GNU General Public License for more details.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #ifndef _GAIM_NETWORK_H_
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26 #define _GAIM_NETWORK_H_
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27
13327
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
28 /*
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
29 * TODO: This API needs a way to cancel pending calls to
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
30 * gaim_network_listen_range() and company.
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
31 */
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
32
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 #ifdef __cplusplus
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 extern "C" {
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 #endif
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 /**************************************************************************/
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
38 /** @name Network API */
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 /**************************************************************************/
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40 /*@{*/
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
41
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
42 typedef void (*GaimNetworkListenCallback) (int listenfd, gpointer data);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
43
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
44 /**
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
45 * Converts a dot-decimal IP address to an array of unsigned
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
46 * chars. For example, converts 192.168.0.1 to a 4 byte
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
47 * array containing 192, 168, 0 and 1.
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
48 *
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
49 * @param ip An IP address in dot-decimal notiation.
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
50 * @return An array of 4 bytes containing an IP addresses
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
51 * equivalent to the given parameter, or NULL if
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
52 * the given IP address is invalid. This value
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
53 * is statically allocated and should not be
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
54 * freed.
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
55 */
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
56 const unsigned char *gaim_network_ip_atoi(const char *ip);
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
57
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
58 /**
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
59 * Sets the IP address of the local system in preferences. This
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
60 * is the IP address that should be used for incoming connections
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
61 * (file transfer, direct IM, etc.) and should therefore be
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
62 * publicly accessible.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64 * @param ip The local IP address.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
65 */
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
66 void gaim_network_set_public_ip(const char *ip);
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
67
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 /**
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 * Returns the IP address of the local system set in preferences.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70 *
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
71 * This returns the value set via gaim_network_set_public_ip().
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
72 * You probably want to use gaim_network_get_my_ip() instead.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
74 * @return The local IP address set in preferences.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 */
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
76 const char *gaim_network_get_public_ip(void);
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
77
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
78 /**
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
79 * Returns the IP address of the local system.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
80 *
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
81 * You probably want to use gaim_network_get_my_ip() instead.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
82 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 * @note The returned string is a pointer to a static buffer. If this
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 * function is called twice, it may be important to make a copy
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 * of the returned string.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
86 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87 * @param fd The fd to use to help figure out the IP, or else -1.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 * @return The local IP address.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 */
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 const char *gaim_network_get_local_system_ip(int fd);
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 /**
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
93 * Returns the IP address that should be used anywhere a
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
94 * public IP addresses is needed (listening for an incoming
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
95 * file transfer, etc).
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
96 *
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
97 * If the user has manually specified an IP address via
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
98 * preferences, then this IP is returned. Otherwise the
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
99 * IP address returned by gaim_network_get_local_system_ip()
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
100 * is returned.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 * @note The returned string is a pointer to a static buffer. If this
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
103 * function is called twice, it may be important to make a copy
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
104 * of the returned string.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
105 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
106 * @param fd The fd to use to help figure out the IP, or -1.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
107 * @return The local IP address to be used.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
108 */
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8834
diff changeset
109 const char *gaim_network_get_my_ip(int fd);
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
110
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
111 /**
8250
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
112 * Attempts to open a listening port ONLY on the specified port number.
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
113 * You probably want to use gaim_network_listen_range() instead of this.
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
114 * This function is useful, for example, if you wanted to write a telnet
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
115 * server as a Gaim plugin, and you HAD to listen on port 23. Why anyone
8248
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
116 * would want to do that is beyond me.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
117 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
118 * This opens a listening port. The caller will want to set up a watcher
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
119 * of type GAIM_INPUT_READ on the fd returned in cb. It will probably call
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
120 * accept in the watcher callback, and then possibly remove the watcher and close
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
121 * the listening socket, and add a new watcher on the new socket accept
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
122 * returned.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
123 *
8250
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
124 * @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
125 * @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
126 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
127 * @param cb The callback to be invoked when the port to listen on is available.
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
128 * The file descriptor of the listening socket will be specified in
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
129 * this callback, or -1 if no socket could be established.
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
130 * @param cb_data extra data to be returned when cb is called
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
131 *
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
132 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
133 * a local socket to listen on.
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
134 */
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
135 gboolean gaim_network_listen(unsigned short port, int socket_type,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
136 GaimNetworkListenCallback cb, gpointer cb_data);
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
137
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
138 /**
8250
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
139 * Opens a listening port selected from a range of ports. The range of
8248
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
140 * ports used is chosen in the following manner:
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
141 * If a range is specified in preferences, these values are used.
8250
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
142 * If a non-0 values are passed to the function as parameters, these
8248
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
143 * values are used.
13327
b7b31c69ade6 [gaim-migrate @ 15697]
Mark Doliner <mark@kingant.net>
parents: 12909
diff changeset
144 * Otherwise a port is chosen at random by the operating system.
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
145 *
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
146 * This opens a listening port. The caller will want to set up a watcher
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
147 * of type GAIM_INPUT_READ on the fd returned in cb. It will probably call
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
148 * accept in the watcher callback, and then possibly remove the watcher and close
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
149 * the listening socket, and add a new watcher on the new socket accept
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
150 * returned.
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
151 *
8248
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
152 * @param start The port number to bind to, or 0 to pick a random port.
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
153 * Users are allowed to override this arg in prefs.
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
154 * @param end The highest possible port in the range of ports to listen on,
8248
fabcfd9a7c1c [gaim-migrate @ 8971]
Mark Doliner <mark@kingant.net>
parents: 8246
diff changeset
155 * or 0 to pick a random port. Users are allowed to override this
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
156 * arg in prefs.
12730
d5b8f4dc1622 [gaim-migrate @ 15074]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 8915
diff changeset
157 * @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
158 * This will be either SOCK_STREAM for TCP or SOCK_DGRAM for UDP.
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
159 * @param cb The callback to be invoked when the port to listen on is available.
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
160 * The file descriptor of the listening socket will be specified in
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
161 * this callback, or -1 if no socket could be established.
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
162 * @param cb_data extra data to be returned when cb is called
8250
b248c1f4efbd [gaim-migrate @ 8973]
Mark Doliner <mark@kingant.net>
parents: 8248
diff changeset
163 *
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
164 * @return TRUE if the callback will be invoked, or FALSE if unable to obtain
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
165 * a local socket to listen on.
8246
e7524f4b4ed2 [gaim-migrate @ 8969]
Mark Doliner <mark@kingant.net>
parents: 8240
diff changeset
166 */
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
167 gboolean gaim_network_listen_range(unsigned short start, unsigned short end,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
168 int socket_type, GaimNetworkListenCallback cb, gpointer cb_data);
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
169
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
170 /**
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
171 * Gets a port number from a file descriptor.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
172 *
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
173 * @param fd The file descriptor. This should be a tcp socket. The current
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 * implementation probably dies on anything but IPv4. Perhaps this
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175 * possible bug will inspire new and valuable contributors to Gaim.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 * @return The port number, in host byte order.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 */
8834
beb7be215db3 [gaim-migrate @ 9598]
Mark Doliner <mark@kingant.net>
parents: 8250
diff changeset
178 unsigned short gaim_network_get_port_from_fd(int fd);
8231
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 /**
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181 * Initializes the network subsystem.
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 */
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183 void gaim_network_init(void);
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185 /*@}*/
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
186
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
187 #ifdef __cplusplus
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
188 }
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
189 #endif
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
190
f50c059b6384 [gaim-migrate @ 8954]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
191 #endif /* _GAIM_NETWORK_H_ */