I looked at the implementations of inet_ntoa like this and this,
I am wondering why they both allocate a buffer of 18 characters.
If I take the maximum length IPv4 address string: 255.255.255.255 the size that I need is: 3 for each octet, 3 for dots and 1 for the null terminator.
3*4+3+1 = 16.
So why do we need those 2 extra characters?
The inet_ntoa implementation from the first link:
static __thread char buffer[18];
char *
inet_ntoa (struct in_addr in)
{
unsigned char *bytes = (unsigned char *) ∈
__snprintf (buffer, sizeof (buffer), "%d.%d.%d.%d",
bytes[0], bytes[1], bytes[2], bytes[3]);
return buffer;
}