Changeset 1239 for pjproject/trunk/pjlib-util/src/pjlib-util/dns.c
- Timestamp:
- May 1, 2007 12:25:01 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib-util/src/pjlib-util/dns.c
r1031 r1239 67 67 68 68 /* Initialize header */ 69 hdr = packet;69 hdr = (pj_dns_hdr*) packet; 70 70 pj_bzero(hdr, sizeof(struct pj_dns_hdr)); 71 71 hdr->id = pj_htons(id); … … 111 111 * it may contain pointers when name compression is applied) 112 112 */ 113 static pj_status_t get_name_len(int rec_counter, const char*pkt,114 const char *start, const char *max,113 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, 115 115 int *parsed_len, int *name_len) 116 116 { 117 const char*p;117 const pj_uint8_t *p; 118 118 pj_status_t status; 119 119 … … 181 181 * it may contain pointers when compression is applied). 182 182 */ 183 static pj_status_t get_name(int rec_counter, const char*pkt,184 const char *start, const char*max,183 static pj_status_t get_name(int rec_counter, const pj_uint8_t *pkt, 184 const pj_uint8_t *start, const pj_uint8_t *max, 185 185 pj_str_t *name) 186 186 { 187 const char*p;187 const pj_uint8_t *p; 188 188 pj_status_t status; 189 189 … … 242 242 /* Skip query records. */ 243 243 static pj_status_t parse_query(pj_dns_parsed_query *q, pj_pool_t *pool, 244 const char *pkt, const char *start,245 const char*max, int *parsed_len)246 { 247 const char*p = start;244 const pj_uint8_t *pkt, const pj_uint8_t *start, 245 const pj_uint8_t *max, int *parsed_len) 246 { 247 const pj_uint8_t *p = start; 248 248 int name_len, name_part_len; 249 249 pj_status_t status; … … 255 255 256 256 /* Allocate memory for the name */ 257 q->name.ptr = pj_pool_alloc(pool, name_len+4);257 q->name.ptr = (char*) pj_pool_alloc(pool, name_len+4); 258 258 q->name.slen = 0; 259 259 … … 283 283 /* Parse RR records */ 284 284 static pj_status_t parse_rr(pj_dns_parsed_rr *rr, pj_pool_t *pool, 285 const char*pkt,286 const char *start, const char *max,285 const pj_uint8_t *pkt, 286 const pj_uint8_t *start, const pj_uint8_t *max, 287 287 int *parsed_len) 288 288 { 289 const char*p = start;289 const pj_uint8_t *p = start; 290 290 int name_len, name_part_len; 291 291 pj_status_t status; … … 297 297 298 298 /* Allocate memory for the name */ 299 rr->name.ptr = pj_pool_alloc(pool, name_len+4);299 rr->name.ptr = (char*) pj_pool_alloc(pool, name_len+4); 300 300 rr->name.slen = 0; 301 301 … … 355 355 356 356 /* Allocate memory for the name */ 357 rr->rdata.cname.name.ptr = pj_pool_alloc(pool, name_len);357 rr->rdata.cname.name.ptr = (char*) pj_pool_alloc(pool, name_len); 358 358 rr->rdata.cname.name.slen = 0; 359 359 … … 388 388 389 389 /* Allocate memory for the name */ 390 rr->rdata.srv.target.ptr = pj_pool_alloc(pool, name_len);390 rr->rdata.srv.target.ptr = (char*) pj_pool_alloc(pool, name_len); 391 391 rr->rdata.srv.target.slen = 0; 392 392 … … 419 419 { 420 420 pj_dns_parsed_packet *res; 421 c har*start, *end;421 const pj_uint8_t *start, *end; 422 422 pj_status_t status; 423 423 unsigned i; … … 431 431 432 432 /* Create the structure */ 433 res = pj_pool_zalloc(pool, sizeof(pj_dns_parsed_packet));433 res = PJ_POOL_ZALLOC_T(pool, pj_dns_parsed_packet); 434 434 435 435 /* Copy the DNS header, and convert endianness to host byte order */ … … 443 443 444 444 /* Mark start and end of payload */ 445 start = ((c har*)packet) + sizeof(pj_dns_hdr);446 end = ((c har*)packet) + size;445 start = ((const pj_uint8_t*)packet) + sizeof(pj_dns_hdr); 446 end = ((const pj_uint8_t*)packet) + size; 447 447 448 448 /* Parse query records (if any). 449 449 */ 450 450 if (res->hdr.qdcount) { 451 res->q = pj_pool_zalloc(pool, res->hdr.qdcount * 451 res->q = (pj_dns_parsed_query*) 452 pj_pool_zalloc(pool, res->hdr.qdcount * 452 453 sizeof(pj_dns_parsed_query)); 453 454 for (i=0; i<res->hdr.qdcount; ++i) { 454 455 int parsed_len = 0; 455 456 456 status = parse_query(&res->q[i], pool, packet, start, end,457 457 status = parse_query(&res->q[i], pool, (const pj_uint8_t*)packet, 458 start, end, &parsed_len); 458 459 if (status != PJ_SUCCESS) 459 460 return status; … … 465 466 /* Parse answer, if any */ 466 467 if (res->hdr.anscount) { 467 res->ans = pj_pool_zalloc(pool, res->hdr.anscount * 468 res->ans = (pj_dns_parsed_rr*) 469 pj_pool_zalloc(pool, res->hdr.anscount * 468 470 sizeof(pj_dns_parsed_rr)); 469 471 … … 471 473 int parsed_len; 472 474 473 status = parse_rr(&res->ans[i], pool, packet, start, end,474 475 status = parse_rr(&res->ans[i], pool, (const pj_uint8_t*)packet, 476 start, end, &parsed_len); 475 477 if (status != PJ_SUCCESS) 476 478 return status; … … 482 484 /* Parse authoritative NS records, if any */ 483 485 if (res->hdr.nscount) { 484 res->ns = pj_pool_zalloc(pool, res->hdr.nscount * 486 res->ns = (pj_dns_parsed_rr*) 487 pj_pool_zalloc(pool, res->hdr.nscount * 485 488 sizeof(pj_dns_parsed_rr)); 486 489 … … 488 491 int parsed_len; 489 492 490 status = parse_rr(&res->ns[i], pool, packet, start, end,491 493 status = parse_rr(&res->ns[i], pool, (const pj_uint8_t*)packet, 494 start, end, &parsed_len); 492 495 if (status != PJ_SUCCESS) 493 496 return status; … … 499 502 /* Parse additional RR answer, if any */ 500 503 if (res->hdr.arcount) { 501 res->arr = pj_pool_zalloc(pool, res->hdr.arcount * 504 res->arr = (pj_dns_parsed_rr*) 505 pj_pool_zalloc(pool, res->hdr.arcount * 502 506 sizeof(pj_dns_parsed_rr)); 503 507 … … 505 509 int parsed_len; 506 510 507 status = parse_rr(&res->arr[i], pool, packet, start, end,508 511 status = parse_rr(&res->arr[i], pool, (const pj_uint8_t*)packet, 512 start, end, &parsed_len); 509 513 if (status != PJ_SUCCESS) 510 514 return status; … … 614 618 615 619 /* Create packet and copy header */ 616 *p_dst = dst = pj_pool_zalloc(pool, sizeof(pj_dns_parsed_packet));620 *p_dst = dst = PJ_POOL_ZALLOC_T(pool, pj_dns_parsed_packet); 617 621 pj_memcpy(&dst->hdr, &p->hdr, sizeof(p->hdr)); 618 622 … … 629 633 /* Copy query section */ 630 634 if (p->hdr.qdcount && (options & PJ_DNS_NO_QD)==0) { 631 dst->q = pj_pool_alloc(pool, p->hdr.qdcount * 635 dst->q = (pj_dns_parsed_query*) 636 pj_pool_alloc(pool, p->hdr.qdcount * 632 637 sizeof(pj_dns_parsed_query)); 633 638 for (i=0; i<p->hdr.qdcount; ++i) { … … 640 645 /* Copy answer section */ 641 646 if (p->hdr.anscount && (options & PJ_DNS_NO_ANS)==0) { 642 dst->ans = pj_pool_alloc(pool, p->hdr.anscount * 647 dst->ans = (pj_dns_parsed_rr*) 648 pj_pool_alloc(pool, p->hdr.anscount * 643 649 sizeof(pj_dns_parsed_rr)); 644 650 for (i=0; i<p->hdr.anscount; ++i) { … … 651 657 /* Copy NS section */ 652 658 if (p->hdr.nscount && (options & PJ_DNS_NO_NS)==0) { 653 dst->ns = pj_pool_alloc(pool, p->hdr.nscount * 659 dst->ns = (pj_dns_parsed_rr*) 660 pj_pool_alloc(pool, p->hdr.nscount * 654 661 sizeof(pj_dns_parsed_rr)); 655 662 for (i=0; i<p->hdr.nscount; ++i) { … … 662 669 /* Copy additional info section */ 663 670 if (p->hdr.arcount && (options & PJ_DNS_NO_AR)==0) { 664 dst->arr = pj_pool_alloc(pool, p->hdr.arcount * 671 dst->arr = (pj_dns_parsed_rr*) 672 pj_pool_alloc(pool, p->hdr.arcount * 665 673 sizeof(pj_dns_parsed_rr)); 666 674 for (i=0; i<p->hdr.arcount; ++i) {
Note: See TracChangeset
for help on using the changeset viewer.