Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IF_NAMESIZE vs. IF_NAMESIZE+1

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.

like image 356
pevik Avatar asked Oct 25 '25 14:10

pevik


1 Answers

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

like image 121
Stargateur Avatar answered Oct 27 '25 03:10

Stargateur