diff options
-rw-r--r-- | toxcore/network.c | 26 | ||||
-rw-r--r-- | toxcore/network.h | 15 |
2 files changed, 27 insertions, 14 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 0009a558..373fef9e 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -671,7 +671,7 @@ int ip_equal(const IP *a, const IP *b) | |||
671 | } | 671 | } |
672 | 672 | ||
673 | return 0; | 673 | return 0; |
674 | }; | 674 | } |
675 | 675 | ||
676 | /* ipport_equal | 676 | /* ipport_equal |
677 | * compares two IPAny_Port structures | 677 | * compares two IPAny_Port structures |
@@ -688,7 +688,7 @@ int ipport_equal(const IP_Port *a, const IP_Port *b) | |||
688 | return 0; | 688 | return 0; |
689 | 689 | ||
690 | return ip_equal(&a->ip, &b->ip); | 690 | return ip_equal(&a->ip, &b->ip); |
691 | }; | 691 | } |
692 | 692 | ||
693 | /* nulls out ip */ | 693 | /* nulls out ip */ |
694 | void ip_reset(IP *ip) | 694 | void ip_reset(IP *ip) |
@@ -697,7 +697,7 @@ void ip_reset(IP *ip) | |||
697 | return; | 697 | return; |
698 | 698 | ||
699 | memset(ip, 0, sizeof(IP)); | 699 | memset(ip, 0, sizeof(IP)); |
700 | }; | 700 | } |
701 | 701 | ||
702 | /* nulls out ip, sets family according to flag */ | 702 | /* nulls out ip, sets family according to flag */ |
703 | void ip_init(IP *ip, uint8_t ipv6enabled) | 703 | void ip_init(IP *ip, uint8_t ipv6enabled) |
@@ -707,7 +707,7 @@ void ip_init(IP *ip, uint8_t ipv6enabled) | |||
707 | 707 | ||
708 | memset(ip, 0, sizeof(IP)); | 708 | memset(ip, 0, sizeof(IP)); |
709 | ip->family = ipv6enabled ? AF_INET6 : AF_INET; | 709 | ip->family = ipv6enabled ? AF_INET6 : AF_INET; |
710 | }; | 710 | } |
711 | 711 | ||
712 | /* checks if ip is valid */ | 712 | /* checks if ip is valid */ |
713 | int ip_isset(const IP *ip) | 713 | int ip_isset(const IP *ip) |
@@ -716,7 +716,7 @@ int ip_isset(const IP *ip) | |||
716 | return 0; | 716 | return 0; |
717 | 717 | ||
718 | return (ip->family != 0); | 718 | return (ip->family != 0); |
719 | }; | 719 | } |
720 | 720 | ||
721 | /* checks if ip is valid */ | 721 | /* checks if ip is valid */ |
722 | int ipport_isset(const IP_Port *ipport) | 722 | int ipport_isset(const IP_Port *ipport) |
@@ -728,7 +728,7 @@ int ipport_isset(const IP_Port *ipport) | |||
728 | return 0; | 728 | return 0; |
729 | 729 | ||
730 | return ip_isset(&ipport->ip); | 730 | return ip_isset(&ipport->ip); |
731 | }; | 731 | } |
732 | 732 | ||
733 | /* copies an ip structure (careful about direction!) */ | 733 | /* copies an ip structure (careful about direction!) */ |
734 | void ip_copy(IP *target, const IP *source) | 734 | void ip_copy(IP *target, const IP *source) |
@@ -737,7 +737,7 @@ void ip_copy(IP *target, const IP *source) | |||
737 | return; | 737 | return; |
738 | 738 | ||
739 | memcpy(target, source, sizeof(IP)); | 739 | memcpy(target, source, sizeof(IP)); |
740 | }; | 740 | } |
741 | 741 | ||
742 | /* copies an ip_port structure (careful about direction!) */ | 742 | /* copies an ip_port structure (careful about direction!) */ |
743 | void ipport_copy(IP_Port *target, const IP_Port *source) | 743 | void ipport_copy(IP_Port *target, const IP_Port *source) |
@@ -805,7 +805,7 @@ const char *ip_ntoa(const IP *ip) | |||
805 | /* brute force protection against lacking termination */ | 805 | /* brute force protection against lacking termination */ |
806 | addresstext[sizeof(addresstext) - 1] = 0; | 806 | addresstext[sizeof(addresstext) - 1] = 0; |
807 | return addresstext; | 807 | return addresstext; |
808 | }; | 808 | } |
809 | 809 | ||
810 | /* | 810 | /* |
811 | * addr_parse_ip | 811 | * addr_parse_ip |
@@ -820,7 +820,6 @@ const char *ip_ntoa(const IP *ip) | |||
820 | * | 820 | * |
821 | * returns 1 on success, 0 on failure | 821 | * returns 1 on success, 0 on failure |
822 | */ | 822 | */ |
823 | |||
824 | int addr_parse_ip(const char *address, IP *to) | 823 | int addr_parse_ip(const char *address, IP *to) |
825 | { | 824 | { |
826 | if (!address || !to) | 825 | if (!address || !to) |
@@ -832,7 +831,7 @@ int addr_parse_ip(const char *address, IP *to) | |||
832 | to->family = AF_INET; | 831 | to->family = AF_INET; |
833 | to->ip4.in_addr = addr4; | 832 | to->ip4.in_addr = addr4; |
834 | return 1; | 833 | return 1; |
835 | }; | 834 | } |
836 | 835 | ||
837 | struct in6_addr addr6; | 836 | struct in6_addr addr6; |
838 | 837 | ||
@@ -840,10 +839,10 @@ int addr_parse_ip(const char *address, IP *to) | |||
840 | to->family = AF_INET6; | 839 | to->family = AF_INET6; |
841 | to->ip6.in6_addr = addr6; | 840 | to->ip6.in6_addr = addr6; |
842 | return 1; | 841 | return 1; |
843 | }; | 842 | } |
844 | 843 | ||
845 | return 0; | 844 | return 0; |
846 | }; | 845 | } |
847 | 846 | ||
848 | /* | 847 | /* |
849 | * addr_resolve(): | 848 | * addr_resolve(): |
@@ -862,7 +861,6 @@ int addr_parse_ip(const char *address, IP *to) | |||
862 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is AF_INET6 | 861 | * returns in *extra an IPv4 address, if family was AF_UNSPEC and *to is AF_INET6 |
863 | * returns 0 on failure | 862 | * returns 0 on failure |
864 | */ | 863 | */ |
865 | |||
866 | int addr_resolve(const char *address, IP *to, IP *extra) | 864 | int addr_resolve(const char *address, IP *to, IP *extra) |
867 | { | 865 | { |
868 | if (!address || !to) | 866 | if (!address || !to) |
@@ -970,4 +968,4 @@ int addr_resolve_or_parse_ip(const char *address, IP *to, IP *extra) | |||
970 | return 0; | 968 | return 0; |
971 | 969 | ||
972 | return 1; | 970 | return 1; |
973 | }; | 971 | } |
diff --git a/toxcore/network.h b/toxcore/network.h index 359d26c8..b902a487 100644 --- a/toxcore/network.h +++ b/toxcore/network.h | |||
@@ -191,6 +191,21 @@ IP_Port; | |||
191 | */ | 191 | */ |
192 | const char *ip_ntoa(const IP *ip); | 192 | const char *ip_ntoa(const IP *ip); |
193 | 193 | ||
194 | /* | ||
195 | * addr_parse_ip | ||
196 | * directly parses the input into an IP structure | ||
197 | * tries IPv4 first, then IPv6 | ||
198 | * | ||
199 | * input | ||
200 | * address: dotted notation (IPv4: quad, IPv6: 16) or colon notation (IPv6) | ||
201 | * | ||
202 | * output | ||
203 | * IP: family and the value is set on success | ||
204 | * | ||
205 | * returns 1 on success, 0 on failure | ||
206 | */ | ||
207 | int addr_parse_ip(const char *address, IP *to); | ||
208 | |||
194 | /* ip_equal | 209 | /* ip_equal |
195 | * compares two IPAny structures | 210 | * compares two IPAny structures |
196 | * unset means unequal | 211 | * unset means unequal |