Changeset dc95342 in mainline
- Timestamp:
- 2013-04-22T06:45:49Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 31e9fe0
- Parents:
- 7262f89
- Location:
- uspace/srv/net/dnsres
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dnsres/dns_msg.c
r7262f89 rdc95342 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 489 489 dns_question_t *q = list_get_instance(link, dns_question_t, msg); 490 490 rc = dns_question_encode(q, data + di, size - di, &q_size); 491 assert(rc == EOK); 491 if (rc != EOK) { 492 assert(rc == ENOMEM || rc == EINVAL); 493 free(data); 494 return rc; 495 } 492 496 493 497 di += q_size; … … 578 582 return EOK; 579 583 error: 580 /* XXX Destroy message */584 dns_message_destroy(msg); 581 585 return rc; 586 } 587 588 static void dns_question_destroy(dns_question_t *question) 589 { 590 free(question->qname); 591 free(question); 592 } 593 594 static void dns_rr_destroy(dns_rr_t *rr) 595 { 596 free(rr->name); 597 free(rr->rdata); 598 free(rr); 599 } 600 601 void dns_message_destroy(dns_message_t *msg) 602 { 603 link_t *link; 604 dns_question_t *question; 605 dns_rr_t *rr; 606 607 while (!list_empty(&msg->question)) { 608 link = list_first(&msg->question); 609 question = list_get_instance(link, dns_question_t, msg); 610 list_remove(&question->msg); 611 dns_question_destroy(question); 612 } 613 614 while (!list_empty(&msg->answer)) { 615 link = list_first(&msg->answer); 616 rr = list_get_instance(link, dns_rr_t, msg); 617 list_remove(&rr->msg); 618 dns_rr_destroy(rr); 619 } 620 621 while (!list_empty(&msg->authority)) { 622 link = list_first(&msg->authority); 623 rr = list_get_instance(link, dns_rr_t, msg); 624 list_remove(&rr->msg); 625 dns_rr_destroy(rr); 626 } 627 628 while (!list_empty(&msg->additional)) { 629 link = list_first(&msg->additional); 630 rr = list_get_instance(link, dns_rr_t, msg); 631 list_remove(&rr->msg); 632 dns_rr_destroy(rr); 633 } 634 635 free(msg); 582 636 } 583 637 -
uspace/srv/net/dnsres/dns_msg.h
r7262f89 rdc95342 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 extern int dns_message_encode(dns_message_t *, void **, size_t *); 46 46 extern int dns_message_decode(void *, size_t, dns_message_t **); 47 extern void dns_message_destroy(dns_message_t *); 47 48 extern uint32_t dns_uint32_t_decode(uint8_t *, size_t); 48 49 -
uspace/srv/net/dnsres/dnsres.c
r7262f89 rdc95342 60 60 int main(int argc, char *argv[]) 61 61 { 62 dns_host_info_t hinfo;62 dns_host_info_t *hinfo; 63 63 char *astr; 64 64 int rc; … … 69 69 70 70 if (rc == EOK) { 71 rc = addr_format(&hinfo .addr, &astr);71 rc = addr_format(&hinfo->addr, &astr); 72 72 if (rc != EOK) { 73 dns_hostinfo_destroy(hinfo); 73 74 printf("Out of memory\n"); 74 75 return ENOMEM; 75 76 } 76 77 77 printf("hostname: %s\n", hinfo .name);78 printf("hostname: %s\n", hinfo->name); 78 79 printf("IPv4 address: %s\n", astr); 79 80 free(astr); 81 dns_hostinfo_destroy(hinfo); 80 82 } 81 83 -
uspace/srv/net/dnsres/query.c
r7262f89 rdc95342 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 36 36 #include <errno.h> 37 37 #include <mem.h> 38 #include <stdlib.h> 38 39 #include <str.h> 39 40 … … 47 48 48 49 #include <stdio.h> 49 int dns_name2host(const char *name, dns_host_info_t * info)50 int dns_name2host(const char *name, dns_host_info_t **rinfo) 50 51 { 51 52 dns_message_t msg; 52 53 dns_message_t *amsg; 53 54 dns_question_t question; 55 dns_host_info_t *info; 54 56 int rc; 55 57 … … 81 83 rr->name, rr->rtype, rr->rclass, rr->rdata_size); 82 84 83 if (rr->rtype == DTYPE_A && rr->rclass == DC_IN) { 84 if (rr->rdata_size != sizeof(uint32_t)) { 85 printf("rdata_size = %u - fail\n", rr->rdata_size); 86 return EIO; 85 if (rr->rtype == DTYPE_A && rr->rclass == DC_IN && 86 rr->rdata_size == sizeof(uint32_t)) { 87 88 info = calloc(1, sizeof(dns_host_info_t)); 89 if (info == NULL) { 90 dns_message_destroy(amsg); 91 return ENOMEM; 87 92 } 88 93 … … 90 95 info->addr.ipv4 = dns_uint32_t_decode(rr->rdata, rr->rdata_size); 91 96 printf("info->addr = %x\n", info->addr.ipv4); 97 98 dns_message_destroy(amsg); 99 *rinfo = info; 92 100 return EOK; 93 101 } 94 102 } 95 103 104 dns_message_destroy(amsg); 96 105 printf("no A/IN found, fail\n"); 97 106 … … 99 108 } 100 109 110 void dns_hostinfo_destroy(dns_host_info_t *info) 111 { 112 free(info->name); 113 free(info); 114 } 115 101 116 /** @} 102 117 */ -
uspace/srv/net/dnsres/query.h
r7262f89 rdc95342 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include "dns_type.h" 40 40 41 extern int dns_name2host(const char *, dns_host_info_t *); 41 extern int dns_name2host(const char *, dns_host_info_t **); 42 extern void dns_hostinfo_destroy(dns_host_info_t *); 42 43 43 44 #endif -
uspace/srv/net/dnsres/transport.c
r7262f89 rdc95342 1 1 /* 2 * Copyright (c) 201 2Jiri Svoboda2 * Copyright (c) 2013 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 120 120 121 121 rc = dns_message_decode(recv_buf, recv_size, &resp); 122 if (rc != EOK) 123 return EIO; 122 if (rc != EOK) { 123 rc = EIO; 124 goto error; 125 } 124 126 125 127 *rresp = resp;
Note:
See TracChangeset
for help on using the changeset viewer.