I've been reading Beej's Guide to Network Programming and tried to compile the first few example programs (section 5.1) using the std=c11
flag with gcc
. I keep getting errors like these (showip.c
):
showip.c: In function ‘main’:
showip.c:15:21: error: storage size of ‘hints’ isn’t known
struct addrinfo hints, *res, *p;
^
showip.c:35:33: error: dereferencing pointer to incomplete type
for(p = res;p != NULL; p = p->ai_next) {
^
showip.c:41:14: error: dereferencing pointer to incomplete type
if (p->ai_family == AF_INET) { // IPv4
^
showip.c:42:63: error: dereferencing pointer to incomplete type
struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
^
showip.c:46:65: error: dereferencing pointer to incomplete type
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
^
showip.c:52:20: error: dereferencing pointer to incomplete type
inet_ntop(p->ai_family, addr, ipstr, sizeof ipstr);
However, without the c11
flag it compiles fine. What is exactly causing this incompatibility? And should I even be using C11 for these kind of things?