Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems using getaddrinfo and friends using c99 standard

30 views
Skip to first unread message

Nathan

unread,
Jun 18, 2008, 2:54:04 PM6/18/08
to
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

Antoninus Twink

unread,
Jun 18, 2008, 4:17:21 PM6/18/08
to
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>

Harald van Dijk

unread,
Jun 18, 2008, 4:37:25 PM6/18/08
to

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.

Antoninus Twink

unread,
Jun 18, 2008, 5:17:17 PM6/18/08
to
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.

Nathan

unread,
Jun 18, 2008, 5:28:49 PM6/18/08
to
On Jun 18, 5:17 pm, Antoninus Twink <nos...@nospam.invalid> wrote:
> One solution is to add -D_POSIX_C_SOURCE=200112L as a command-line
> option.

Harald is correct. I had included the required headers.

Antoninus, your solution does work, but unless I have to I would
prefer to avoid defining a (to me) obscure symbol in order to make a
standard POSIX function work. Like you said, I don't appreciate the
"feature" of gcc denying me access to these functions just because my
company uses the c99 standard.

Thanks for the help, and I'll use the above solution as a stopgap
unless (hopefully until) someone comes up with something better.

Nathan

0 new messages