WIFI_API_20150524e

WIFI_Driver/nmc/cyntec_dns.h

Committer:
Marcomissyou
Date:
2015-06-09
Revision:
0:a2de37bf5f3d

File content as of revision 0:a2de37bf5f3d:

#ifndef CYNTEC_DNS_H
#define CYNTEC_DNS_H

#include <stdint.h>

class DnsClient
{
private:

//    class Hander {
//    private:

//        uint16_t *handerMsg = 0;
//        uint16_t *transactionId = 0;  //A 16 bit identifier assigned by the program that generates any kind of query.
//        uint16_t *handerSecondRow = 0;
//        uint16_t *qdCount = 0;
//        uint16_t *anCount = 0;
//        uint16_t *nsCount = 0;
//        uint16_t *arCount = 0;

//    public:
//        Hander();
//        Hander(uint16_t *msg);
//        uint16_t getTransactionId();
//        uint8_t getQueryOrRespone();
//        uint8_t getOpCode();
//        uint8_t getAuthoritativeAnswer();
//        uint8_t getTrunCation();
//        uint8_t getRecursionDesired();
//        uint8_t getRecursionAvailable();
//        uint8_t getZ();
//        uint8_t getResponseCode();
//        uint16_t *getQdCountget();
//        uint16_t *getAnCount();
//        uint16_t *getNsCount();
//        uint16_t *getArCount();
//    };

//    class Question {
//    private:
//        Question(char *msg);
//        char *questionMsg = 0;
//        char *QName = 0; // a domain name represented as a sequence of labels.
//        char *QType[2]; //a two octet code which specifies the type of the query.
//        char *QClass[2]; //a two octet code that specifies the class of the query.
//    public:
//        const char* getQName();
//        const char* getQType();
//        const char* getQClass();
//    };

//    class RRecord{
//    private:
//        RRecord(char *msg);
//        char *rRecordMsg;
//        char *RRName; // a domain name to which this resource record pertains.
//        char *RRType[2]; //two octets containing one of the RR type codes
//        char *RRClass[2]; //two octets which specify the class of the data in the RDATA field.
//        char *RRTll[4]; // a domain name represented as a sequence of labels.
//        char *RdLength[2]; //an unsigned 16 bit integer that specifies the length in octets of the RDATA field.
//        char *RData[2]; //a variable length string of octets that describes the resource.
//    public:
//        const char* getRRName();
//        const char* getRRType();
//        const char* getRRClass();
//        const char* getRRTll();
//        const char* getRdLength();
//        const char* getRData();
//    };

    const char *queryMsg;
    char *queryEcMsg;
    short queryId;
    int querySize;

    char *answerMsg;
    short answerId;
    int iPCounters;
    char **answerIPs;
//    Hander *ptrHander = 0;
//    Question *ptrQuestion = 0;
//    RRecord *ptrRRcoed = 0;

    /**
     *		QR (1 bit)
     * 	query (0), or a response (1).
     *
     *		OpCode (4 bits)
     *	0 a standard query (QUERY)
     *	1 an inverse query (IQUERY)
     *	2 a server status request (STATUS)
     *	3-15 reserved for future use
     *
     * 		Authoritative Answer (1 bit)
     * 	this bit is valid in responses,
     * 	and specifies that the responding name server is an
     * 	authority for the domain name in question section.
     *
     *		TrunCation (1 bit)
     *	specifies that this message was truncated
     * 	due to length greater than that permitted on the
     * 	transmission channel.
     *
     *		Recursion Desired (1 bit)
     *	this bit may be set in a query and is copied into the response.
     *
     * 		Recursion Available (1 bit)
     * 	this be is set or cleared in a
     * 	response, and denotes whether recursive query support is
     * 	available in the name server.
     *
     * 		Z (3 bits)
     * 	 Reserved for future use.
     *
     *	Response code (4 bits)
     * 	this 4 bit field is set as part of responses.
     */

    char *queryEncode();
    void queryAddHeader(char *startChar);
    void queryAddQuestion(char *startChar);
//    void queryAddRRFrom(char *dst);

    short parseAnswerId(char *answerMsg);
    char **parseAnswerIPs(char *answerMsg);


public:
    DnsClient(const char *msg);
    ~DnsClient();

    int getQuerySize();
    char *getQueryEncode();
    short getQueryID();

    void *answerDecode(char *msg);
    short getAnswerId();
    int getIpCounters();
    const char** getAnswerIPs();

//    void *responseDecode();
//    Hander *getHander();
//    Question *getQuestion();
//    RRecord *getRRecord();

};

#endif // CYNTEC_DNS_H