diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index c0bd366d..39483b42 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -207,7 +207,13 @@ void networking_poll(Networking_Core *net) | |||
207 | while (receivepacket(net->sock, &ip_port, data, &length) != -1) { | 207 | while (receivepacket(net->sock, &ip_port, data, &length) != -1) { |
208 | if (length < 1) continue; | 208 | if (length < 1) continue; |
209 | 209 | ||
210 | if (!(net->packethandlers[data[0]].function)) continue; | 210 | if (!(net->packethandlers[data[0]].function)) { |
211 | #ifdef LOGGING | ||
212 | sprintf(logbuffer, "[%02u] -- Packet has no handler.\n", data[0]); | ||
213 | loglog(logbuffer); | ||
214 | #endif | ||
215 | continue; | ||
216 | } | ||
211 | 217 | ||
212 | net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length); | 218 | net->packethandlers[data[0]].function(net->packethandlers[data[0]].object, ip_port, data, length); |
213 | } | 219 | } |
@@ -661,16 +667,18 @@ int addr_parse_ip(const char *address, IP *to) | |||
661 | * | 667 | * |
662 | * input | 668 | * input |
663 | * address: a hostname (or something parseable to an IP address) | 669 | * address: a hostname (or something parseable to an IP address) |
664 | * ip: ip.family MUST be initialized, either set to a specific IP version | 670 | * to: to.family MUST be initialized, either set to a specific IP version |
665 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | 671 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both |
666 | * IP versions are acceptable | 672 | * IP versions are acceptable |
673 | * extra can be NULL and is only set in special circumstances, see returns | ||
667 | * | 674 | * |
668 | * returns in ip a valid IPAny (v4/v6), | 675 | * returns in *to a valid IPAny (v4/v6), |
669 | * prefers v6 if ip.family was AF_UNSPEC and both available | 676 | * prefers v6 if ip.family was AF_UNSPEC and both available |
677 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is AF_INET6 | ||
670 | * returns 0 on failure | 678 | * returns 0 on failure |
671 | */ | 679 | */ |
672 | 680 | ||
673 | int addr_resolve(const char *address, IP *to) | 681 | int addr_resolve(const char *address, IP *to, IP *extra) |
674 | { | 682 | { |
675 | if (!address || !to) | 683 | if (!address || !to) |
676 | return 0; | 684 | return 0; |
@@ -772,6 +780,10 @@ int addr_resolve(const char *address, IP *to) | |||
772 | if (rc & 2) { | 780 | if (rc & 2) { |
773 | to->family = AF_INET6; | 781 | to->family = AF_INET6; |
774 | to->ip6 = ip6; | 782 | to->ip6 = ip6; |
783 | if ((rc & 1) && (extra != NULL)) { | ||
784 | extra->family = AF_INET; | ||
785 | extra->ip4 = ip4; | ||
786 | } | ||
775 | } | 787 | } |
776 | else if (rc & 1) { | 788 | else if (rc & 1) { |
777 | to->family = AF_INET; | 789 | to->family = AF_INET; |
@@ -794,12 +806,20 @@ int addr_resolve(const char *address, IP *to) | |||
794 | * addr_resolve_or_parse_ip | 806 | * addr_resolve_or_parse_ip |
795 | * resolves string into an IP address | 807 | * resolves string into an IP address |
796 | * | 808 | * |
797 | * to->family MUST be set (AF_UNSPEC, AF_INET, AF_INET6) | 809 | * address: a hostname (or something parseable to an IP address) |
798 | * returns 1 on success, 0 on failure | 810 | * to: to.family MUST be initialized, either set to a specific IP version |
811 | * (AF_INET/AF_INET6) or to the unspecified AF_UNSPEC (= 0), if both | ||
812 | * IP versions are acceptable | ||
813 | * extra can be NULL and is only set in special circumstances, see returns | ||
814 | * | ||
815 | * returns in *tro a matching address (IPv6 or IPv4) | ||
816 | * returns in *extra, if not NULL, an IPv4 address, if to->family was AF_UNSPEC | ||
817 | * returns 1 on success | ||
818 | * returns 0 on failure | ||
799 | */ | 819 | */ |
800 | int addr_resolve_or_parse_ip(const char *address, IP *to) | 820 | int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra) |
801 | { | 821 | { |
802 | if (!addr_resolve(address, to)) | 822 | if (!addr_resolve(address, to, extra)) |
803 | if (!addr_parse_ip(address, to)) | 823 | if (!addr_parse_ip(address, to)) |
804 | return 0; | 824 | return 0; |
805 | 825 | ||