470,849 Members | 1,133 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

Problems using getaddrinfo and friends using c99 standard

Hi,

I'm trying to do some network programming, but when I use 'struct
addrinfo' or getaddrinfo, I see errors:
[ ~/src/_sandbox] gcc --std=c99 -Wall ipv6_test.c -o it
ipv6_test.c: In function `main':
ipv6_test.c:25: error: storage size of 'hints' isn't known
ipv6_test.c:34: warning: implicit declaration of function
`getaddrinfo'
ipv6_test.c:38: error: dereferencing pointer to incomplete type
ipv6_test.c:39: error: dereferencing pointer to incomplete type
ipv6_test.c:40: error: dereferencing pointer to incomplete type
ipv6_test.c:41: error: dereferencing pointer to incomplete type
ipv6_test.c:49: error: dereferencing pointer to incomplete type
ipv6_test.c:49: error: dereferencing pointer to incomplete type
ipv6_test.c:49: error: dereferencing pointer to incomplete type
ipv6_test.c:56: warning: implicit declaration of function
`gai_strerror'
ipv6_test.c:56: warning: format argument is not a pointer (arg 4)
ipv6_test.c:71: error: dereferencing pointer to incomplete type
ipv6_test.c:71: error: dereferencing pointer to incomplete type
ipv6_test.c:77: warning: implicit declaration of function
`freeaddrinfo'
ipv6_test.c:25: warning: unused variable `hints'

However, it builds fine when I remove --std-c99

Does anyone know the reason for this?

Thanks,
Nathan
Jun 27 '08 #1
3 7861
On 18 Jun 2008 at 18:54, Nathan wrote:
I'm trying to do some network programming, but when I use 'struct
addrinfo' or getaddrinfo, I see errors:
[snip]
ipv6_test.c:34: warning: implicit declaration of function `getaddrinfo'
[snip]
ipv6_test.c:56: warning: implicit declaration of function `gai_strerror'
[snip]
ipv6_test.c:77: warning: implicit declaration of function `freeaddrinfo'
You're probably not including the reqired headers. Try

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

Jun 27 '08 #2
On Wed, 18 Jun 2008 20:17:21 +0000, Antoninus Twink wrote:
On 18 Jun 2008 at 18:54, Nathan wrote:
>I'm trying to do some network programming, but when I use 'struct
addrinfo' or getaddrinfo, I see errors:
[snip]
>ipv6_test.c:34: warning: implicit declaration of function `getaddrinfo'
[snip]
>ipv6_test.c:56: warning: implicit declaration of function
`gai_strerror'
[snip]
>ipv6_test.c:77: warning: implicit declaration of function
`freeaddrinfo'

You're probably not including the reqired headers. Try

#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
The OP probably is including the required headers, or the compiler would
also have complained without the --std-c99 option. The answer is simply
that getaddrinfo is not a C99 function, and is therefore not declared by
the library when asking for a C99 implementation.
Jun 27 '08 #3
On 18 Jun 2008 at 20:37, Harald van Dijk wrote:
The OP probably is including the required headers, or the compiler would
also have complained without the --std-c99 option. The answer is simply
that getaddrinfo is not a C99 function, and is therefore not declared by
the library when asking for a C99 implementation.
I think you're right. That seems like a terrible misfeature of gcc. If I
have a C program and I include a POSIX header, I damn well want the
functions from that header, in just the same way as if I include my own
header file then I want access to those functions, without the compiler
getting all holier-than-thou and telling me my functions aren't
mentioned in the C standard.

One solution is to add -D_POSIX_C_SOURCE=200112L as a command-line
option.

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Vidyasagara Guntaka | last post: by
4 posts views Thread by edcdave | last post: by
1 post views Thread by mirandacascade | last post: by
3 posts views Thread by Thomas Dybdahl Ahle | last post: by
4 posts views Thread by Eric Lilja | last post: by
1 post views Thread by Karl Chen | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.