Changeset 1355
- Timestamp:
- Jun 11, 2007 4:43:29 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/dns.c
r1239 r1355 42 42 43 43 44 static void write16(pj_uint8_t *p, pj_uint16_t val) 45 { 46 p[0] = (pj_uint8_t)(val >> 8); 47 p[1] = (pj_uint8_t)(val & 0xFF); 48 } 49 50 44 51 /** 45 52 * Initialize a DNS query transaction. … … 51 58 const pj_str_t *name) 52 59 { 53 pj_dns_hdr *hdr; 54 char *query, *p; 60 pj_uint8_t *query, *p = packet; 55 61 const char *startlabel, *endlabel, *endname; 56 pj_uint16_t tmp;57 62 unsigned d; 58 63 … … 67 72 68 73 /* Initialize header */ 69 hdr = (pj_dns_hdr*) packet;70 pj_bzero( hdr, sizeof(struct pj_dns_hdr));71 hdr->id = pj_htons(id);72 hdr->flags = pj_htons(PJ_DNS_SET_RD(1));73 hdr->qdcount = pj_htons(1);74 pj_assert(sizeof(pj_dns_hdr)==12); 75 pj_bzero(p, sizeof(struct pj_dns_hdr)); 76 write16(p+0, id); 77 write16(p+2, (pj_uint16_t)PJ_DNS_SET_RD(1)); 78 write16(p+4, (pj_uint16_t)1); 74 79 75 80 /* Initialize query */ 76 query = p = ( char*)(hdr+1);81 query = p = ((pj_uint8_t*)packet)+sizeof(pj_dns_hdr); 77 82 78 83 /* Tokenize name */ … … 82 87 while (endlabel != endname && *endlabel != '.') 83 88 ++endlabel; 84 *p++ = ( char)(endlabel - startlabel);89 *p++ = (pj_uint8_t)(endlabel - startlabel); 85 90 pj_memcpy(p, startlabel, endlabel-startlabel); 86 91 p += (endlabel-startlabel); … … 92 97 93 98 /* Set type */ 94 tmp = pj_htons((pj_uint16_t)(qtype)); 95 pj_memcpy(p, &tmp, 2); 99 write16(p, (pj_uint16_t)qtype); 96 100 p += 2; 97 101 98 102 /* Set class (IN=1) */ 99 tmp = pj_htons(1); 100 pj_memcpy(p, &tmp, 2); 103 write16(p, 1); 101 104 p += 2; 102 105 103 106 /* Done, calculate length */ 104 *size = p - ( char*)packet;107 *size = p - (pj_uint8_t*)packet; 105 108 106 109 return 0; … … 112 115 */ 113 116 static pj_status_t get_name_len(int rec_counter, const pj_uint8_t *pkt, 114 const pj_uint8_t *start, const pj_uint8_t *max, 117 const pj_uint8_t *start, const pj_uint8_t *max, 115 118 int *parsed_len, int *name_len) 116 119 { … … 240 243 241 244 242 /* Skipquery records. */245 /* Parse query records. */ 243 246 static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool, 244 247 const pj_uint8_t *pkt, const pj_uint8_t *start, … … 327 330 /* Get TTL */ 328 331 pj_memcpy(&rr->ttl, p, 4); 329 rr->ttl = pj_ htonl(rr->ttl);332 rr->ttl = pj_ntohl(rr->ttl); 330 333 p += 4; 331 334 332 335 /* Get rdlength */ 333 336 pj_memcpy(&rr->rdlength, p, 2); 334 rr->rdlength = pj_ htons(rr->rdlength);337 rr->rdlength = pj_ntohs(rr->rdlength); 335 338 p += 2; 336 339
Note: See TracChangeset
for help on using the changeset viewer.