NSLookup in C Programm durchführen!



  • Hallo Leutz...ich hab da mal ne dringende Frage und hoffe, dass ihr mir mal wieder helfen könnt! Beim HTTP Server hat das ja auch ganz gut geklappt! Naja auf jeden fall soll ich nun erstmal einen SMTP Server programmieren und bin soweit auch ganz gut vorangekommen!

    Nun mein Problem! Also ich bekomme die Nachricht von meinem Client (Outlook Express) auf meinen Server via SMTP Protokoll! Nun möchte ich die Mail natürlich von meinem Server an den entsprechenden Empfänger schicken! Dazu brauch ich ja den genauen Mailserver des jeweiligen Empfängers um ein Connect mit ihm herzustellen. Das Problem ist nun, dass ich ja nur die Domain habe, also das was in der E-Mail nach dem @ folgt, da fehlt mir ja noch der prefix und der ist von Empfänger zu Empfäner verschiedend.

    Lösung hatte ich ir jetzt gedacht ist ganz einfach sowas wir ein NSLookup machen, also über die MXRecords an die komplette DNS heranzukommen.

    Wenn ich NSLookup in der Windows Komandozeile öffne und dann MXRecord für z.B. gmx.de mache, dann bekomme ich die mailserver von gmx.

    Genau soetwas möchte ich in meinem C-Code machen!

    kennt da jemand vll eine bereits vorhandene Funktion? ich hab das bislang nichts gefunden und schon ne weile gesucht!

    Das einzige das ich bislang gefunden habe ist DnsQuery, aber da ist die msdn sehr verwirrend und ich weiß nicht ob ich das verwenden kann.

    Bitte um hilfe und ein beispiel wäre mehr als überragend! 😉



  • The Windows Sockets gethostbyname function gets host information corresponding to a hostname.

    struct hostent FAR * gethostbyname (

    const char FAR * name
    );
    Parameters

    name

    [out] A pointer to the null terminated name of the host.

    Remarks

    gethostbyname returns a pointer to a hostent structure. The contents of this structure correspond to the hostname name.
    The pointer which is returned points to a structure which is allocated by Windows Sockets. The application must never attempt to modify this structure or to free any of its components. Furthermore, only one copy of this structure is allocated per thread, and so the application should copy any information which it needs before issuing any other Windows Sockets function calls.

    gethostbyname does not resolve IP address strings passed to it. Such a request is treated exactly as if an unknown host name were passed. An application with an IP address string to resolve should use inet_addr to convert the string to an IP address, then gethostbyaddr to obtain the hostent structure.
    gethostbyname will resolve the string returned by a successful call to gethostname.

    Return Values

    If no error occurs, gethostbyname returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.



  • DnsQuery


Anmelden zum Antworten