int
main(void)
{
- rdata_t *new;
- printf("size %u\n", (unsigned int)sizeof(struct struct_rdata_t));
+ t_rdata_field *new;
new = rd_new(20, RD_DNAME_T, (uint8_t*)"hallo.nl");
- xprintf_rd(new);
+ xprintf_rd_field(new);
return 0;
}
*
* Contains the information about the packet itself
*/
-struct struct_header_type
+struct type_struct_header
{
/** \brief Id of a packet */
uint16_t id;
/** \brief Authentic data */
uint8_t ad:1;
/** \brief Query type */
- uint8_t opcode;
+ uint8_t opcode; /* XXX 8 bits? */
/** \brief Response code */
uint8_t rcode;
/** \brief question sec */
- uint8_t qdcount;
+ uint16_t qdcount;
/** \brief answer sec */
- uint8_t ancount;
+ uint16_t ancount;
/** \brief auth sec */
- uint8_t nscount;
+ uint16_t nscount;
/** \brief add sec */
- uint8_t acount;
+ uint16_t acount;
};
-typedef struct struct_header_type header_t;
+typedef struct type_struct_header t_header;
/**
* \brief DNS packet
struct struct_packet_type
{
/** \brief header section */
- header_t *header;
+ t_header *header;
/** \brief question section */
- rrset_t *question;
+ t_rrset *question;
/** \brief answer section */
- rrset_t *answer;
+ t_rrset *answer;
/** \brief auth section */
- rrset_t *authority;
+ t_rrset *authority;
/** \brief add section */
- rrset_t *additional;
+ t_rrset *additional;
};
-typedef struct struct_packet_type packet_t;
+typedef struct type_struct_packet t_packet;
#endif /* _PACKET_H */
/* util.c */
void *xmalloc(size_t);
-void xprintf_rd(rdata_t *);
+void xprintf_rd_field(t_rdata_field *);
#endif /* _PROTOTYPE_H */
/* read */
uint16_t
-rd_size(rdata_t *rd)
+rd_size(t_rdata_field *rd)
{
return rd->_size;
}
-rd_type_t
-rd_type(rdata_t *rd)
+t_rd_type
+rd_type(t_rdata_field *rd)
{
return rd->_type;
}
uint8_t *
-rd_data(rdata_t *rd)
+rd_data(t_rdata_field *rd)
{
return rd->_data;
}
/* write */
void
-rd_set_size(rdata_t *rd, uint16_t s)
+rd_set_size(t_rdata_field *rd, uint16_t s)
{
rd->_size = s;
}
void
-rd_set_type(rdata_t *rd, rd_type_t t)
+rd_set_type(t_rdata_field *rd, t_rd_type t)
{
rd->_type = t;
}
void
-rd_set_data(rdata_t *rd, uint8_t *d, uint16_t s)
+rd_set_data(t_rdata_field *rd, uint8_t *d, uint16_t s)
{
rd->_data = xmalloc(s);
memcpy(rd->_data, d, s);
}
-/* allocate a new rdata_t structure
+/* allocate a new t_rdata_field structure
* and return it
*/
-rdata_t *
-rd_new(uint16_t s, rd_type_t t, uint8_t *d)
+t_rdata_field *
+rd_new(uint16_t s, t_rd_type t, uint8_t *d)
{
- rdata_t *new;
- new = xmalloc(sizeof(rdata_t));
+ t_rdata_field *new;
+ new = xmalloc(sizeof(t_rdata_field));
if (NULL == new)
return NULL;
return(new);
}
-/* allocate a new rdata_t from
+/* allocate a new t_rdata_field from
* a NULL terminated string
* and return it
*
* uint8_t == char !!!!
*/
-rdata_t *
-rd_new_frm_string(rd_type_t t, char *s)
+t_rdata_field *
+rd_new_frm_string(t_rd_type t, char *s)
{
- rdata_t *new;
- new = xmalloc(sizeof(rdata_t));
+ t_rdata_field *new;
+ new = xmalloc(sizeof(t_rdata_field));
if (NULL == new)
return NULL;
return(new);
}
-void rd_destroy(rdata_t *rd)
+void rd_destroy(t_rdata_field *rd)
{
rd = NULL; /* kuch */
/* empty */
#include <stdint.h>
-enum enum_rdata_type
+enum type_enum_rdata
{
/** domain name */
RD_DNAME_T,
/** location data */
RD_LOC_T
};
-typedef enum enum_rdata_type rd_type_t;
+typedef enum type_enum_rdata t_rd_type;
-enum enum_class_type
+enum type_enum_class
{
/** the Internet */
CLASS_IN = 1,
/** Any class */
CLASS_ANY = 255
};
-typedef enum enum_class_type class_t;
+typedef enum type_enum_class t_class;
/**
* \brief Resource record data
* The data is a network ordered array of bytes, which size is specified by the (16-bit) size field.<br>
* To correctly parse it, use the type specified in the (16-bit) type field.
*/
-struct struct_rdata_t
+struct type_struct_rdata_field
{
/** \brief The size of the data (in bytes) */
uint16_t _size;
/** \brief The type of the data */
- rd_type_t _type;
+ t_rd_type _type;
/** \brief Pointer to the data (byte buffer) */
uint8_t *_data;
};
-typedef struct struct_rdata_t rdata_t;
+typedef struct type_struct_rdata_field t_rdata_field;
/* prototypes */
-uint16_t rd_size(rdata_t *);
-uint8_t *rd_data(rdata_t *);
-void rd_set_size(rdata_t *, uint16_t);
-void rd_set_type(rdata_t *, rd_type_t);
-void rd_set_data(rdata_t *, uint8_t *, uint16_t);
-rd_type_t rd_type(rdata_t *);
-rdata_t *rd_new(uint16_t, rd_type_t, uint8_t *);
-void rd_destroy(rdata_t *);
+uint16_t rd_size(t_rdata_field *);
+uint8_t *rd_data(t_rdata_field *);
+void rd_set_size(t_rdata_field *, uint16_t);
+void rd_set_type(t_rdata_field *, t_rd_type);
+void rd_set_data(t_rdata_field *, uint8_t *, uint16_t);
+t_rd_type rd_type(t_rdata_field *);
+t_rdata_field *rd_new(uint16_t, t_rd_type, uint8_t *);
+void rd_destroy(t_rdata_field *);
#endif /* _RDATA_H */
*
* This is the basic DNS element that contains actual data
*/
-struct struct_rr_type
+struct type_struct_rr
{
/** \brief Owner name, uncompressed */
uint8_t *owner;
*
* name chosen to avoid clash with class keyword
*/
- class_t klass;
+ t_class klass;
/* everything in the rdata is in network order */
/** \brief The list of data's */
- rdata_t *rdata;
+ t_rdata_field *rdata_fields;
};
-typedef struct struct_rr_type rr_t;
+typedef struct type_struct_rr t_rr;
/**
* \brief Resource Record Set
* Contains a list of rr's <br>
* No official RFC-like checks are made
*/
-struct t_rrset_type
+struct type_struct_rrset
{
- rr_t *rrs;
+ t_rr *rrs;
};
-typedef struct t_rrset_type rrset_t;
+typedef struct type_struct_rrset t_rrset;
#endif /* _RR_H */
/* put this here tmp. for debugging */
void
-xprintf_rd(rdata_t *rd)
+xprintf_rd_field(t_rdata_field *rd)
{
/* assume printable string */
fprintf(stdout, "size\t:%u\n", (unsigned int)rd_size(rd));