1
0
mirror of https://frontier.innolan.net/rainlance/c-ares.git synced 2025-10-06 09:09:33 +00:00

ares_dns.h: adjust DNS__16BIT and DNS__32BIT macro definitions

Fixing compiler warnings existing definitions triggered on these.
This commit is contained in:
Yang Tse
2011-08-21 19:18:53 +02:00
parent b816675c0f
commit 1089cf6052
4 changed files with 34 additions and 21 deletions

20
adig.c
View File

@ -649,7 +649,7 @@ static const unsigned char *display_rr(const unsigned char *aptr,
*/ */
if (dlen < 2) if (dlen < 2)
return NULL; return NULL;
printf("\t%d", DNS__16BIT(aptr)); printf("\t%d", (int)DNS__16BIT(aptr));
status = ares_expand_name(aptr + 2, abuf, alen, &name.as_char, &len); status = ares_expand_name(aptr + 2, abuf, alen, &name.as_char, &len);
if (status != ARES_SUCCESS) if (status != ARES_SUCCESS)
return NULL; return NULL;
@ -676,10 +676,10 @@ static const unsigned char *display_rr(const unsigned char *aptr,
p += len; p += len;
if (p + 20 > aptr + dlen) if (p + 20 > aptr + dlen)
return NULL; return NULL;
printf("\t\t\t\t\t\t( %lu %lu %lu %lu %lu )", printf("\t\t\t\t\t\t( %u %u %u %u %u )",
(unsigned long)DNS__32BIT(p), (unsigned long)DNS__32BIT(p+4), DNS__32BIT(p), DNS__32BIT(p+4),
(unsigned long)DNS__32BIT(p+8), (unsigned long)DNS__32BIT(p+12), DNS__32BIT(p+8), DNS__32BIT(p+12),
(unsigned long)DNS__32BIT(p+16)); DNS__32BIT(p+16));
break; break;
case T_TXT: case T_TXT:
@ -723,9 +723,9 @@ static const unsigned char *display_rr(const unsigned char *aptr,
* priority, weight, and port, followed by a domain name. * priority, weight, and port, followed by a domain name.
*/ */
printf("\t%d", DNS__16BIT(aptr)); printf("\t%d", (int)DNS__16BIT(aptr));
printf(" %d", DNS__16BIT(aptr + 2)); printf(" %d", (int)DNS__16BIT(aptr + 2));
printf(" %d", DNS__16BIT(aptr + 4)); printf(" %d", (int)DNS__16BIT(aptr + 4));
status = ares_expand_name(aptr + 6, abuf, alen, &name.as_char, &len); status = ares_expand_name(aptr + 6, abuf, alen, &name.as_char, &len);
if (status != ARES_SUCCESS) if (status != ARES_SUCCESS)
@ -736,8 +736,8 @@ static const unsigned char *display_rr(const unsigned char *aptr,
case T_NAPTR: case T_NAPTR:
printf("\t%d", DNS__16BIT(aptr)); /* order */ printf("\t%d", (int)DNS__16BIT(aptr)); /* order */
printf(" %d\n", DNS__16BIT(aptr + 2)); /* preference */ printf(" %d\n", (int)DNS__16BIT(aptr + 2)); /* preference */
p = aptr + 4; p = aptr + 4;
status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len); status = ares_expand_string(p, abuf, alen, &name.as_uchar, &len);

View File

@ -1,5 +1,7 @@
#ifndef HEADER_CARES_DNS_H
#define HEADER_CARES_DNS_H
/* Copyright 1998 by the Massachusetts Institute of Technology. /* Copyright 1998, 2011 by the Massachusetts Institute of Technology.
* *
* Permission to use, copy, modify, and distribute this * Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without * software and its documentation for any purpose and without
@ -14,12 +16,23 @@
* without express or implied warranty. * without express or implied warranty.
*/ */
#ifndef ARES__DNS_H /*
#define ARES__DNS_H * Macro DNS__16BIT reads a network short (16 bit) given in network
* byte order, and returns its value as an unsigned short.
*/
#define DNS__16BIT(p) ((unsigned short)((unsigned int) 0xffff & \
(((unsigned int)((unsigned char)(p)[0]) << 8U) | \
((unsigned int)((unsigned char)(p)[1])))))
#define DNS__16BIT(p) (((p)[0] << 8) | (p)[1]) /*
#define DNS__32BIT(p) (((p)[0] << 24) | ((p)[1] << 16) | \ * Macro DNS__32BIT reads a network long (32 bit) given in network
((p)[2] << 8) | (p)[3]) * byte order, and returns its value as an unsigned int.
*/
#define DNS__32BIT(p) ((unsigned int) \
(((unsigned int)((unsigned char)(p)[0]) << 24U) | \
((unsigned int)((unsigned char)(p)[1]) << 16U) | \
((unsigned int)((unsigned char)(p)[2]) << 8U) | \
((unsigned int)((unsigned char)(p)[3]))))
#define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \ #define DNS__SET16BIT(p, v) (((p)[0] = (unsigned char)(((v) >> 8) & 0xff)), \
((p)[1] = (unsigned char)((v) & 0xff))) ((p)[1] = (unsigned char)((v) & 0xff)))
@ -87,4 +100,4 @@
#define DNS_RR_SET_TTL(r) DNS__SET32BIT((r) + 4, v) #define DNS_RR_SET_TTL(r) DNS__SET32BIT((r) + 4, v)
#define DNS_RR_SET_LEN(r) DNS__SET16BIT((r) + 8, v) #define DNS_RR_SET_LEN(r) DNS__SET16BIT((r) + 8, v)
#endif /* ARES__DNS_H */ #endif /* HEADER_CARES_DNS_H */

View File

@ -139,11 +139,11 @@ ares_parse_srv_reply (const unsigned char *abuf, int alen,
srv_last = srv_curr; srv_last = srv_curr;
vptr = aptr; vptr = aptr;
srv_curr->priority = (unsigned short)DNS__16BIT(vptr); srv_curr->priority = DNS__16BIT(vptr);
vptr += sizeof(unsigned short); vptr += sizeof(unsigned short);
srv_curr->weight = (unsigned short)DNS__16BIT(vptr); srv_curr->weight = DNS__16BIT(vptr);
vptr += sizeof(unsigned short); vptr += sizeof(unsigned short);
srv_curr->port = (unsigned short)DNS__16BIT(vptr); srv_curr->port = DNS__16BIT(vptr);
vptr += sizeof(unsigned short); vptr += sizeof(unsigned short);
status = ares_expand_name (vptr, abuf, alen, &srv_curr->host, &len); status = ares_expand_name (vptr, abuf, alen, &srv_curr->host, &len);

View File

@ -77,7 +77,7 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
} }
/* Compute the query ID. Start with no timeout. */ /* Compute the query ID. Start with no timeout. */
query->qid = (unsigned short)DNS_HEADER_QID(qbuf); query->qid = DNS_HEADER_QID(qbuf);
query->timeout.tv_sec = 0; query->timeout.tv_sec = 0;
query->timeout.tv_usec = 0; query->timeout.tv_usec = 0;