When I use IF_NAMESIZE (from net/if.h in libc implementations) as array size, should I use it as it is or with + 1 for \0 (null byte)?
char iface[IF_NAMESIZE];
or
char iface[IF_NAMESIZE + 1];
I see it using both ways across various open source projects.
The header shall define the following symbolic constant for the length of a buffer containing an interface name (including the terminating NULL character):
IF_NAMESIZE Interface name length.
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/net_if.h.html
So:
char iface[IF_NAMESIZE];
is enough
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With