diff options
author | irungentoo <irungentoo@gmail.com> | 2015-03-12 13:03:14 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-03-12 13:03:14 -0400 |
commit | 7afab000f70c8a9d8070492fb42fb57bede4a75c (patch) | |
tree | a5f34d24974671659936151c4734eb275162ec9e /toxcore/network.c | |
parent | 4ee017078b1c8bbdf5f61b17194163768f3b0ad8 (diff) |
tox_new now sets error to TOX_ERR_NEW_PORT_ALLOC when binding to port fails.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index d7d07bdb..d974ddc2 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -471,7 +471,7 @@ static void at_shutdown(void) | |||
471 | */ | 471 | */ |
472 | Networking_Core *new_networking(IP ip, uint16_t port) | 472 | Networking_Core *new_networking(IP ip, uint16_t port) |
473 | { | 473 | { |
474 | return new_networking_ex(ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM)); | 474 | return new_networking_ex(ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), 0); |
475 | } | 475 | } |
476 | 476 | ||
477 | /* Initialize networking. | 477 | /* Initialize networking. |
@@ -481,8 +481,10 @@ Networking_Core *new_networking(IP ip, uint16_t port) | |||
481 | * | 481 | * |
482 | * return Networking_Core object if no problems | 482 | * return Networking_Core object if no problems |
483 | * return NULL if there are problems. | 483 | * return NULL if there are problems. |
484 | * | ||
485 | * If error is non NULL it is set to 0 if no issues, 1 if bind failed, 2 if other. | ||
484 | */ | 486 | */ |
485 | Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to) | 487 | Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) |
486 | { | 488 | { |
487 | /* If both from and to are 0, use default port range | 489 | /* If both from and to are 0, use default port range |
488 | * If one is 0 and the other is non-0, use the non-0 value as only port | 490 | * If one is 0 and the other is non-0, use the non-0 value as only port |
@@ -501,6 +503,9 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to) | |||
501 | port_to = temp; | 503 | port_to = temp; |
502 | } | 504 | } |
503 | 505 | ||
506 | if (error) | ||
507 | *error = 2; | ||
508 | |||
504 | /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ | 509 | /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ |
505 | if (ip.family != AF_INET && ip.family != AF_INET6) { | 510 | if (ip.family != AF_INET && ip.family != AF_INET6) { |
506 | #ifdef DEBUG | 511 | #ifdef DEBUG |
@@ -643,6 +648,9 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to) | |||
643 | if (tries > 0) | 648 | if (tries > 0) |
644 | errno = 0; | 649 | errno = 0; |
645 | 650 | ||
651 | if (error) | ||
652 | *error = 0; | ||
653 | |||
646 | return temp; | 654 | return temp; |
647 | } | 655 | } |
648 | 656 | ||
@@ -658,6 +666,10 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to) | |||
658 | ip_ntoa(&ip), port_from, port_to); | 666 | ip_ntoa(&ip), port_from, port_to); |
659 | 667 | ||
660 | kill_networking(temp); | 668 | kill_networking(temp); |
669 | |||
670 | if (error) | ||
671 | *error = 1; | ||
672 | |||
661 | return NULL; | 673 | return NULL; |
662 | } | 674 | } |
663 | 675 | ||