getaddrinfo



  • folgendes problem:

    Ich will diese neue Funktion nutzen, genauso wie das gegenstück: getnameinfo
    ABER ... Obwohl ich den benötigten Header "Ws2tcpip.h" und natürlich die lib gelinkt hab, wird gesagt, sie sei nicht definiert. Aber daran liegt es nicht. Eher an folgender Codeeinschränkung:

    Code stammt aus dem Header "Ws2tcpip.h"...

    #if (_WIN32_WINNT >= 0x0501) // Klar es liegt daran
    void WSAAPI freeaddrinfo (struct addrinfo*);
    int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
    		        struct addrinfo**);
    int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
    		       char*,DWORD,int);
    #else
    /* FIXME: Need WS protocol-independent API helpers.  */
    #endif
    

    Aber wieso habt ihr ne Idee ?

    Gruß Chris



  • Nutzt du denn ein älteres Windows als XP? Diese Funktionen kann man offensichtlich nur ab WinXP einsetzen.

    Gruß Matze



  • hmm ich hab xp sp 2 + updates.. aber sollte diese funktion nicht auch unter linux einsetzbar sein ?



  • Tut mir leid, zu der Funktion und ob sie unter Linux verfügbar sein sollte kann ich leider nichts sagen. Ich weiß nur, dass der Ausdruck "WIN32_WINNT>=0x501" dafür sorgt, dass diese Funktionen nur ab XP deklariert werden.

    Hat die MSDN denn keine Erklärung parat?

    Gruß Matze



  • Das "ws" im Headernamen "ws2tcpip.h" sagt schon klar aus, dass es sich um Windows Sockets handelt. Also nichts mit Linux 😃



  • naja header und library aber nt / 2000 soll diese funktion verfügbar sein



  • hab grad was bei wikipedia gefunden

    #include <stdio.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <sys/socket.h>
    
    int main()
    {
        struct addrinfo *result;
        char hostname[NI_MAXHOST];
        int error;
    
        if (error = getaddrinfo("www.example.com", NULL, NULL, &result))
        {
            fprintf(stderr, "error using getaddrinfo: %s\n", gai_strerror(error));
        }
    
        if (result)
        {
            if (error = getnameinfo(result->ai_addr, result->ai_addrlen, hostname, sizeof(hostname), NULL,0,0))
            {
                fprintf(stderr, "error using getnameinfo: %s\n", gai_strerror(error));
            }
        }
    }
    

    Scheint wohl plattform unabhängig zu sein 🙂



  • Hast du schon bei den Projekteinstellungen unter C++->Präprozessor schon folgendes eingetragen??? "_WIN32_WINNT=0x0502;WINVER=0x0502;" Danach sollte der Compiler die Funktion finden... Wobei bei mir die Funktion so geschrieben wird: GetAddrInfo

    DEADBEEF



  • msdn schrieb:

    Support for getaddrinfo on older versions of Windows
    The getaddrinfo function was added to the Ws2_32.dll on Windows XP and later. If you want to execute an application using this function on earlier versions of Windows (Windows 2000, Windows NT, and Windows Me/98/95), then you need to include the Ws2tcpip.h file and also include the Wspiapi.h file. When the Wspiapi.h include file is added, the getaddrinfo function is defined to the WspiapiGetAddrInfo inline function in the Wspiapi.h file. At runtime, the WspiapiGetAddrInfo function is implemented in such a way that if the Ws2_32.dll or the Wship6.dll (the file containing getaddrinfo in the IPv6 Technology Preview for Windows 2000) does not include getaddrinfo, then a version of getaddrinfo is implemented inline based on code in the Wspiapi.h header file. This inline code will be used on older Windows platforms that do not natively support the getaddrinfo function.


Anmelden zum Antworten