* \return The calculated hash value
*/
-static int NameHash(const int8_t *str)
+static int NameHash(const char *str)
{
- const uint8_t *name = (const uint8_t *)str;
+ const char *name = (const char *)str;
uint32_t hash = 0;
uint32_t g;
*
* \return The next matching query or NULL
*/
-static TQuery *QueryNext(TMdnsd *mdnsd, TQuery *query, int8_t *host, int type)
+static TQuery *QueryNext(TMdnsd *mdnsd, TQuery *query, char *host, int type)
{
if (query == NULL) {
query = mdnsd->queries[NameHash(host) % SPRIME];
*
* \return The next matching cache entry or NULL
*/
-static TCached *CachedNext(TMdnsd *mdnsd, TCached *cached, uint8_t *host, int type)
+static TCached *CachedNext(TMdnsd *mdnsd, TCached *cached, char *host, int type)
{
if (cached == NULL) {
cached = mdnsd->cache[NameHash(host) % LPRIME];
*
* \return The next matching dns record or NULL
*/
-static TMdnsdRecord *RecordNext(TMdnsd *mdnsd, TMdnsdRecord *record, uint8_t *host, int type)
+static TMdnsdRecord *RecordNext(TMdnsd *mdnsd, TMdnsdRecord *record, char *host, int type)
{
if (record == NULL) {
record = mdnsd->published[NameHash(host) % SPRIME];
}
#ifdef MDNSD_DEBUG
-uint8_t *MdnsdDecodeType(uint16_t type)
+char *MdnsdDecodeType(uint16_t type)
{
switch (type) {
case QTYPE_A: return "A";
}
}
-void mdnsd_dump (FILE *file, DNSMESSAGE *msg, uint8_t *type)
+void mdnsd_dump (FILE *file, DNSMESSAGE *msg, char *type)
{
int idx;
*
* \return Maximum time after which MdnsdOutput needs to be called again
*/
-void MdnsdQuery(TMdnsd *mdnsd, uint8_t *host, int type, int (*answer)(TMdnsdAnswer *answer, void *arg), void *arg)
+void MdnsdQuery(TMdnsd *mdnsd, char *host, int type, int (*answer)(TMdnsdAnswer *answer, void *arg), void *arg)
{
TQuery *query;
TCached *current = NULL;
*
* \return next cached answer
*/
-TMdnsdAnswer *MdnsdListCachedAnswers(TMdnsd *mdnsd, uint8_t *host, int type, TMdnsdAnswer *last)
+TMdnsdAnswer *MdnsdListCachedAnswers(TMdnsd *mdnsd, char *host, int type, TMdnsdAnswer *last)
{
return (TMdnsdAnswer *)CachedNext(mdnsd, (TCached *)last, host, type);
}
*
* \return newly allocated share record
*/
-TMdnsdRecord *MdnsdAllocShared(TMdnsd *mdnsd, uint8_t *host, int type, uint32_t ttl)
+TMdnsdRecord *MdnsdAllocShared(TMdnsd *mdnsd, char *host, int type, uint32_t ttl)
{
int idx;
TMdnsdRecord *record;
*
* \return newly allocated share record
*/
-TMdnsdRecord *MdnsdAllocUnique(TMdnsd *mdnsd, uint8_t *host, int type, uint32_t ttl, void (*conflict)(TMdnsdRecord *record, uint8_t *host, int type, void *arg), void *arg)
+TMdnsdRecord *MdnsdAllocUnique(TMdnsd *mdnsd, char *host, int type, uint32_t ttl, void (*conflict)(TMdnsdRecord *record, char *host, int type, void *arg), void *arg)
{
TMdnsdRecord *record;
record = MdnsdAllocShared(mdnsd, host, type, ttl);
* \param record The record which shall be de-listed
* \param name Hostname
*/
-void MdnsdSetHost(TMdnsd *mdnsd, TMdnsdRecord *record, uint8_t *name)
+void MdnsdSetHost(TMdnsd *mdnsd, TMdnsdRecord *record, char *name)
{
free(record->rr.rdname);
record->rr.rdname = strdup(name);
* \param port TCP / UDP port number of the service
* \param name The canonical hostname of the machine providing the service.
*/
-void MdnsdSetSrv(TMdnsd *mdnsd, TMdnsdRecord *record, int priority, int weight, uint16_t port, uint8_t *name)
+void MdnsdSetSrv(TMdnsd *mdnsd, TMdnsdRecord *record, int priority, int weight, uint16_t port, char *name)
{
record->rr.srv.priority = priority;
record->rr.srv.weight = weight;
typedef struct _mdnsda_struct TMdnsdAnswer;
struct _mdnsda_struct
{
- uint8_t *name;
+ char *name;
uint16_t type;
uint32_t ttl;
uint16_t rdlen;
- uint8_t *rdata;
+ char *rdata;
struct in_addr ip; // A
uint8_t *rdname; // NS/CNAME/PTR/SRV
struct {
TMdnsdAnswer rr;
int8_t unique; // # of checks performed to ensure
int tries;
- void (*conflict)(TMdnsdRecord *record, uint8_t *name, int type, void *arg);
+ void (*conflict)(TMdnsdRecord *record,char *name, int type, void *arg);
void *arg;
TMdnsdRecord *next;
TMdnsdRecord *list;
typedef struct _query_struct TQuery;
struct _query_struct
{
- uint8_t *name;
+ char *name;
int type;
uint32_t nexttry;
int tries;
struct timeval *MdnsdGetMaxSleepTime(TMdnsd *mdnsd);
/* Qery / Answer functions */
-void MdnsdQuery(TMdnsd *mdnsd, uint8_t *host, int type, int (*answer)(TMdnsdAnswer *a, void *arg), void *arg);
-TMdnsdAnswer *MdnsdListCachedAnswers(TMdnsd *mdnsd, uint8_t *host, int type, TMdnsdAnswer *last);
+void MdnsdQuery(TMdnsd *mdnsd, char *host, int type, int (*answer)(TMdnsdAnswer *a, void *arg), void *arg);
+TMdnsdAnswer *MdnsdListCachedAnswers(TMdnsd *mdnsd, char *host, int type, TMdnsdAnswer *last);
/* Publishing functions */
-TMdnsdRecord *MdnsdAllocUnique(TMdnsd *mdnsd, uint8_t *host, int type, uint32_t ttl, void (*conflict)(TMdnsdRecord *record, uint8_t *host, int type, void *arg), void *arg);
-TMdnsdRecord *MdnsdAllocShared(TMdnsd *mdnsd, uint8_t *host, int type, uint32_t ttl);
+TMdnsdRecord *MdnsdAllocUnique(TMdnsd *mdnsd, char *host, int type, uint32_t ttl, void (*conflict)(TMdnsdRecord *record, char *host, int type, void *arg), void *arg);
+TMdnsdRecord *MdnsdAllocShared(TMdnsd *mdnsd, char *host, int type, uint32_t ttl);
void MdnsdDone(TMdnsd *mdnsd, TMdnsdRecord *record);
/* These all set/update the data for the given record, nothing is published until they are called */
void MdnsdSetRaw(TMdnsd *mdnsd, TMdnsdRecord *record, uint8_t *data, int len);
-void MdnsdSetHost(TMdnsd *mdnsd, TMdnsdRecord *record, uint8_t *name);
+void MdnsdSetHost(TMdnsd *mdnsd, TMdnsdRecord *record, char *name);
void MdnsdSetIp(TMdnsd *mdnsd, TMdnsdRecord *record, struct in_addr ip);
-void MdnsdSetSrv(TMdnsd *mdnsd, TMdnsdRecord *record, int priority, int weight, uint16_t port, uint8_t *name);
+void MdnsdSetSrv(TMdnsd *mdnsd, TMdnsdRecord *record, int priority, int weight, uint16_t port, char *name);
#endif
* \param buf Pointer to the package data buffer
* \param namep Pointer to the string buffer, where the label will be copied to
*/
-static void ExtractLabel(DNSMESSAGE *msg, uint8_t **buf, uint8_t **namep)
+static void ExtractLabel(DNSMESSAGE *msg, uint8_t **buf, char **namep)
{
uint8_t *label;
- uint8_t *name;
+ char *name;
int x;
/* Set the name pointer to the end of the data block */
}
/* Copy label to the name buffer */
- memcpy(name, label+1,*label);
+ memcpy(name, label+1, *label);
name[*label] = '.';
name += *label + 1;
*
* \return Length of the label
*/
-static int Host2Label(DNSMESSAGE *msg, uint8_t **buf, uint8_t *name)
+static int Host2Label(DNSMESSAGE *msg, uint8_t **buf, char *name)
{
uint8_t label[MAX_LABEL_SIZE];
uint8_t *l;
* \param class Query class
* \param ttl TTL value
*/
-static void DnsAppendRR(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl)
+static void DnsAppendRR(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl)
{
if (msg->buf == 0) {
/* Initialise the buffer pointer */
* \param type Query type
* \param class Query class
*/
-void DnsMsgAdd_qd(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class)
+void DnsMsgAdd_qd(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class)
{
msg->qdcount++;
if (msg->buf == 0) {
* \param type Query type
* \param class Query class
*/
-void DnsMsgAdd_an(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl)
+void DnsMsgAdd_an(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl)
{
msg->ancount++;
DnsAppendRR(msg, name, type, class, ttl);
* \param type Query type
* \param class Query class
*/
-void DnsMsgAdd_ns(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl)
+void DnsMsgAdd_ns(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl)
{
msg->nscount++;
DnsAppendRR(msg, name, type, class, ttl);
* \param type Query type
* \param class Query class
*/
-void DnsMsgAdd_ar(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl)
+void DnsMsgAdd_ar(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl)
{
msg->arcount++;
DnsAppendRR(msg, name, type, class, ttl);
* \param msg DNS message
* \param name Hostname
*/
-void DnsMsgAdd_rdata_name(DNSMESSAGE *msg, uint8_t *name)
+void DnsMsgAdd_rdata_name(DNSMESSAGE *msg, char *name)
{
uint8_t *tmp_buf = msg->buf;
msg->buf += 2;
* \param port TCP / UDP port number of the service
* \param name The canonical hostname of the machine providing the service.
*/
-void DnsMsgAdd_rdata_srv(DNSMESSAGE *msg, uint16_t priority, uint16_t weight, uint16_t port, uint8_t *name)
+void DnsMsgAdd_rdata_srv(DNSMESSAGE *msg, uint16_t priority, uint16_t weight, uint16_t port, char *name)
{
uint8_t *tmp_buf = msg->buf;
msg->buf += 2;
*/
typedef struct
{
- uint8_t *name;
+ char *name;
uint16_t type;
uint16_t class;
} DNSQUESTION;
*/
typedef struct
{
- uint8_t *name;
+ char *name;
uint16_t type;
uint16_t class;
uint32_t ttl;
union {
struct {
uint32_t ip;
- uint8_t *name;
+ char *name;
} a;
struct {
- uint8_t *name;
+ char *name;
} ns;
struct {
- uint8_t *name;
+ char *name;
} cname;
struct {
- uint8_t *name;
+ char *name;
} ptr;
struct {
uint16_t priority;
uint16_t weight;
uint16_t port;
- uint8_t *name;
+ char *name;
} srv;
} known;
} DNSRESOURCE;
DNSRESOURCE *ar;
/* internal variables */
- uint8_t* buf;
- uint8_t* labels[MAX_LABEL];
+ uint8_t *buf;
+ uint8_t *labels[MAX_LABEL];
int len;
int label;
DNSMESSAGE *DnsCreateMsg(void);
/* Append a question to the message buffer */
-void DnsMsgAdd_qd(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class);
+void DnsMsgAdd_qd(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class);
/* Append a resource record to the message. Call these functions in the below order. */
-void DnsMsgAdd_an(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl);
-void DnsMsgAdd_ns(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl);
-void DnsMsgAdd_ar(DNSMESSAGE *msg, uint8_t *name, uint16_t type, uint16_t class, uint32_t ttl);
+void DnsMsgAdd_an(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
+void DnsMsgAdd_ns(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
+void DnsMsgAdd_ar(DNSMESSAGE *msg, char *name, uint16_t type, uint16_t class, uint32_t ttl);
/* Append resource data types blocks */
void DnsMsgAdd_rdata_long(DNSMESSAGE *msg, uint32_t val);
-void DnsMsgAdd_rdata_name(DNSMESSAGE *msg, uint8_t *name);
-void DnsMsgAdd_rdata_srv(DNSMESSAGE *msg, uint16_t priority, uint16_t weight, uint16_t port, uint8_t *name);
+void DnsMsgAdd_rdata_name(DNSMESSAGE *msg, char *name);
+void DnsMsgAdd_rdata_srv(DNSMESSAGE *msg, uint16_t priority, uint16_t weight, uint16_t port, char *name);
void DnsMsgAdd_rdata_raw(DNSMESSAGE *msg, uint8_t *rdata, uint16_t rdlength);
/* Generate the message packet to be send out and return the length */