Click here to Skip to main content
15,889,116 members
Articles / Desktop Programming / MFC

The Ultimate TCP/IP Home Page

Rate me:
Please Sign up or sign in to vote.
4.98/5 (77 votes)
25 Aug 2007CPOL13 min read 2.6M   45.4K   267  
Ultimate TCP-IP is now Open Source
// =================================================================
//  class: CUT_MXLookup
//  File:  mxlookup.h
//  
//  Purpose:
//
//      Performs DNS lookups specifically on MX records
//      for a given email address 
//
// ===================================================================
// Ultimate TCP/IP v4.2
// This software along with its related components, documentation and files ("The Libraries")
// is � 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is
// governed by a software license agreement ("Agreement").  Copies of the Agreement are
// available at The Code Project (www.codeproject.com), as part of the package you downloaded
// to obtain this file, or directly from our office.  For a copy of the license governing
// this software, you may contact us at legalaffairs@codeproject.com, or by calling 416-849-8900.
// ===================================================================

#ifndef DNS_MX_LOOKUP_H
#define DNS_MX_LOOKUP_H

#include "ut_clnt.h"
#include "dns_c.h"
#include "utstrlst.h"

// ===================================
//  MX Lookup class
// ===================================
class CUT_MXLookup : public CUT_DNSClient
{

protected:
    
    typedef struct UT_MXLIST{       //MXRecord structure
        LPSTR       m_szName;
        LPSTR       m_szAddress;
        long        m_nPreference;
        UT_MXLIST*      m_pNext;
    };

    UT_MXLIST* m_pMXListStart;      //MXRecord List Start Pointer
    UT_MXLIST* m_pMXListPos;        //MXRecord List Enum Pointer
    long m_nRecordCount;            //number of MXRecords found
    
    CUT_StringList m_nameServerList;//optional name servers to search with

    CUT_StringList m_usedNameServerList;//List of name servers to already used
                                        //to perform the search

    BOOL m_nIncludeDefaultRecord;   //Include flag, for default MX record
    int  m_nTCPRetryCount;          //Number of times to try a lookup using TCP/IP
    int  m_nUDPRetryCount;          //Number of times to try a lookup using UDP

    int  m_nMaxRecurseCount;        //number of levels deep to search for MX records
    int  m_nRecurseCount;           //current search level

    virtual	void ClearList();               //clear MXRecord list
    virtual	BOOL AddItem(LPSTR szName,LPSTR szAddress,long nPreference);//Add item to MXRecord list
    virtual	void AddMXRecords();            //adds the MX records from the last lookup to the MXRecord list

    virtual	int LookupMXInt(LPCSTR szDomain,LPCSTR szNameServer); //performs the actual lookup

    virtual	int GetLookupMXRecordCount();   //retrieve the number of MX records found in the last lookup

    virtual	BOOL GetDomainFromEmailAddress(LPCSTR szEmailAddress,LPSTR szDomain,int nLenDomain); //parse email address


public:

    CUT_MXLookup();             //constructor
    virtual ~CUT_MXLookup();    //destructor

    //MX record lookup function
    int     LookupMX(LPCSTR szNameServer,LPCSTR szEmailAddress);
#if defined _UNICODE
    int     LookupMX(LPCWSTR szNameServer,LPCWSTR szEmailAddress);
#endif

    //Functions to retrieve information after a successful lookup
    long    GetMXRecordCount(); 
    int     GetMXRecord(LPSTR szName,int nNameLen,LPSTR szAddress,int nAddressLen,long* nPref);
#if defined _UNICODE
    int     GetMXRecord(LPWSTR szName,int nNameLen,LPWSTR szAddress,int nAddressLen,long* nPref);
#endif

    LPCSTR   GetMXRecord();
	// v4.2 Refactored - added interface with LPSTR and LPWSTR params
	int GetMXRecord(LPSTR record, size_t maxSize, size_t *size);
#if defined _UNICODE
	int GetMXRecord(LPWSTR record, size_t maxSize, size_t *size);
#endif

    int     ResetEnum();

    //Functions for setting lookup options - set before calling LookupMX(...)
    int     IncludeDefaultRecord(BOOL bTrueFalse = TRUE);
    int     SetRetryCounts(int nTCPCount,int nUDPCount);
    int     SetMaxRecurseLevel(int nLevel);
    int     AddNameServer(LPCSTR szNameServer);
#if defined _UNICODE
    int     AddNameServer(LPCWSTR szNameServer);
#endif
    int     ClearNameServerList();
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions