| 384 |
|
{ |
| 385 |
|
char buf[HOSTIPLEN + 1] = ""; |
| 386 |
|
|
| 387 |
– |
/* conversion structs */ |
| 388 |
– |
struct sockaddr_in *v4; |
| 389 |
– |
|
| 387 |
|
/* Make sure conf is useful */ |
| 388 |
|
assert(conf); |
| 389 |
|
assert(conf->type == CONF_SERVER); |
| 390 |
|
assert(hash_find_server(conf->name) == NULL); /* This should have been checked by the caller */ |
| 391 |
|
|
| 395 |
– |
getnameinfo((const struct sockaddr *)&conf->addr, conf->addr.ss_len, |
| 396 |
– |
buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
| 397 |
– |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host, buf); |
| 398 |
– |
|
| 392 |
|
/* Still processing a DNS lookup? -> exit */ |
| 393 |
|
if (conf->dns_pending == true) |
| 394 |
|
{ |
| 406 |
|
return false; |
| 407 |
|
} |
| 408 |
|
|
| 409 |
+ |
getnameinfo((const struct sockaddr *)conf->addr, conf->addr->ss_len, |
| 410 |
+ |
buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); |
| 411 |
+ |
ilog(LOG_TYPE_IRCD, "Connect to %s[%s] @%s", conf->name, conf->host, buf); |
| 412 |
+ |
|
| 413 |
|
/* Create a socket for the server connection */ |
| 414 |
< |
int fd = comm_socket(conf->addr.ss.ss_family, SOCK_STREAM, 0); |
| 414 |
> |
int fd = comm_socket(conf->addr->ss.ss_family, SOCK_STREAM, 0); |
| 415 |
|
if (fd == -1) |
| 416 |
|
{ |
| 417 |
|
/* Eek, failure to create the socket */ |
| 429 |
|
/* We already converted the ip once, so lets use it - stu */ |
| 430 |
|
strlcpy(client_p->sockhost, buf, sizeof(client_p->sockhost)); |
| 431 |
|
|
| 432 |
+ |
memcpy(&client_p->ip, conf->addr, sizeof(client_p->ip)); |
| 433 |
+ |
|
| 434 |
|
client_p->connection->fd = fd_open(fd, true, NULL); |
| 435 |
|
|
| 436 |
|
/* Server names are always guaranteed under HOSTLEN chars */ |
| 450 |
|
strlcpy(client_p->serv->by, "AutoConn.", sizeof(client_p->serv->by)); |
| 451 |
|
|
| 452 |
|
SetConnecting(client_p); |
| 454 |
– |
client_p->ip.ss.ss_family = conf->aftype; |
| 453 |
|
|
| 454 |
|
/* Now, initiate the connection */ |
| 455 |
< |
/* XXX assume that a non 0 type means a specific bind address |
| 456 |
< |
* for this connect. |
| 459 |
< |
*/ |
| 460 |
< |
switch (conf->aftype) |
| 461 |
< |
{ |
| 462 |
< |
case AF_INET: |
| 463 |
< |
v4 = (struct sockaddr_in*)&conf->bind; |
| 464 |
< |
|
| 465 |
< |
if (v4->sin_addr.s_addr) |
| 466 |
< |
{ |
| 467 |
< |
struct irc_ssaddr ipn; |
| 468 |
< |
|
| 469 |
< |
memset(&ipn, 0, sizeof(ipn)); |
| 470 |
< |
ipn.ss.ss_family = AF_INET; |
| 471 |
< |
ipn.ss_port = 0; |
| 472 |
< |
memcpy(&ipn, &conf->bind, sizeof(ipn)); |
| 473 |
< |
|
| 474 |
< |
comm_connect_tcp(client_p->connection->fd, conf->host, conf->port, |
| 475 |
< |
(struct sockaddr *)&ipn, ipn.ss_len, |
| 476 |
< |
server_connect_callback, client_p, conf->aftype, |
| 477 |
< |
CONNECTTIMEOUT); |
| 478 |
< |
} |
| 479 |
< |
else if (ConfigServerInfo.specific_ipv4_vhost) |
| 480 |
< |
{ |
| 481 |
< |
struct irc_ssaddr ipn; |
| 482 |
< |
|
| 483 |
< |
memset(&ipn, 0, sizeof(ipn)); |
| 484 |
< |
ipn.ss.ss_family = AF_INET; |
| 485 |
< |
ipn.ss_port = 0; |
| 486 |
< |
memcpy(&ipn, &ConfigServerInfo.ip, sizeof(ipn)); |
| 487 |
< |
|
| 488 |
< |
comm_connect_tcp(client_p->connection->fd, conf->host, conf->port, |
| 489 |
< |
(struct sockaddr *)&ipn, ipn.ss_len, |
| 490 |
< |
server_connect_callback, client_p, conf->aftype, |
| 491 |
< |
CONNECTTIMEOUT); |
| 492 |
< |
} |
| 493 |
< |
else |
| 494 |
< |
comm_connect_tcp(client_p->connection->fd, conf->host, conf->port, |
| 495 |
< |
NULL, 0, server_connect_callback, client_p, conf->aftype, |
| 496 |
< |
CONNECTTIMEOUT); |
| 497 |
< |
break; |
| 498 |
< |
case AF_INET6: |
| 499 |
< |
{ |
| 500 |
< |
struct irc_ssaddr ipn; |
| 501 |
< |
struct sockaddr_in6 *v6; |
| 502 |
< |
struct sockaddr_in6 *v6conf; |
| 503 |
< |
|
| 504 |
< |
memset(&ipn, 0, sizeof(ipn)); |
| 505 |
< |
v6conf = (struct sockaddr_in6 *)&conf->bind; |
| 506 |
< |
v6 = (struct sockaddr_in6 *)&ipn; |
| 507 |
< |
|
| 508 |
< |
if (memcmp(&v6conf->sin6_addr, &v6->sin6_addr, sizeof(struct in6_addr))) |
| 509 |
< |
{ |
| 510 |
< |
memcpy(&ipn, &conf->bind, sizeof(ipn)); |
| 511 |
< |
ipn.ss.ss_family = AF_INET6; |
| 512 |
< |
ipn.ss_port = 0; |
| 513 |
< |
|
| 514 |
< |
comm_connect_tcp(client_p->connection->fd, |
| 515 |
< |
conf->host, conf->port, |
| 516 |
< |
(struct sockaddr *)&ipn, ipn.ss_len, |
| 517 |
< |
server_connect_callback, client_p, |
| 518 |
< |
conf->aftype, CONNECTTIMEOUT); |
| 519 |
< |
} |
| 520 |
< |
else if (ConfigServerInfo.specific_ipv6_vhost) |
| 521 |
< |
{ |
| 522 |
< |
memcpy(&ipn, &ConfigServerInfo.ip6, sizeof(ipn)); |
| 523 |
< |
ipn.ss.ss_family = AF_INET6; |
| 524 |
< |
ipn.ss_port = 0; |
| 525 |
< |
|
| 526 |
< |
comm_connect_tcp(client_p->connection->fd, |
| 527 |
< |
conf->host, conf->port, |
| 528 |
< |
(struct sockaddr *)&ipn, ipn.ss_len, |
| 529 |
< |
server_connect_callback, client_p, |
| 530 |
< |
conf->aftype, CONNECTTIMEOUT); |
| 531 |
< |
} |
| 532 |
< |
else |
| 533 |
< |
comm_connect_tcp(client_p->connection->fd, |
| 534 |
< |
conf->host, conf->port, |
| 535 |
< |
NULL, 0, server_connect_callback, client_p, |
| 536 |
< |
conf->aftype, CONNECTTIMEOUT); |
| 537 |
< |
} |
| 538 |
< |
} |
| 455 |
> |
comm_connect_tcp(client_p->connection->fd, conf->addr, conf->port, conf->bind, |
| 456 |
> |
server_connect_callback, client_p, CONNECTTIMEOUT); |
| 457 |
|
|
| 458 |
|
/* |
| 459 |
|
* At this point we have a connection in progress and a connect {} block |
| 481 |
|
return; |
| 482 |
|
} |
| 483 |
|
|
| 484 |
+ |
/* Next, send the initial handshake */ |
| 485 |
+ |
SetHandshake(client_p); |
| 486 |
+ |
|
| 487 |
|
sendto_one(client_p, "PASS %s TS %u %s", conf->spasswd, TS_CURRENT, me.id); |
| 488 |
|
|
| 489 |
|
sendto_one(client_p, "CAPAB :%s", capab_get(NULL)); |
| 586 |
|
assert(client_p->connection->fd); |
| 587 |
|
assert(client_p->connection->fd == F); |
| 588 |
|
|
| 668 |
– |
/* Next, for backward purposes, record the ip of the server */ |
| 669 |
– |
memcpy(&client_p->ip, &F->connect.hostaddr, sizeof(client_p->ip)); |
| 670 |
– |
|
| 589 |
|
/* Check the status */ |
| 590 |
|
if (status != COMM_OK) |
| 591 |
|
{ |
| 620 |
|
return; |
| 621 |
|
} |
| 622 |
|
|
| 705 |
– |
/* Next, send the initial handshake */ |
| 706 |
– |
SetHandshake(client_p); |
| 707 |
– |
|
| 623 |
|
if (IsConfSSL(conf)) |
| 624 |
|
{ |
| 625 |
|
server_tls_connect_init(client_p, conf, F); |
| 626 |
|
return; |
| 627 |
|
} |
| 628 |
|
|
| 629 |
+ |
/* Next, send the initial handshake */ |
| 630 |
+ |
SetHandshake(client_p); |
| 631 |
+ |
|
| 632 |
|
sendto_one(client_p, "PASS %s TS %u %s", conf->spasswd, TS_CURRENT, me.id); |
| 633 |
|
|
| 634 |
|
sendto_one(client_p, "CAPAB :%s", capab_get(NULL)); |