comparison src/network.h @ 8231:f50c059b6384

[gaim-migrate @ 8954] This is Tim Ringenbach's patch to move some IP-related functions into the new gaim_network namespace, improve the local IP checking functionality by opening a socket, change some prefs, and add the ability to modify these prefs in the UI. Some ft.c bugs were fixed, and OSCAR, Jabber and Yahoo were updated to reflect the changes. The DCC SEND portion of this patch was not committed, as per his request (unless I misunderstood? :) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Thu, 12 Feb 2004 00:36:55 +0000
parents
children 5220e0898252
comparison
equal deleted inserted replaced
8230:4e354776ae2a 8231:f50c059b6384
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 /**************************************************************************/
33 /** @name Network API */
34 /**************************************************************************/
35 /*@{*/
36
37 /**
38 * Sets the IP address of the local system in preferences.
39 *
40 * @param ip The local IP address.
41 */
42 void gaim_network_set_local_ip(const char *ip);
43
44 /**
45 * Returns the IP address of the local system set in preferences.
46 *
47 * This returns the value set via gaim_network_set_local_ip().
48 * You probably want to use gaim_network_get_ip_for_account() instead.
49 *
50 * @return The local IP address set in preferences.
51 */
52 const char *gaim_network_get_local_ip(void);
53
54 /**
55 * Returns the IP address of the local system.
56 *
57 * You probably want to use gaim_network_get_ip_for_account() instead.
58 *
59 * @note The returned string is a pointer to a static buffer. If this
60 * function is called twice, it may be important to make a copy
61 * of the returned string.
62 *
63 * @param fd The fd to use to help figure out the IP, or else -1.
64 * @return The local IP address.
65 */
66 const char *gaim_network_get_local_system_ip(int fd);
67
68 /**
69 * Returns the IP address that should be used for the specified account.
70 *
71 * First, if @a account is not @c NULL, the IP associated with @a account
72 * is tried, via a call to gaim_account_get_local_ip().
73 *
74 * If that IP is not set, the IP set in preferences is tried.
75 *
76 * If that IP is not set, the system's local IP is tried, via a call to
77 * gaim_network_get_local_ip().
78 *
79 * @note The returned string is a pointer to a static buffer. If this
80 * function is called twice, it may be important to make a copy
81 * of the returned string.
82 *
83 * @param account The account to use. This may be @c NULL, and if so
84 * the first step listed above is skipped.
85 * @param fd The fd to use to help figure out the IP, or -1.
86 * @return The local IP address to be used.
87 */
88 const char *gaim_network_get_ip_for_account(const GaimAccount *account, int fd);
89
90 /**
91 * Opens a listening port.
92 *
93 * This opens a listening port. The caller will want to set up a watcher
94 * of type GAIM_INPUT_READ on the returned fd. It will probably call
95 * accept in the callback, and then possibly remove the watcher and close
96 * the listening socket, and add a new watcher on the new socket accept
97 * returned.
98 *
99 * @param portnum The port number to bind to, or 0, to let the core decide.
100 * By default, the core will let the kernel pick one at random,
101 * but users are allowed to specify a range.
102 *
103 * @return The file descriptor of the listening socket.
104 */
105 int gaim_network_listen(short portnum);
106
107 /**
108 * Gets a port number from a file descriptor.
109 *
110 * @param fd The file descriptor. This should be a tcp socket. The current
111 * implementation probably dies on anything but IPv4. Perhaps this
112 * possible bug will inspire new and valuable contributors to Gaim.
113 * @return The port number, in host byte order.
114 */
115 short gaim_network_get_port_from_fd(int fd);
116
117 /**
118 * Initializes the network subsystem.
119 */
120 void gaim_network_init(void);
121
122 /*@}*/
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif /* _GAIM_NETWORK_H_ */