mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Remove brackets from ip_ntoa ipv6 formatting
The brackets serve no purpose and make us do extra string parsing when using the output for other things Also removed a useless call to ip_ntoa in LAN_discovery.c
This commit is contained in:
parent
2b783c4170
commit
3f4ea3d5fd
|
@ -1 +1 @@
|
||||||
0edccd9abfeac725152b708b805ab9880a57398ef9e83a814256893c52fef3c0 /usr/local/bin/tox-bootstrapd
|
4bf8ff0a64f54bd11be8def3a00fb7d57fbc1a8c639eefdce9ccae91abcdf0a5 /usr/local/bin/tox-bootstrapd
|
||||||
|
|
|
@ -353,9 +353,6 @@ static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *pack
|
||||||
{
|
{
|
||||||
DHT *dht = (DHT *)object;
|
DHT *dht = (DHT *)object;
|
||||||
|
|
||||||
char ip_str[IP_NTOA_LEN] = { 0 };
|
|
||||||
ip_ntoa(&source.ip, ip_str, sizeof(ip_str));
|
|
||||||
|
|
||||||
if (!ip_is_lan(source.ip)) {
|
if (!ip_is_lan(source.ip)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1209,7 +1209,6 @@ void ipport_copy(IP_Port *target, const IP_Port *source)
|
||||||
* converts ip into a string
|
* converts ip into a string
|
||||||
* ip_str must be of length at least IP_NTOA_LEN
|
* ip_str must be of length at least IP_NTOA_LEN
|
||||||
*
|
*
|
||||||
* IPv6 addresses are enclosed into square brackets, i.e. "[IPv6]"
|
|
||||||
* writes error message into the buffer on error
|
* writes error message into the buffer on error
|
||||||
*
|
*
|
||||||
* returns ip_str
|
* returns ip_str
|
||||||
|
@ -1235,12 +1234,8 @@ const char *ip_ntoa(const IP *ip, char *ip_str, size_t length)
|
||||||
struct in6_addr addr;
|
struct in6_addr addr;
|
||||||
fill_addr6(ip->ip.v6, &addr);
|
fill_addr6(ip->ip.v6, &addr);
|
||||||
|
|
||||||
ip_str[0] = '[';
|
|
||||||
assert(make_family(ip->family) == AF_INET6);
|
assert(make_family(ip->family) == AF_INET6);
|
||||||
inet_ntop6(&addr, &ip_str[1], length - 3);
|
inet_ntop6(&addr, ip_str, length);
|
||||||
const size_t len = strlen(ip_str);
|
|
||||||
ip_str[len] = ']';
|
|
||||||
ip_str[len + 1] = '\0';
|
|
||||||
} else {
|
} else {
|
||||||
snprintf(ip_str, length, "(IP invalid, family %u)", ip->family.value);
|
snprintf(ip_str, length, "(IP invalid, family %u)", ip->family.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,6 @@ bool ipv6_ipv4_in_v6(IP6 a);
|
||||||
* converts ip into a string
|
* converts ip into a string
|
||||||
* ip_str must be of length at least IP_NTOA_LEN
|
* ip_str must be of length at least IP_NTOA_LEN
|
||||||
*
|
*
|
||||||
* IPv6 addresses are enclosed into square brackets, i.e. "[IPv6]"
|
|
||||||
* writes error message into the buffer on error
|
* writes error message into the buffer on error
|
||||||
*
|
*
|
||||||
* returns ip_str
|
* returns ip_str
|
||||||
|
|
|
@ -13,7 +13,7 @@ TEST(IpNtoa, DoesntWriteOutOfBounds) {
|
||||||
|
|
||||||
ip_ntoa(&ip, ip_str, sizeof(ip_str));
|
ip_ntoa(&ip, ip_str, sizeof(ip_str));
|
||||||
|
|
||||||
EXPECT_EQ(std::string(ip_str), "[ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]");
|
EXPECT_EQ(std::string(ip_str), "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||||
EXPECT_LT(std::string(ip_str).length(), IP_NTOA_LEN);
|
EXPECT_LT(std::string(ip_str).length(), IP_NTOA_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user