mirror of
https://github.com/irssi/irssi.git
synced 2026-08-16 07:02:12 +02:00
Revert "Network and IPv{4,6} related changes"
This commit is contained in:
parent
2d69deb0a3
commit
f5f3d7cc98
19 changed files with 241 additions and 88 deletions
|
|
@ -33,22 +33,32 @@ GSList *setupservers;
|
|||
|
||||
static char *old_source_host;
|
||||
int source_host_ok; /* Use source_host_ip .. */
|
||||
IPADDR source_host_ip; /* Resolved address */
|
||||
IPADDR *source_host_ip4, *source_host_ip6; /* Resolved address */
|
||||
|
||||
static void save_ips(IPADDR *ip, IPADDR **save_ip)
|
||||
static void save_ips(IPADDR *ip4, IPADDR *ip6,
|
||||
IPADDR **save_ip4, IPADDR **save_ip6)
|
||||
{
|
||||
if (ip->family == 0)
|
||||
g_free_and_null(*save_ip);
|
||||
if (ip4->family == 0)
|
||||
g_free_and_null(*save_ip4);
|
||||
else {
|
||||
if (*save_ip == NULL)
|
||||
*save_ip = g_new(IPADDR, 1);
|
||||
memcpy(*save_ip, ip, sizeof(IPADDR));
|
||||
if (*save_ip4 == NULL)
|
||||
*save_ip4 = g_new(IPADDR, 1);
|
||||
memcpy(*save_ip4, ip4, sizeof(IPADDR));
|
||||
}
|
||||
|
||||
if (ip6->family == 0)
|
||||
g_free_and_null(*save_ip6);
|
||||
else {
|
||||
if (*save_ip6 == NULL)
|
||||
*save_ip6 = g_new(IPADDR, 1);
|
||||
memcpy(*save_ip6, ip6, sizeof(IPADDR));
|
||||
}
|
||||
}
|
||||
|
||||
static void get_source_host_ip(void)
|
||||
{
|
||||
const char *hostname;
|
||||
IPADDR ip4, ip6;
|
||||
|
||||
if (source_host_ok)
|
||||
return;
|
||||
|
|
@ -56,21 +66,28 @@ static void get_source_host_ip(void)
|
|||
/* FIXME: This will block! */
|
||||
hostname = settings_get_str("hostname");
|
||||
source_host_ok = *hostname != '\0' &&
|
||||
net_gethostbyname(hostname, &source_host_ip) == 0;
|
||||
net_gethostbyname(hostname, &ip4, &ip6) == 0;
|
||||
|
||||
if (source_host_ok)
|
||||
save_ips(&ip4, &ip6, &source_host_ip4, &source_host_ip6);
|
||||
else {
|
||||
g_free_and_null(source_host_ip4);
|
||||
g_free_and_null(source_host_ip6);
|
||||
}
|
||||
}
|
||||
|
||||
static void conn_set_ip(SERVER_CONNECT_REC *conn, const char *own_host,
|
||||
IPADDR **own_ip)
|
||||
IPADDR **own_ip4, IPADDR **own_ip6)
|
||||
{
|
||||
IPADDR ip;
|
||||
IPADDR ip4, ip6;
|
||||
|
||||
if (*own_ip == NULL) {
|
||||
if (*own_ip4 == NULL && *own_ip6 == NULL) {
|
||||
/* resolve the IP */
|
||||
if (net_gethostbyname(own_host, &ip) == 0)
|
||||
save_ips(&ip, own_ip);
|
||||
if (net_gethostbyname(own_host, &ip4, &ip6) == 0)
|
||||
save_ips(&ip4, &ip6, own_ip4, own_ip6);
|
||||
}
|
||||
|
||||
server_connect_own_ip_save(conn, *own_ip);
|
||||
server_connect_own_ip_save(conn, *own_ip4, *own_ip6);
|
||||
}
|
||||
|
||||
/* Fill information to connection from server setup record */
|
||||
|
|
@ -81,7 +98,8 @@ void server_setup_fill_reconn(SERVER_CONNECT_REC *conn,
|
|||
g_return_if_fail(IS_SERVER_SETUP(sserver));
|
||||
|
||||
if (sserver->own_host != NULL) {
|
||||
conn_set_ip(conn, sserver->own_host, &sserver->own_ip);
|
||||
conn_set_ip(conn, sserver->own_host,
|
||||
&sserver->own_ip4, &sserver->own_ip6);
|
||||
}
|
||||
|
||||
if (sserver->chatnet != NULL && conn->chatnet == NULL)
|
||||
|
|
@ -121,9 +139,13 @@ static void server_setup_fill(SERVER_CONNECT_REC *conn,
|
|||
}
|
||||
|
||||
/* source IP */
|
||||
if (source_host_ok) {
|
||||
conn->own_ip = g_new(IPADDR, 1);
|
||||
memcpy(conn->own_ip, &source_host_ip, sizeof(IPADDR));
|
||||
if (source_host_ip4 != NULL) {
|
||||
conn->own_ip4 = g_new(IPADDR, 1);
|
||||
memcpy(conn->own_ip4, source_host_ip4, sizeof(IPADDR));
|
||||
}
|
||||
if (source_host_ip6 != NULL) {
|
||||
conn->own_ip6 = g_new(IPADDR, 1);
|
||||
memcpy(conn->own_ip6, source_host_ip6, sizeof(IPADDR));
|
||||
}
|
||||
|
||||
signal_emit("server setup fill connect", 1, conn);
|
||||
|
|
@ -184,7 +206,8 @@ static void server_setup_fill_chatnet(SERVER_CONNECT_REC *conn,
|
|||
conn->realname = g_strdup(chatnet->realname);;
|
||||
}
|
||||
if (chatnet->own_host != NULL) {
|
||||
conn_set_ip(conn, chatnet->own_host, &chatnet->own_ip);
|
||||
conn_set_ip(conn, chatnet->own_host,
|
||||
&chatnet->own_ip4, &chatnet->own_ip6);
|
||||
}
|
||||
|
||||
signal_emit("server setup fill chatnet", 2, conn, chatnet);
|
||||
|
|
@ -458,7 +481,8 @@ static void server_setup_destroy(SERVER_SETUP_REC *rec)
|
|||
signal_emit("server setup destroyed", 1, rec);
|
||||
|
||||
g_free_not_null(rec->own_host);
|
||||
g_free_not_null(rec->own_ip);
|
||||
g_free_not_null(rec->own_ip4);
|
||||
g_free_not_null(rec->own_ip6);
|
||||
g_free_not_null(rec->chatnet);
|
||||
g_free_not_null(rec->password);
|
||||
g_free_not_null(rec->ssl_cert);
|
||||
|
|
@ -532,6 +556,7 @@ void servers_setup_init(void)
|
|||
settings_add_str("proxy", "proxy_password", "");
|
||||
|
||||
setupservers = NULL;
|
||||
source_host_ip4 = source_host_ip6 = NULL;
|
||||
old_source_host = NULL;
|
||||
read_settings();
|
||||
|
||||
|
|
@ -542,6 +567,8 @@ void servers_setup_init(void)
|
|||
|
||||
void servers_setup_deinit(void)
|
||||
{
|
||||
g_free_not_null(source_host_ip4);
|
||||
g_free_not_null(source_host_ip6);
|
||||
g_free_not_null(old_source_host);
|
||||
|
||||
while (setupservers != NULL)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue