diff options
Diffstat (limited to 'toxcore/network.c')
-rw-r--r-- | toxcore/network.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/toxcore/network.c b/toxcore/network.c index 4b71d70b..63d0c3d7 100644 --- a/toxcore/network.c +++ b/toxcore/network.c | |||
@@ -891,6 +891,31 @@ void ipport_copy(IP_Port *target, IP_Port *source) | |||
891 | memcpy(target, source, sizeof(IP_Port)); | 891 | memcpy(target, source, sizeof(IP_Port)); |
892 | }; | 892 | }; |
893 | 893 | ||
894 | /* packing and unpacking functions */ | ||
895 | void ip_pack(uint8_t *data, IP *source) | ||
896 | { | ||
897 | data[0] = source->family; | ||
898 | memcpy(data + 1, &source->ip6, SIZE_IP6); | ||
899 | } | ||
900 | |||
901 | void ip_unpack(IP *target, uint8_t *data) | ||
902 | { | ||
903 | target->family = data[0]; | ||
904 | memcpy(&target->ip6, data + 1, SIZE_IP6); | ||
905 | } | ||
906 | |||
907 | void ipport_pack(uint8_t *data, IP_Port *source) | ||
908 | { | ||
909 | ip_pack(data, &source.ip); | ||
910 | memcpy(data + SIZE_IP, &source->port, SIZE_PORT); | ||
911 | } | ||
912 | |||
913 | void ipport_unpack(IP_Port *target, uint8_t *data) | ||
914 | { | ||
915 | ip_unpack(&target.ip, data); | ||
916 | memcpy(&target->port, data + SIZE_IP, SIZE_PORT); | ||
917 | } | ||
918 | |||
894 | /* ip_ntoa | 919 | /* ip_ntoa |
895 | * converts ip into a string | 920 | * converts ip into a string |
896 | * uses a static buffer, so mustn't used multiple times in the same output | 921 | * uses a static buffer, so mustn't used multiple times in the same output |