/*=========================================================================== (c) Copyright 2000, Emmanuel KARTMANN, all rights reserved =========================================================================== File : SimpleDNSClient.h $Header: $ Author : Emmanuel KARTMANN Creation : Monday 1/31/00 3:51:10 PM Remake : ------------------------------- Description ------------------------------- Declaration of the CSimpleDNSClient class. ------------------------------ Modifications ------------------------------ $Log: $ =========================================================================== */ #ifndef __SIMPLEDNSCLIENT_H_ #define __SIMPLEDNSCLIENT_H_ #include "resource.h" // main symbols ///////////////////////////////////////////////////////////////////////////// // CSimpleDNSClient /* ----------------------------------------------------------------- CLASS CSimpleDNSClient COM (ActiveX) object implementing ISimpleDNSClient, a DNS resolver. DESCRIPTION This class implements a DNS resolver within a COM object. It relies on a porting of the BIND (Berkeley Internet Name Domain) implementation of DNS. USAGE To use this class: EXAMPLE
    Dim oDNS
    Set oDNS = CreateObject("Emmanuel.SimpleDNSClient.1")

    Dim requested_name
    requested_name = "www.microsoft.com"

    Dim found_names
    found_names = ""

    ' Set the server address(es) [optional on Windows NT, mandatory on Win95/98]
    oDNS.ServerAddresses = "99.99.99.99"

    ' Set the separator
    oDNS.Separator = ";"

    On Error Resume Next
    oDNS.GetEmailServers requested_name, found_names
    If Err <> 0 Then
        MsgBox Err.Description
    Else
        ' Show resolved names (within dialog box)
        MsgBox "Found names:" & vbCrLf & vbCrLf & found_names
    End If
    
ADMINISTRATIVE Author Emmanuel KARTMANN Date Monday 1/31/00 3:52:04 PM SEE ALSO RFC1034,
RFC1035. ----------------------------------------------------------------- */ class ATL_NO_VTABLE CSimpleDNSClient : public CComObjectRootEx, public CComCoClass, public ISupportErrorInfo, public IObjectSafetyImpl, public IDispatchImpl { public: ///////////////////////////////////////////////////////////////////// // // Purpose: create an instance of the class // // Parameters: none (C++ constructor) // // Return value : none (C++ constructor) // // Description : // CSimpleDNSClient() : m_szSeparator(", ") { } DECLARE_REGISTRY_RESOURCEID(IDR_SIMPLEDNSCLIENT) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CSimpleDNSClient) COM_INTERFACE_ENTRY(ISimpleDNSClient) COM_INTERFACE_ENTRY(IDispatch) COM_INTERFACE_ENTRY(ISupportErrorInfo) COM_INTERFACE_ENTRY(IObjectSafety) END_COM_MAP() // ISupportsErrorInfo STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid); // ISimpleDNSClient public: ///////////////////////////////////////////////////////////////////// // // Purpose: return the known DNS server addresses, // as configured in your local machine (Windows Registry) // // Parameters: // // [out] pvServerAddresses // list of DNS Server addresses (separated by spaces), // in dotted notation, e.g. "192.175.235.1 192.175.234.2" // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : This function reads the registry key // HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\NameServer // to find the DNS servers on the local machine. // // This function works on Windows NT only. // STDMETHOD(FindServerAddresses)(VARIANT *pvServerAddresses); ///////////////////////////////////////////////////////////////////// // // Purpose: return value of the ServerAddresses property, // i.e. the list of DNS servers. // // Parameters: // // [out] pVal // list of DNS Server addresses (separated by spaces), // in dotted notation, e.g. "192.175.235.1 192.175.234.2" // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : The property ServerAddresses can be set // via method put_ServerAddresses(). // STDMETHOD(get_ServerAddresses)(/*[out, retval]*/ BSTR *pVal); ///////////////////////////////////////////////////////////////////// // // Purpose: set value of the ServerAddresses property, // i.e. the list of DNS servers. // // Parameters: // // [in] newVal // new list of DNS Server addresses (separated by spaces), // in dotted notation, e.g. "192.175.235.1 192.175.234.2" // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : The property ServerAddresses can be read // via method get_ServerAddresses(). // STDMETHOD(put_ServerAddresses)(/*[in]*/ BSTR newVal); ///////////////////////////////////////////////////////////////////// // // Purpose: resolve a name in DNS, i.e. send a request and // build a list (string) of results with the server's // answer(s). // // Parameters: // // [in] BSearchedNames // name of the searched resource records (multiple names allowed) // [out] pvFoundNames // list of found records (a string with every entry // separated by value of 'Separator' property). // [in] BResourceClass // class of searched record. Can be any of the following // classes: //
    //
  • C_IN: ARPA Internet (default) //
  • C_CHAOS: Chaos Net at MIT //
  • C_HS: Hesiod at MIT //
  • C_ANY: Any class //
// // [in] BResourceType // type of searched record. Can be any of the following // types: //
    //
  • T_A: host address (IPv4) (default) //
  • T_NS: authoritative server //
  • T_MD: mail destination //
  • T_MF: mail forwarder //
  • T_CNAME: canonical name //
  • T_SOA: start of authority zone //
  • T_MB: mailbox domain name //
  • T_MG: mail group member //
  • T_MR: mail rename name //
  • T_NULL: null resource record //
  • T_WKS: well known service //
  • T_PTR: domain name pointer //
  • T_HINFO: host information //
  • T_MINFO: mailbox information //
  • T_MX: mail routing information //
  • T_TXT: text strings //
  • T_RP: responsible person //
  • T_AFSDB: AFS cell database //
  • T_X25: X_25 calling address //
  • T_ISDN: ISDN calling address //
  • T_RT: router //
  • T_NSAP: NSAP address //
  • T_NSAP_PTR: reverse NSAP lookup (deprecated) //
  • T_SIG: security signature //
  • T_KEY: security key //
  • T_PX: X.400 mail mapping //
  • T_GPOS: geographical position (withdrawn) //
  • T_AAAA: IPv6 Address //
  • T_LOC: Location Information //
  • T_NXT: Next Valid Name in Zone //
  • T_EID: Endpoint identifier //
  • T_NIMLOC: Nimrod locator //
  • T_SRV: Server selection //
  • T_ATMA: ATM Address //
  • T_NAPTR: Naming Authority PoinTeR //
  • T_UINFO: user (finger) information (non standard) //
  • T_UID: user ID (non standard) //
  • T_GID: group ID (non standard) //
  • T_UNSPEC: Unspecified format (binary data/non standard) //
  • T_IXFR: incremental zone transfer //
  • T_AXFR: transfer zone of authority //
  • T_MAILB: transfer mailbox records //
  • T_MAILA: transfer mail agent records //
  • T_ANY: wildcard match //
// // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : IP addresses are returned in dotted notation (e.g. "123.123.123.123") // STDMETHOD(Resolve)(/*[in]*/ BSTR BSearchedNames, /*[out]*/ VARIANT *pvFoundNames, /*[in, optional, defaultvalue("C_IN")]*/ BSTR BResourceClass, /*[in, optional, defaultvalue("T_A")]*/ BSTR BResourceType); ///////////////////////////////////////////////////////////////////// // // Purpose: get the Email (SMTP) Servers for a given domain // // Parameters: // // [in] BDomainName // domain name to look for. Note that if this parameter // is empty, the domain name for local machine will be // used (see method GetDNSDomain()). // [out] pvEmailServerNames // list of found server names (a string with every entry // separated by value of 'Separator' property). // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : SMTP servers are declared in the DNS database. // This function calls method Resolve() with class // "C_IN" and type "T_MX" for the given domain; the // returned records, if any, consist in the SMTP // servers declared for that domain. // STDMETHOD(GetEmailServers)(/*[in, optional, defaultvalue("")]*/ BSTR BDomainName, /*[out]*/ VARIANT *pvEmailServerNames); ///////////////////////////////////////////////////////////////////// // // Purpose: return the string used to separate // multiple results of method Resolve() // // Parameters: // // [out] pVal // separator string (defaults to ", ") // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : // STDMETHOD(get_Separator)(/*[out, retval]*/ BSTR *pVal); ///////////////////////////////////////////////////////////////////// // // Purpose: set the string used to separate // multiple results of method Resolve() // // Parameters: // // [in] newVal // new separator string // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : // STDMETHOD(put_Separator)(/*[in]*/ BSTR newVal); ///////////////////////////////////////////////////////////////////// // // Purpose: returns the DNS domain as defined in machine // configuration (Windows Registry). // // Parameters: // // [out] pvDNSDomainName // DNS domain name (e.g. "kartmann.org"). // // Return value : HRESULT = S_OK for success, // otherwise an error occurred // // Description : This function works on Windows NT only. // // STDMETHOD(GetDNSDomain)(/*[out]*/ VARIANT *pvDNSDomainName); STDMETHOD(GetInterfaceSafetyOptions)(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions); STDMETHOD(SetInterfaceSafetyOptions)(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions); protected: BOOL BuildListFromString(LPCTSTR lpszStringWithSeparators, CStringList &oList); BOOL BuildStringFromList(CStringList &oList, CString &szStringWithSeparators); CString m_szServerAddresses; CString m_szSeparator; HRESULT SetError(LPCTSTR lpszErrorMessage, DWORD dwLastError = 0); CString FindFirstDNSServer(void); CString FindAllDNSServers(void); BOOL AppendResult(int nRequestedType, int nType, LPCTSTR lpszResult, CString &szTotalResult); CString GetParentDomainName(LPCTSTR lpszDomainName); BOOL AddDomain(CStringList &oDNSDomainList, LPCTSTR lpszDomainName); HRESULT ResolveOne(/*[in]*/ BSTR BSearchedName, /*[out]*/ VARIANT *pvFoundNames, /*[in, optional, defaultvalue("C_IN")]*/ BSTR BResourceClass, /*[in, optional, defaultvalue("T_A")]*/ BSTR BResourceType); HRESULT ResolveMultiple(/*[in]*/ BSTR BSearchedNames, /*[out]*/ VARIANT *pvFoundNames, /*[in, optional, defaultvalue("C_IN")]*/ BSTR BResourceClass, /*[in, optional, defaultvalue("T_A")]*/ BSTR BResourceType); }; #endif //__SIMPLEDNSCLIENT_H_