Problems using getaddrinfo and friends using c99 standard

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nathan

    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
  • Antoninus Twink

    #2
    Re: Problems using getaddrinfo and friends using c99 standard

    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>

    Comment

    • Harald van =?UTF-8?b?RMSzaw==?=

      #3
      Re: Problems using getaddrinfo and friends using c99 standard

      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_strerro r'
      [snip]
      >ipv6_test.c:77 : warning: implicit declaration of function
      >`freeaddrinf o'
      >
      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.

      Comment

      • Antoninus Twink

        #4
        Re: Problems using getaddrinfo and friends using c99 standard

        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_SOURC E=200112L as a command-line
        option.

        Comment

        Working...