/*
* pkthdr.h - packet header from wire conversion routines
*
* a Net::DNS like library for C
*
* (c) NLnet Labs, 2005-2006
*
* See the file LICENSE for the license
*/
/**
* \file
*
* Contains functions that translate dns data from the wire format (as sent
* by servers and clients) to the internal structures for the packet header.
*/
#ifndef LDNS_PKTHDR_H
#define LDNS_PKTHDR_H
#ifdef __cplusplus
extern "C" {
#endif
/* The length of the header */
#define LDNS_HEADER_SIZE 12
/* Counter of the answer section */
#define LDNS_ANCOUNT_OFF 6
#define LDNS_ANCOUNT(wirebuf) (sldns_read_uint16(wirebuf+LDNS_ANCOUNT_OFF))
#define LDNS_ANCOUNT_SET(wirebuf, i) (sldns_write_uint16(wirebuf+LDNS_ANCOUNT_OFF, i))
/* Counter of the authority section */
#define LDNS_NSCOUNT_OFF 8
#define LDNS_NSCOUNT(wirebuf) (sldns_read_uint16(wirebuf+LDNS_NSCOUNT_OFF))
#define LDNS_NSCOUNT_SET(wirebuf, i) (sldns_write_uint16(wirebuf+LDNS_NSCOUNT_OFF, i))
/* Counter of the additional section */
#define LDNS_ARCOUNT_OFF 10
#define LDNS_ARCOUNT(wirebuf) (sldns_read_uint16(wirebuf+LDNS_ARCOUNT_OFF))
#define LDNS_ARCOUNT_SET(wirebuf, i) (sldns_write_uint16(wirebuf+LDNS_ARCOUNT_OFF, i))
/**
* The sections of a packet
*/
enum sldns_enum_pkt_section {
LDNS_SECTION_QUESTION = 0,
LDNS_SECTION_ANSWER = 1,
LDNS_SECTION_AUTHORITY = 2,
LDNS_SECTION_ADDITIONAL = 3,
/** bogus section, if not interested */
LDNS_SECTION_ANY = 4,
/** used to get all non-question rrs from a packet */
LDNS_SECTION_ANY_NOQUESTION = 5
};
typedef enum sldns_enum_pkt_section sldns_pkt_section;
/* opcodes for pkt's */
enum sldns_enum_pkt_opcode {
LDNS_PACKET_QUERY = 0,
LDNS_PACKET_IQUERY = 1,
LDNS_PACKET_STATUS = 2, /* there is no 3?? DNS is weird */
LDNS_PACKET_NOTIFY = 4,
LDNS_PACKET_UPDATE = 5
};
typedef enum sldns_enum_pkt_opcode sldns_pkt_opcode;