Mercurial > pidgin
comparison src/network.c @ 8834:beb7be215db3
[gaim-migrate @ 9598]
I removed account->ip because it isn't used anywhere and I think it's dumb.
Also added handling for a and aaaa records to rendezvous. Gaim peeps
show up in iChat rendezvous lists now. There are still problems.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Wed, 28 Apr 2004 00:48:21 +0000 |
| parents | 86b8d8b4287e |
| children | 518455386538 |
comparison
equal
deleted
inserted
replaced
| 8833:61fdef863ffa | 8834:beb7be215db3 |
|---|---|
| 29 #include "account.h" | 29 #include "account.h" |
| 30 #include "network.h" | 30 #include "network.h" |
| 31 #include "prefs.h" | 31 #include "prefs.h" |
| 32 | 32 |
| 33 void | 33 void |
| 34 gaim_network_set_local_ip(const char *ip) | 34 gaim_network_set_public_ip(const char *ip) |
| 35 { | 35 { |
| 36 g_return_if_fail(ip != NULL); | 36 g_return_if_fail(ip != NULL); |
| 37 | 37 |
| 38 gaim_prefs_set_string("/core/network/public_ip", ip); | 38 gaim_prefs_set_string("/core/network/public_ip", ip); |
| 39 } | 39 } |
| 40 | 40 |
| 41 const char * | 41 const char * |
| 42 gaim_network_get_local_ip(void) | 42 gaim_network_get_public_ip(void) |
| 43 { | 43 { |
| 44 const char *ip; | 44 const char *ip; |
| 45 | |
| 46 if (gaim_prefs_get_bool("/core/network/auto_ip")) | |
| 47 return NULL; | |
| 48 | 45 |
| 49 ip = gaim_prefs_get_string("/core/network/public_ip"); | 46 ip = gaim_prefs_get_string("/core/network/public_ip"); |
| 50 | 47 |
| 51 if (ip == NULL || *ip == '\0') | 48 if (ip == NULL || *ip == '\0') |
| 52 return NULL; | 49 return NULL; |
| 109 } | 106 } |
| 110 | 107 |
| 111 const char * | 108 const char * |
| 112 gaim_network_get_ip_for_account(const GaimAccount *account, int fd) | 109 gaim_network_get_ip_for_account(const GaimAccount *account, int fd) |
| 113 { | 110 { |
| 114 if (account && (gaim_account_get_public_ip(account) != NULL)) | 111 const char *ip = NULL; |
| 115 return gaim_account_get_public_ip(account); | 112 |
| 116 else if (gaim_network_get_local_ip() != NULL) | 113 /* Check if the user specified an IP manually */ |
| 117 return gaim_network_get_local_ip(); | 114 if (!gaim_prefs_get_bool("/core/network/auto_ip")) { |
| 118 else | 115 ip = gaim_network_get_public_ip(); |
| 119 return gaim_network_get_local_system_ip(fd); | 116 if (ip != NULL) |
| 120 } | 117 return ip; |
| 121 | 118 } |
| 122 static int gaim_network_do_listen(unsigned short port) | 119 |
| 120 /* Just fetch the IP of the local system */ | |
| 121 return gaim_network_get_local_system_ip(fd); | |
| 122 } | |
| 123 | |
| 124 static int | |
| 125 gaim_network_do_listen(unsigned short port) | |
| 123 { | 126 { |
| 124 #if HAVE_GETADDRINFO | 127 #if HAVE_GETADDRINFO |
| 125 int listenfd; | 128 int listenfd; |
| 126 const int on = 1; | 129 const int on = 1; |
| 127 struct addrinfo hints, *res, *ressave; | 130 struct addrinfo hints, *res, *ressave; |
| 187 | 190 |
| 188 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); | 191 gaim_debug_info("network", "Listening on port: %hu\n", gaim_network_get_port_from_fd(listenfd)); |
| 189 return listenfd; | 192 return listenfd; |
| 190 } | 193 } |
| 191 | 194 |
| 192 int gaim_network_listen(unsigned short port) | 195 int |
| 196 gaim_network_listen(unsigned short port) | |
| 193 { | 197 { |
| 194 g_return_val_if_fail(port != 0, -1); | 198 g_return_val_if_fail(port != 0, -1); |
| 195 | 199 |
| 196 return gaim_network_do_listen(port); | 200 return gaim_network_do_listen(port); |
| 197 } | 201 } |
| 198 | 202 |
| 199 int gaim_network_listen_range(unsigned short start, unsigned short end) | 203 int |
| 204 gaim_network_listen_range(unsigned short start, unsigned short end) | |
| 200 { | 205 { |
| 201 int ret = -1; | 206 int ret = -1; |
| 202 | 207 |
| 203 if (gaim_prefs_get_bool("/core/network/ports_range_use")) { | 208 if (gaim_prefs_get_bool("/core/network/ports_range_use")) { |
| 204 start = gaim_prefs_get_int("/core/network/ports_range_start"); | 209 start = gaim_prefs_get_int("/core/network/ports_range_start"); |
| 215 } | 220 } |
| 216 | 221 |
| 217 return ret; | 222 return ret; |
| 218 } | 223 } |
| 219 | 224 |
| 220 short gaim_network_get_port_from_fd(int fd) | 225 unsigned short |
| 226 gaim_network_get_port_from_fd(int fd) | |
| 221 { | 227 { |
| 222 struct sockaddr_in addr; | 228 struct sockaddr_in addr; |
| 223 socklen_t len; | 229 socklen_t len; |
| 224 | 230 |
| 225 g_return_val_if_fail(fd > 0, 0); | 231 g_return_val_if_fail(fd > 0, 0); |
