<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>ldns documentation</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <div class="logo"> <img src="LogoInGradientBar2-y100.png"/> </div> <!-- Generated by Doxygen 1.7.4 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>Globals</span></a></li> </ul> </div> <div class="header"> <div class="headertitle"> <div class="title">wire2host.c</div> </div> </div> <div class="contents"> <a href="wire2host_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * wire2host.c</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * conversion routines from the wire to the host</span> <a name="l00005"></a>00005 <span class="comment"> * format.</span> <a name="l00006"></a>00006 <span class="comment"> * This will usually just a re-ordering of the</span> <a name="l00007"></a>00007 <span class="comment"> * data (as we store it in network format)</span> <a name="l00008"></a>00008 <span class="comment"> *</span> <a name="l00009"></a>00009 <span class="comment"> * a Net::DNS like library for C</span> <a name="l00010"></a>00010 <span class="comment"> *</span> <a name="l00011"></a>00011 <span class="comment"> * (c) NLnet Labs, 2004-2006</span> <a name="l00012"></a>00012 <span class="comment"> *</span> <a name="l00013"></a>00013 <span class="comment"> * See the file LICENSE for the license</span> <a name="l00014"></a>00014 <span class="comment"> */</span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <a name="l00017"></a>00017 <span class="preprocessor">#include <<a class="code" href="ldns_2config_8h.html">ldns/config.h</a>></span> <a name="l00018"></a>00018 <a name="l00019"></a>00019 <span class="preprocessor">#include <<a class="code" href="ldns_8h.html" title="Including this file will include all ldns files, and define some lookup tables.">ldns/ldns.h</a>></span> <a name="l00020"></a>00020 <span class="comment">/*#include <ldns/wire2host.h>*/</span> <a name="l00021"></a>00021 <a name="l00022"></a>00022 <span class="preprocessor">#include <strings.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#include <limits.h></span> <a name="l00024"></a>00024 <a name="l00025"></a>00025 <a name="l00026"></a>00026 <a name="l00027"></a>00027 <span class="comment">/*</span> <a name="l00028"></a>00028 <span class="comment"> * Set of macro's to deal with the dns message header as specified</span> <a name="l00029"></a>00029 <span class="comment"> * in RFC1035 in portable way.</span> <a name="l00030"></a>00030 <span class="comment"> *</span> <a name="l00031"></a>00031 <span class="comment"> */</span> <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="comment">/*</span> <a name="l00034"></a>00034 <span class="comment"> *</span> <a name="l00035"></a>00035 <span class="comment"> * 1 1 1 1 1 1</span> <a name="l00036"></a>00036 <span class="comment"> * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5</span> <a name="l00037"></a>00037 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00038"></a>00038 <span class="comment"> * | ID |</span> <a name="l00039"></a>00039 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00040"></a>00040 <span class="comment"> * |QR| Opcode |AA|TC|RD|RA| Z|AD|CD| RCODE |</span> <a name="l00041"></a>00041 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00042"></a>00042 <span class="comment"> * | QDCOUNT |</span> <a name="l00043"></a>00043 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00044"></a>00044 <span class="comment"> * | ANCOUNT |</span> <a name="l00045"></a>00045 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00046"></a>00046 <span class="comment"> * | NSCOUNT |</span> <a name="l00047"></a>00047 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00048"></a>00048 <span class="comment"> * | ARCOUNT |</span> <a name="l00049"></a>00049 <span class="comment"> * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+</span> <a name="l00050"></a>00050 <span class="comment"> *</span> <a name="l00051"></a>00051 <span class="comment"> */</span> <a name="l00052"></a>00052 <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="comment">/* allocates memory to *dname! */</span> <a name="l00055"></a>00055 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00056"></a><a class="code" href="wire2host_8h.html#a3bf2a93cc61e3942288ebb8b803e4ce9">00056</a> <a class="code" href="wire2host_8c.html#a3bf2a93cc61e3942288ebb8b803e4ce9" title="converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.">ldns_wire2dname</a>(<a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> **dname, <span class="keyword">const</span> uint8_t *wire, <span class="keywordtype">size_t</span> max, <span class="keywordtype">size_t</span> *pos) <a name="l00057"></a>00057 { <a name="l00058"></a>00058 uint8_t label_size; <a name="l00059"></a>00059 uint16_t pointer_target; <a name="l00060"></a>00060 uint8_t pointer_target_buf[2]; <a name="l00061"></a>00061 <span class="keywordtype">size_t</span> dname_pos = 0; <a name="l00062"></a>00062 <span class="keywordtype">size_t</span> uncompressed_length = 0; <a name="l00063"></a>00063 <span class="keywordtype">size_t</span> compression_pos = 0; <a name="l00064"></a>00064 uint8_t tmp_dname[<a class="code" href="rr_8h.html#ad52564ca775d206b60f48b254de552b2" title="Maximum length of a complete dname.">LDNS_MAX_DOMAINLEN</a>]; <a name="l00065"></a>00065 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pointer_count = 0; <a name="l00066"></a>00066 <a name="l00067"></a>00067 <span class="keywordflow">if</span> (*pos >= max) { <a name="l00068"></a>00068 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00069"></a>00069 } <a name="l00070"></a>00070 <a name="l00071"></a>00071 label_size = wire[*pos]; <a name="l00072"></a>00072 <span class="keywordflow">while</span> (label_size > 0) { <a name="l00073"></a>00073 <span class="comment">/* compression */</span> <a name="l00074"></a>00074 <span class="keywordflow">while</span> (label_size >= 192) { <a name="l00075"></a>00075 <span class="keywordflow">if</span> (compression_pos == 0) { <a name="l00076"></a>00076 compression_pos = *pos + 2; <a name="l00077"></a>00077 } <a name="l00078"></a>00078 <a name="l00079"></a>00079 pointer_count++; <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="comment">/* remove first two bits */</span> <a name="l00082"></a>00082 <span class="keywordflow">if</span> (*pos + 2 > max) { <a name="l00083"></a>00083 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00084"></a>00084 } <a name="l00085"></a>00085 pointer_target_buf[0] = wire[*pos] & 63; <a name="l00086"></a>00086 pointer_target_buf[1] = wire[*pos + 1]; <a name="l00087"></a>00087 pointer_target = ldns_read_uint16(pointer_target_buf); <a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="keywordflow">if</span> (pointer_target == 0) { <a name="l00090"></a>00090 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaa63a49a6ff041ba0f1d8715c53010b08">LDNS_STATUS_INVALID_POINTER</a>; <a name="l00091"></a>00091 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pointer_target >= max) { <a name="l00092"></a>00092 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaa63a49a6ff041ba0f1d8715c53010b08">LDNS_STATUS_INVALID_POINTER</a>; <a name="l00093"></a>00093 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pointer_count > <a class="code" href="rr_8h.html#aa8b60545035350bf97dd637dc98ede6a" title="Maximum number of pointers in 1 dname.">LDNS_MAX_POINTERS</a>) { <a name="l00094"></a>00094 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaa63a49a6ff041ba0f1d8715c53010b08">LDNS_STATUS_INVALID_POINTER</a>; <a name="l00095"></a>00095 } <a name="l00096"></a>00096 *pos = pointer_target; <a name="l00097"></a>00097 label_size = wire[*pos]; <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <span class="keywordflow">if</span>(label_size == 0) <a name="l00100"></a>00100 <span class="keywordflow">break</span>; <span class="comment">/* break from pointer to 0 byte */</span> <a name="l00101"></a>00101 <span class="keywordflow">if</span> (label_size > <a class="code" href="rr_8h.html#a38645125207e50b2feb48e5a73d8190d" title="Maximum length of a dname label.">LDNS_MAX_LABELLEN</a>) { <a name="l00102"></a>00102 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa6918ba0f18db820fc7736c11b40099e9">LDNS_STATUS_LABEL_OVERFLOW</a>; <a name="l00103"></a>00103 } <a name="l00104"></a>00104 <span class="keywordflow">if</span> (*pos + 1 + label_size > max) { <a name="l00105"></a>00105 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa6918ba0f18db820fc7736c11b40099e9">LDNS_STATUS_LABEL_OVERFLOW</a>; <a name="l00106"></a>00106 } <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">/* check space for labelcount itself */</span> <a name="l00109"></a>00109 <span class="keywordflow">if</span> (dname_pos + 1 > <a class="code" href="rr_8h.html#ad52564ca775d206b60f48b254de552b2" title="Maximum length of a complete dname.">LDNS_MAX_DOMAINLEN</a>) { <a name="l00110"></a>00110 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad77a477a6892604c0365ce181e72fb87">LDNS_STATUS_DOMAINNAME_OVERFLOW</a>; <a name="l00111"></a>00111 } <a name="l00112"></a>00112 tmp_dname[dname_pos] = label_size; <a name="l00113"></a>00113 <span class="keywordflow">if</span> (label_size > 0) { <a name="l00114"></a>00114 dname_pos++; <a name="l00115"></a>00115 } <a name="l00116"></a>00116 *pos = *pos + 1; <a name="l00117"></a>00117 <span class="keywordflow">if</span> (dname_pos + label_size > <a class="code" href="rr_8h.html#ad52564ca775d206b60f48b254de552b2" title="Maximum length of a complete dname.">LDNS_MAX_DOMAINLEN</a>) { <a name="l00118"></a>00118 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad77a477a6892604c0365ce181e72fb87">LDNS_STATUS_DOMAINNAME_OVERFLOW</a>; <a name="l00119"></a>00119 } <a name="l00120"></a>00120 memcpy(&tmp_dname[dname_pos], &wire[*pos], label_size); <a name="l00121"></a>00121 uncompressed_length += label_size + 1; <a name="l00122"></a>00122 dname_pos += label_size; <a name="l00123"></a>00123 *pos = *pos + label_size; <a name="l00124"></a>00124 <a name="l00125"></a>00125 <span class="keywordflow">if</span> (*pos < max) { <a name="l00126"></a>00126 label_size = wire[*pos]; <a name="l00127"></a>00127 } <a name="l00128"></a>00128 } <a name="l00129"></a>00129 <a name="l00130"></a>00130 <span class="keywordflow">if</span> (compression_pos > 0) { <a name="l00131"></a>00131 *pos = compression_pos; <a name="l00132"></a>00132 } <span class="keywordflow">else</span> { <a name="l00133"></a>00133 *pos = *pos + 1; <a name="l00134"></a>00134 } <a name="l00135"></a>00135 <a name="l00136"></a>00136 <span class="keywordflow">if</span> (dname_pos >= <a class="code" href="rr_8h.html#ad52564ca775d206b60f48b254de552b2" title="Maximum length of a complete dname.">LDNS_MAX_DOMAINLEN</a>) { <a name="l00137"></a>00137 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad77a477a6892604c0365ce181e72fb87">LDNS_STATUS_DOMAINNAME_OVERFLOW</a>; <a name="l00138"></a>00138 } <a name="l00139"></a>00139 <a name="l00140"></a>00140 tmp_dname[dname_pos] = 0; <a name="l00141"></a>00141 dname_pos++; <a name="l00142"></a>00142 <a name="l00143"></a>00143 *dname = <a class="code" href="rdata_8c.html#afeaa67dccf9c97ac9209776936279319" title="allocates a new rdf structure and fills it.">ldns_rdf_new_frm_data</a>(<a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a72cb73467bcbfbb41168e2a2b4a8283a" title="domain name">LDNS_RDF_TYPE_DNAME</a>, <a name="l00144"></a>00144 (uint16_t) dname_pos, tmp_dname); <a name="l00145"></a>00145 <span class="keywordflow">if</span> (!*dname) { <a name="l00146"></a>00146 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa81e80e66a14551db514726fa49290498">LDNS_STATUS_MEM_ERR</a>; <a name="l00147"></a>00147 } <a name="l00148"></a>00148 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00149"></a>00149 } <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="comment">/* maybe make this a goto error so data can be freed or something/ */</span> <a name="l00152"></a><a class="code" href="wire2host_8c.html#a542d428bf1d4a080c332e6291e2cadf0">00152</a> <span class="preprocessor">#define LDNS_STATUS_CHECK_RETURN(st) {if (st != LDNS_STATUS_OK) { return st; }}</span> <a name="l00153"></a><a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">00153</a> <span class="preprocessor"></span><span class="preprocessor">#define LDNS_STATUS_CHECK_GOTO(st, label) {if (st != LDNS_STATUS_OK) { </span><span class="comment">/*printf("STG %s:%d: status code %d\n", __FILE__, __LINE__, st);*/</span> goto label; }} <a name="l00154"></a>00154 <a name="l00155"></a>00155 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00156"></a><a class="code" href="wire2host_8h.html#a75fe7ca2ee5f51b9c8ab14a37a491d43">00156</a> <a class="code" href="wire2host_8c.html#a75fe7ca2ee5f51b9c8ab14a37a491d43" title="converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the...">ldns_wire2rdf</a>(<a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr, <span class="keyword">const</span> uint8_t *wire, <span class="keywordtype">size_t</span> max, <span class="keywordtype">size_t</span> *pos) <a name="l00157"></a>00157 { <a name="l00158"></a>00158 <span class="keywordtype">size_t</span> end; <a name="l00159"></a>00159 <span class="keywordtype">size_t</span> cur_rdf_length; <a name="l00160"></a>00160 uint8_t rdf_index; <a name="l00161"></a>00161 uint8_t *data; <a name="l00162"></a>00162 uint16_t rd_length; <a name="l00163"></a>00163 <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *cur_rdf = NULL; <a name="l00164"></a>00164 <a class="code" href="rdata_8h.html#af4980b902b413c784ab278a8d41e132a">ldns_rdf_type</a> cur_rdf_type; <a name="l00165"></a>00165 <span class="keyword">const</span> <a class="code" href="structldns__struct__rr__descriptor.html" title="Contains all information about resource record types.">ldns_rr_descriptor</a> *descriptor = <a class="code" href="rr_8c.html#a25e28bda55a3d8578f6377caafc9cfb0" title="returns the resource record descriptor for the given rr type.">ldns_rr_descript</a>(<a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(rr)); <a name="l00166"></a>00166 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status; <a name="l00167"></a>00167 <a name="l00168"></a>00168 <span class="keywordflow">if</span> (*pos + 2 > max) { <a name="l00169"></a>00169 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00170"></a>00170 } <a name="l00171"></a>00171 <a name="l00172"></a>00172 rd_length = ldns_read_uint16(&wire[*pos]); <a name="l00173"></a>00173 *pos = *pos + 2; <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="keywordflow">if</span> (*pos + rd_length > max) { <a name="l00176"></a>00176 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00177"></a>00177 } <a name="l00178"></a>00178 <a name="l00179"></a>00179 end = *pos + (size_t) rd_length; <a name="l00180"></a>00180 <a name="l00181"></a>00181 <span class="keywordflow">for</span> (rdf_index = 0; <a name="l00182"></a>00182 rdf_index < <a class="code" href="rr_8c.html#a903dbeb5f9d525abf9d9503102dc3cc8" title="returns the maximum number of rdata fields of the rr type this descriptor describes.">ldns_rr_descriptor_maximum</a>(descriptor); rdf_index++) { <a name="l00183"></a>00183 <span class="keywordflow">if</span> (*pos >= end) { <a name="l00184"></a>00184 <span class="keywordflow">break</span>; <a name="l00185"></a>00185 } <a name="l00186"></a>00186 cur_rdf_length = 0; <a name="l00187"></a>00187 <a name="l00188"></a>00188 cur_rdf_type = <a class="code" href="rr_8c.html#a78025ddab06deb49fa7c7f453ed5f459" title="returns the rdf type for the given rdata field number of the rr type for the given descriptor...">ldns_rr_descriptor_field_type</a>(descriptor, rdf_index); <a name="l00189"></a>00189 <span class="comment">/* handle special cases immediately, set length</span> <a name="l00190"></a>00190 <span class="comment"> for fixed length rdata and do them below */</span> <a name="l00191"></a>00191 <span class="keywordflow">switch</span> (cur_rdf_type) { <a name="l00192"></a>00192 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a72cb73467bcbfbb41168e2a2b4a8283a" title="domain name">LDNS_RDF_TYPE_DNAME</a>: <a name="l00193"></a>00193 status = <a class="code" href="wire2host_8c.html#a3bf2a93cc61e3942288ebb8b803e4ce9" title="converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.">ldns_wire2dname</a>(&cur_rdf, wire, max, pos); <a name="l00194"></a>00194 <a class="code" href="wire2host_8c.html#a542d428bf1d4a080c332e6291e2cadf0">LDNS_STATUS_CHECK_RETURN</a>(status); <a name="l00195"></a>00195 <span class="keywordflow">break</span>; <a name="l00196"></a>00196 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9abf3ea50fba0758689921debefc9faa21" title="a class">LDNS_RDF_TYPE_CLASS</a>: <a name="l00197"></a>00197 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9ae267872ec0957925bbf1d6720b93597a" title="a key algorithm">LDNS_RDF_TYPE_ALG</a>: <a name="l00198"></a>00198 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9ac18c3e598d6a7a85b8eb1d1a047ac557" title="8 bits">LDNS_RDF_TYPE_INT8</a>: <a name="l00199"></a>00199 cur_rdf_length = <a class="code" href="rdata_8h.html#a74089fa5ee9b1520a2e3e13eec02d7cb">LDNS_RDF_SIZE_BYTE</a>; <a name="l00200"></a>00200 <span class="keywordflow">break</span>; <a name="l00201"></a>00201 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9af943c7b93856ac0cfcda816c7c952c9f" title="a RR type">LDNS_RDF_TYPE_TYPE</a>: <a name="l00202"></a>00202 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9adef66c8791f83ba190e5f5775791e4c6" title="16 bits">LDNS_RDF_TYPE_INT16</a>: <a name="l00203"></a>00203 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a2fea2b715b1d67d24ec2687379e3f506" title="certificate algorithm">LDNS_RDF_TYPE_CERT_ALG</a>: <a name="l00204"></a>00204 cur_rdf_length = <a class="code" href="rdata_8h.html#a36a3c3e1aabff6107f3f5d5f723a94c6">LDNS_RDF_SIZE_WORD</a>; <a name="l00205"></a>00205 <span class="keywordflow">break</span>; <a name="l00206"></a>00206 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a75048af9090d43c3105a41fbec16c96e" title="time (32 bits)">LDNS_RDF_TYPE_TIME</a>: <a name="l00207"></a>00207 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a077e8e14046bf02ac92053e784921e73" title="32 bits">LDNS_RDF_TYPE_INT32</a>: <a name="l00208"></a>00208 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a8ab64a730a4d6b7a717e6a3dbdc6123d" title="A record.">LDNS_RDF_TYPE_A</a>: <a name="l00209"></a>00209 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a45e328c984e7e1a01aea68ec3e377dbd" title="period">LDNS_RDF_TYPE_PERIOD</a>: <a name="l00210"></a>00210 cur_rdf_length = <a class="code" href="rdata_8h.html#aba5cb61124a20ecbe661d84deebb8dfe">LDNS_RDF_SIZE_DOUBLEWORD</a>; <a name="l00211"></a>00211 <span class="keywordflow">break</span>; <a name="l00212"></a>00212 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9af92739b2430f01ad89cec4a53bcc08b5" title="tsig time 48 bits">LDNS_RDF_TYPE_TSIGTIME</a>: <a name="l00213"></a>00213 cur_rdf_length = <a class="code" href="rdata_8h.html#a7854294e68859d13608b457a37a23b6e">LDNS_RDF_SIZE_6BYTES</a>; <a name="l00214"></a>00214 <span class="keywordflow">break</span>; <a name="l00215"></a>00215 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a5959b86d3aacff828167e6dca5a935fd" title="AAAA record.">LDNS_RDF_TYPE_AAAA</a>: <a name="l00216"></a>00216 cur_rdf_length = <a class="code" href="rdata_8h.html#a910c13d092c2927b0e224edcc62b85ce">LDNS_RDF_SIZE_16BYTES</a>; <a name="l00217"></a>00217 <span class="keywordflow">break</span>; <a name="l00218"></a>00218 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9ade27cf2658eb51902914c7fe6a6a3bb0" title="txt string">LDNS_RDF_TYPE_STR</a>: <a name="l00219"></a>00219 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a87d3781e435a1fd0a7cefce6d3cfe273" title="nsec3 hash salt">LDNS_RDF_TYPE_NSEC3_SALT</a>: <a name="l00220"></a>00220 <span class="comment">/* len is stored in first byte</span> <a name="l00221"></a>00221 <span class="comment"> * it should be in the rdf too, so just</span> <a name="l00222"></a>00222 <span class="comment"> * copy len+1 from this position</span> <a name="l00223"></a>00223 <span class="comment"> */</span> <a name="l00224"></a>00224 cur_rdf_length = ((size_t) wire[*pos]) + 1; <a name="l00225"></a>00225 <span class="keywordflow">break</span>; <a name="l00226"></a>00226 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9aa66f3cec1402d326c773715de32c748e" title="variable length any type rdata where the length is specified by the first 2 bytes">LDNS_RDF_TYPE_INT16_DATA</a>: <a name="l00227"></a>00227 cur_rdf_length = (size_t) ldns_read_uint16(&wire[*pos]) + 2; <a name="l00228"></a>00228 <span class="keywordflow">break</span>; <a name="l00229"></a>00229 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a20eeaadcda9fe241639d34b8decaff72" title="b32 string">LDNS_RDF_TYPE_B32_EXT</a>: <a name="l00230"></a>00230 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a245bc4ea82df46ceeeb97921e563a616" title="nsec3 base32 string (with length byte on wire">LDNS_RDF_TYPE_NSEC3_NEXT_OWNER</a>: <a name="l00231"></a>00231 <span class="comment">/* length is stored in first byte */</span> <a name="l00232"></a>00232 cur_rdf_length = ((size_t) wire[*pos]) + 1; <a name="l00233"></a>00233 <span class="keywordflow">break</span>; <a name="l00234"></a>00234 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a88057121614020f91062e7cb29b4324d" title="apl data">LDNS_RDF_TYPE_APL</a>: <a name="l00235"></a>00235 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a4bbe575feeed4d2e7045962b7262c180" title="b64 string">LDNS_RDF_TYPE_B64</a>: <a name="l00236"></a>00236 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9abb1b198b0e4c7dc8a5d659bb60a4d0b0" title="hex string">LDNS_RDF_TYPE_HEX</a>: <a name="l00237"></a>00237 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a8060ea4dff4d7af7148ef6ee2d5a0f1c" title="nsec type codes">LDNS_RDF_TYPE_NSEC</a>: <a name="l00238"></a>00238 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a64231b892a5ff592247660d795ee3e63" title="unknown types">LDNS_RDF_TYPE_UNKNOWN</a>: <a name="l00239"></a>00239 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a3f24ac5ab15e8fa733d8bfac683bf565" title="protocol and port bitmaps">LDNS_RDF_TYPE_SERVICE</a>: <a name="l00240"></a>00240 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9aa2c89d6e5d720a6fffae12a07dbbf4c3" title="location data">LDNS_RDF_TYPE_LOC</a>: <a name="l00241"></a>00241 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a70215c46d4acf9dec8e5f058540ca006" title="well known services">LDNS_RDF_TYPE_WKS</a>: <a name="l00242"></a>00242 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a1344c38bc2f566f6273925c549760c85" title="NSAP.">LDNS_RDF_TYPE_NSAP</a>: <a name="l00243"></a>00243 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9abb09899d5dd4c0bd05998d83e15abc39" title="ATMA.">LDNS_RDF_TYPE_ATMA</a>: <a name="l00244"></a>00244 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9ad558dc264349b8619fb907108c6b5a46" title="IPSECKEY.">LDNS_RDF_TYPE_IPSECKEY</a>: <a name="l00245"></a>00245 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a137406d5dd460601083526b7c89d2189">LDNS_RDF_TYPE_TSIG</a>: <a name="l00246"></a>00246 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9abd0e34ab5520bb9c6ec2ef6c23348edf" title="none">LDNS_RDF_TYPE_NONE</a>: <a name="l00247"></a>00247 <span class="comment">/*</span> <a name="l00248"></a>00248 <span class="comment"> * Read to end of rr rdata</span> <a name="l00249"></a>00249 <span class="comment"> */</span> <a name="l00250"></a>00250 cur_rdf_length = end - *pos; <a name="l00251"></a>00251 <span class="keywordflow">break</span>; <a name="l00252"></a>00252 } <a name="l00253"></a>00253 <a name="l00254"></a>00254 <span class="comment">/* fixed length rdata */</span> <a name="l00255"></a>00255 <span class="keywordflow">if</span> (cur_rdf_length > 0) { <a name="l00256"></a>00256 <span class="keywordflow">if</span> (cur_rdf_length + *pos > end) { <a name="l00257"></a>00257 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00258"></a>00258 } <a name="l00259"></a>00259 data = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, rd_length); <a name="l00260"></a>00260 <span class="keywordflow">if</span> (!data) { <a name="l00261"></a>00261 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa81e80e66a14551db514726fa49290498">LDNS_STATUS_MEM_ERR</a>; <a name="l00262"></a>00262 } <a name="l00263"></a>00263 memcpy(data, &wire[*pos], cur_rdf_length); <a name="l00264"></a>00264 <a name="l00265"></a>00265 cur_rdf = <a class="code" href="rdata_8c.html#a5074dfaf129822d72061d81b290bd332" title="allocates a new rdf structure and fills it.">ldns_rdf_new</a>(cur_rdf_type, cur_rdf_length, data); <a name="l00266"></a>00266 *pos = *pos + cur_rdf_length; <a name="l00267"></a>00267 } <a name="l00268"></a>00268 <a name="l00269"></a>00269 <span class="keywordflow">if</span> (cur_rdf) { <a name="l00270"></a>00270 <a class="code" href="rr_8c.html#ab5903437318cd6ad1e4b701587c9842c" title="sets rd_field member, it will be placed in the next available spot.">ldns_rr_push_rdf</a>(rr, cur_rdf); <a name="l00271"></a>00271 cur_rdf = NULL; <a name="l00272"></a>00272 } <a name="l00273"></a>00273 } <a name="l00274"></a>00274 <a name="l00275"></a>00275 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00276"></a>00276 } <a name="l00277"></a>00277 <a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="comment">/* TODO:</span> <a name="l00280"></a>00280 <span class="comment"> can *pos be incremented at READ_INT? or maybe use something like</span> <a name="l00281"></a>00281 <span class="comment"> RR_CLASS(wire)?</span> <a name="l00282"></a>00282 <span class="comment"> uhhm Jelte??</span> <a name="l00283"></a>00283 <span class="comment">*/</span> <a name="l00284"></a>00284 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00285"></a><a class="code" href="wire2host_8h.html#a55009dd323cdb52c39e289ac522004bf">00285</a> <a class="code" href="wire2host_8c.html#a5e32cefa04dd6b44e342556c46d4f02f" title="converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.">ldns_wire2rr</a>(<a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> **rr_p, <span class="keyword">const</span> uint8_t *wire, <span class="keywordtype">size_t</span> max, <a name="l00286"></a>00286 <span class="keywordtype">size_t</span> *pos, <a class="code" href="packet_8h.html#a9d9ba3c95f003511a16f9a6236661bc9">ldns_pkt_section</a> section) <a name="l00287"></a>00287 { <a name="l00288"></a>00288 <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *owner = NULL; <a name="l00289"></a>00289 <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr = <a class="code" href="rr_8c.html#af0921b9dc51c173c6e7007c2fcedfce3" title="creates a new rr structure.">ldns_rr_new</a>(); <a name="l00290"></a>00290 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status; <a name="l00291"></a>00291 <a name="l00292"></a>00292 status = <a class="code" href="wire2host_8c.html#a3bf2a93cc61e3942288ebb8b803e4ce9" title="converts the data on the uint8_t bytearray (in wire format) to a DNS dname rdata field.">ldns_wire2dname</a>(&owner, wire, max, pos); <a name="l00293"></a>00293 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00294"></a>00294 <a name="l00295"></a>00295 <a class="code" href="rr_8c.html#a2c7374383b168ce0d33b56f43a91c940" title="sets the owner in the rr structure.">ldns_rr_set_owner</a>(rr, owner); <a name="l00296"></a>00296 <a name="l00297"></a>00297 <span class="keywordflow">if</span> (*pos + 4 > max) { <a name="l00298"></a>00298 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00299"></a>00299 <span class="keywordflow">goto</span> status_error; <a name="l00300"></a>00300 } <a name="l00301"></a>00301 <a name="l00302"></a>00302 <a class="code" href="rr_8c.html#a613e90c7efbdbb3da546fe1f244023c0" title="sets the type in the rr.">ldns_rr_set_type</a>(rr, ldns_read_uint16(&wire[*pos])); <a name="l00303"></a>00303 *pos = *pos + 2; <a name="l00304"></a>00304 <a name="l00305"></a>00305 <a class="code" href="rr_8c.html#aac682e10305e017760e65a423e6e6374" title="sets the class in the rr.">ldns_rr_set_class</a>(rr, ldns_read_uint16(&wire[*pos])); <a name="l00306"></a>00306 *pos = *pos + 2; <a name="l00307"></a>00307 <a name="l00308"></a>00308 <span class="keywordflow">if</span> (section != <a class="code" href="packet_8h.html#adad42096a5200b78a988227bd8c59b71a7f20925b013173d60eccb9d0cf18997e">LDNS_SECTION_QUESTION</a>) { <a name="l00309"></a>00309 <span class="keywordflow">if</span> (*pos + 4 > max) { <a name="l00310"></a>00310 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>; <a name="l00311"></a>00311 <span class="keywordflow">goto</span> status_error; <a name="l00312"></a>00312 } <a name="l00313"></a>00313 <a class="code" href="rr_8c.html#a84a12460eb7ffe5c5fd3d84e9efbe3cf" title="sets the ttl in the rr structure.">ldns_rr_set_ttl</a>(rr, ldns_read_uint32(&wire[*pos])); <a name="l00314"></a>00314 <a name="l00315"></a>00315 *pos = *pos + 4; <a name="l00316"></a>00316 status = <a class="code" href="wire2host_8c.html#a75fe7ca2ee5f51b9c8ab14a37a491d43" title="converts the data on the uint8_t bytearray (in wire format) to DNS rdata fields, and adds them to the...">ldns_wire2rdf</a>(rr, wire, max, pos); <a name="l00317"></a>00317 <a name="l00318"></a>00318 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00319"></a>00319 <a class="code" href="rr_8c.html#a80ab3cc8038d968eea64e7f1360fd4b8" title="sets the question flag in the rr structure.">ldns_rr_set_question</a>(rr, <span class="keyword">false</span>); <a name="l00320"></a>00320 } <span class="keywordflow">else</span> { <a name="l00321"></a>00321 <a class="code" href="rr_8c.html#a80ab3cc8038d968eea64e7f1360fd4b8" title="sets the question flag in the rr structure.">ldns_rr_set_question</a>(rr, <span class="keyword">true</span>); <a name="l00322"></a>00322 } <a name="l00323"></a>00323 <a name="l00324"></a>00324 *rr_p = rr; <a name="l00325"></a>00325 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00326"></a>00326 <a name="l00327"></a>00327 status_error: <a name="l00328"></a>00328 <a class="code" href="rr_8c.html#a277ccb85853d3c527ff3bc963cdde505" title="frees an RR structure">ldns_rr_free</a>(rr); <a name="l00329"></a>00329 <span class="keywordflow">return</span> status; <a name="l00330"></a>00330 } <a name="l00331"></a>00331 <a name="l00332"></a>00332 <span class="keyword">static</span> <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00333"></a>00333 ldns_wire2pkt_hdr(<a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> *packet, <span class="keyword">const</span> uint8_t *wire, <span class="keywordtype">size_t</span> max, <span class="keywordtype">size_t</span> *pos) <a name="l00334"></a>00334 { <a name="l00335"></a>00335 <span class="keywordflow">if</span> (*pos + <a class="code" href="wire2host_8h.html#a94452854ef88ae92a200a2cdb08fb07f">LDNS_HEADER_SIZE</a> > max) { <a name="l00336"></a>00336 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa3792a55167e0c47354379f9c7db84128">LDNS_STATUS_WIRE_INCOMPLETE_HEADER</a>; <a name="l00337"></a>00337 } <span class="keywordflow">else</span> { <a name="l00338"></a>00338 <a class="code" href="packet_8c.html#ace4a28c5ddb36917440db70bc4bd9614" title="Set the packet's id.">ldns_pkt_set_id</a>(packet, <a class="code" href="wire2host_8h.html#a27edb64c61680041cd92b88127d5baa7">LDNS_ID_WIRE</a>(wire)); <a name="l00339"></a>00339 <a class="code" href="packet_8c.html#ae3dc6438162483929b6f5d077a86a6a0" title="Set the packet's qr bit.">ldns_pkt_set_qr</a>(packet, <a class="code" href="wire2host_8h.html#ae618c982fda469fcbb7559c610c5c5c9">LDNS_QR_WIRE</a>(wire)); <a name="l00340"></a>00340 <a class="code" href="packet_8c.html#a31253d7eb96356147df1b1437dab77c7" title="Set the packet's opcode.">ldns_pkt_set_opcode</a>(packet, <a class="code" href="wire2host_8h.html#a24af8d0ef7fb797f9d66562db829c30d">LDNS_OPCODE_WIRE</a>(wire)); <a name="l00341"></a>00341 <a class="code" href="packet_8c.html#a40702391e1243d6917f9c9648116e2f6" title="Set the packet's aa bit.">ldns_pkt_set_aa</a>(packet, <a class="code" href="wire2host_8h.html#a5c47b5bb87d9e789d15f3ec4c6748f59">LDNS_AA_WIRE</a>(wire)); <a name="l00342"></a>00342 <a class="code" href="packet_8c.html#a0d0ec0f182a86863ce394d9846e195ad" title="Set the packet's tc bit.">ldns_pkt_set_tc</a>(packet, <a class="code" href="wire2host_8h.html#af7ce332ba4410e8f2acae2f9c20798d1">LDNS_TC_WIRE</a>(wire)); <a name="l00343"></a>00343 <a class="code" href="packet_8c.html#a10fac125dc3623c6efa198162bf14663" title="Set the packet's rd bit.">ldns_pkt_set_rd</a>(packet, <a class="code" href="wire2host_8h.html#a9ad2f4885c63800843068efdbe620c6f">LDNS_RD_WIRE</a>(wire)); <a name="l00344"></a>00344 <a class="code" href="packet_8c.html#ac41605bf4a78a5d210a9bb81985adc60" title="Set the packet's ra bit.">ldns_pkt_set_ra</a>(packet, <a class="code" href="wire2host_8h.html#aa6455d8de37c1e66b811422f84f7b306">LDNS_RA_WIRE</a>(wire)); <a name="l00345"></a>00345 <a class="code" href="packet_8c.html#a690ec9f53dcbf146383d05fe9e43c524" title="Set the packet's ad bit.">ldns_pkt_set_ad</a>(packet, <a class="code" href="wire2host_8h.html#a524eca8df462c7058a6033b3c78ab1cb">LDNS_AD_WIRE</a>(wire)); <a name="l00346"></a>00346 <a class="code" href="packet_8c.html#a7f6bdee14007649153092d2114894665" title="Set the packet's cd bit.">ldns_pkt_set_cd</a>(packet, <a class="code" href="wire2host_8h.html#a3926092f68a175a748f05d45e94ca14e">LDNS_CD_WIRE</a>(wire)); <a name="l00347"></a>00347 <a class="code" href="packet_8c.html#af61ee2b91dadf199ccbb862e25f2b081" title="Set the packet's respons code.">ldns_pkt_set_rcode</a>(packet, <a class="code" href="wire2host_8h.html#a72db4542316d72a7b87971e9d28e021e">LDNS_RCODE_WIRE</a>(wire)); <a name="l00348"></a>00348 <a name="l00349"></a>00349 <a class="code" href="packet_8c.html#a8c1184a51ba2d82508169d5e9993b9a2" title="Set the packet's qd count.">ldns_pkt_set_qdcount</a>(packet, <a class="code" href="wire2host_8h.html#a8d02271cbd1a6dc33460c9f8560d7167">LDNS_QDCOUNT</a>(wire)); <a name="l00350"></a>00350 <a class="code" href="packet_8c.html#a102126f65a7311eae3be1c659b4e008b" title="Set the packet's an count.">ldns_pkt_set_ancount</a>(packet, <a class="code" href="wire2host_8h.html#ac2b5f503ea3462fb7a20edf851f46ff0">LDNS_ANCOUNT</a>(wire)); <a name="l00351"></a>00351 <a class="code" href="packet_8c.html#a4bacb8d6c93f808aac967d99ad271631" title="Set the packet's ns count.">ldns_pkt_set_nscount</a>(packet, <a class="code" href="wire2host_8h.html#aa9c3fa931e7b4e8385d3fd1590ccda72">LDNS_NSCOUNT</a>(wire)); <a name="l00352"></a>00352 <a class="code" href="packet_8c.html#af3c11171cf7981f75f68ac1e02b0fed3" title="Set the packet's arcount.">ldns_pkt_set_arcount</a>(packet, <a class="code" href="wire2host_8h.html#ac5e039a650ff8d74c982a5c00400af67">LDNS_ARCOUNT</a>(wire)); <a name="l00353"></a>00353 <a name="l00354"></a>00354 *pos += <a class="code" href="wire2host_8h.html#a94452854ef88ae92a200a2cdb08fb07f">LDNS_HEADER_SIZE</a>; <a name="l00355"></a>00355 <a name="l00356"></a>00356 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00357"></a>00357 } <a name="l00358"></a>00358 } <a name="l00359"></a>00359 <a name="l00360"></a>00360 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00361"></a><a class="code" href="wire2host_8h.html#aa860408131e728fcf258385c8fd4c324">00361</a> <a class="code" href="wire2host_8c.html#aa860408131e728fcf258385c8fd4c324" title="converts the data on the uint8_t bytearray (in wire format) to a DNS packet.">ldns_buffer2pkt_wire</a>(<a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> **packet, <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *buffer) <a name="l00362"></a>00362 { <a name="l00363"></a>00363 <span class="comment">/* lazy */</span> <a name="l00364"></a>00364 <span class="keywordflow">return</span> <a class="code" href="wire2host_8c.html#a97a3e0f9c50711f7dcaa5850c6356e09" title="converts the data on the uint8_t bytearray (in wire format) to a DNS packet.">ldns_wire2pkt</a>(packet, ldns_buffer_begin(buffer), <a name="l00365"></a>00365 ldns_buffer_limit(buffer)); <a name="l00366"></a>00366 <a name="l00367"></a>00367 } <a name="l00368"></a>00368 <a name="l00369"></a>00369 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00370"></a><a class="code" href="wire2host_8h.html#a7140e6cbc3cdaa168204328ab7a47be7">00370</a> <a class="code" href="wire2host_8c.html#a97a3e0f9c50711f7dcaa5850c6356e09" title="converts the data on the uint8_t bytearray (in wire format) to a DNS packet.">ldns_wire2pkt</a>(<a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> **packet_p, <span class="keyword">const</span> uint8_t *wire, <span class="keywordtype">size_t</span> max) <a name="l00371"></a>00371 { <a name="l00372"></a>00372 <span class="keywordtype">size_t</span> pos = 0; <a name="l00373"></a>00373 uint16_t i; <a name="l00374"></a>00374 <a class="code" href="structldns__struct__rr.html" title="Resource Record.">ldns_rr</a> *rr; <a name="l00375"></a>00375 <a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> *packet = <a class="code" href="packet_8c.html#a397f48f6716671a13516e37fc465a884" title="allocates and initializes a ldns_pkt structure.">ldns_pkt_new</a>(); <a name="l00376"></a>00376 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00377"></a>00377 <span class="keywordtype">int</span> have_edns = 0; <a name="l00378"></a>00378 <a name="l00379"></a>00379 uint8_t data[4]; <a name="l00380"></a>00380 <a name="l00381"></a>00381 status = ldns_wire2pkt_hdr(packet, wire, max, &pos); <a name="l00382"></a>00382 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00383"></a>00383 <a name="l00384"></a>00384 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="packet_8c.html#acfd9095572aa59123edcdeb598976b69" title="Return the packet's qd count.">ldns_pkt_qdcount</a>(packet); i++) { <a name="l00385"></a>00385 <a name="l00386"></a>00386 status = <a class="code" href="wire2host_8c.html#a5e32cefa04dd6b44e342556c46d4f02f" title="converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.">ldns_wire2rr</a>(&rr, wire, max, &pos, <a class="code" href="packet_8h.html#adad42096a5200b78a988227bd8c59b71a7f20925b013173d60eccb9d0cf18997e">LDNS_SECTION_QUESTION</a>); <a name="l00387"></a>00387 <span class="keywordflow">if</span> (status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>) { <a name="l00388"></a>00388 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa05562056eabb1c9a530fdfe35cb07b65">LDNS_STATUS_WIRE_INCOMPLETE_QUESTION</a>; <a name="l00389"></a>00389 } <a name="l00390"></a>00390 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00391"></a>00391 <span class="keywordflow">if</span> (!<a class="code" href="rr_8c.html#a8bdc038678e7492ae3facf83283f8d04" title="pushes an rr to an rrlist.">ldns_rr_list_push_rr</a>(<a class="code" href="packet_8c.html#a3dbd67b300227c8a40daf3865aeb236e" title="Return the packet's question section.">ldns_pkt_question</a>(packet), rr)) { <a name="l00392"></a>00392 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(packet); <a name="l00393"></a>00393 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa9029a7994da0e2f27cff8848a6c6f9da">LDNS_STATUS_INTERNAL_ERR</a>; <a name="l00394"></a>00394 } <a name="l00395"></a>00395 } <a name="l00396"></a>00396 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="packet_8c.html#a801e0c9c3766dde74347793984ecd417" title="Return the packet's an count.">ldns_pkt_ancount</a>(packet); i++) { <a name="l00397"></a>00397 status = <a class="code" href="wire2host_8c.html#a5e32cefa04dd6b44e342556c46d4f02f" title="converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.">ldns_wire2rr</a>(&rr, wire, max, &pos, <a class="code" href="packet_8h.html#adad42096a5200b78a988227bd8c59b71a80effb31e9d19e57c89b79424a0b08ec">LDNS_SECTION_ANSWER</a>); <a name="l00398"></a>00398 <span class="keywordflow">if</span> (status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>) { <a name="l00399"></a>00399 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaa0975072f4b49d00fa9accb3f66eef13">LDNS_STATUS_WIRE_INCOMPLETE_ANSWER</a>; <a name="l00400"></a>00400 } <a name="l00401"></a>00401 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00402"></a>00402 <span class="keywordflow">if</span> (!<a class="code" href="rr_8c.html#a8bdc038678e7492ae3facf83283f8d04" title="pushes an rr to an rrlist.">ldns_rr_list_push_rr</a>(<a class="code" href="packet_8c.html#abe3507def1f75f9a369334f75a4b4799" title="Return the packet's answer section.">ldns_pkt_answer</a>(packet), rr)) { <a name="l00403"></a>00403 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(packet); <a name="l00404"></a>00404 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa9029a7994da0e2f27cff8848a6c6f9da">LDNS_STATUS_INTERNAL_ERR</a>; <a name="l00405"></a>00405 } <a name="l00406"></a>00406 } <a name="l00407"></a>00407 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="packet_8c.html#ac551c3cfc6a48241e1d4cd4d1390df1c" title="Return the packet's ns count.">ldns_pkt_nscount</a>(packet); i++) { <a name="l00408"></a>00408 status = <a class="code" href="wire2host_8c.html#a5e32cefa04dd6b44e342556c46d4f02f" title="converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.">ldns_wire2rr</a>(&rr, wire, max, &pos, <a class="code" href="packet_8h.html#adad42096a5200b78a988227bd8c59b71ab4c0eddd3ed0bfc089a7eb0cded20558">LDNS_SECTION_AUTHORITY</a>); <a name="l00409"></a>00409 <span class="keywordflow">if</span> (status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>) { <a name="l00410"></a>00410 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaa8f309dc0b33d2004aa5508ded949e5f">LDNS_STATUS_WIRE_INCOMPLETE_AUTHORITY</a>; <a name="l00411"></a>00411 } <a name="l00412"></a>00412 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00413"></a>00413 <span class="keywordflow">if</span> (!<a class="code" href="rr_8c.html#a8bdc038678e7492ae3facf83283f8d04" title="pushes an rr to an rrlist.">ldns_rr_list_push_rr</a>(<a class="code" href="packet_8c.html#a7edc2a338e1adfce9ef3ae137e6aa5d6" title="Return the packet's authority section.">ldns_pkt_authority</a>(packet), rr)) { <a name="l00414"></a>00414 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(packet); <a name="l00415"></a>00415 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa9029a7994da0e2f27cff8848a6c6f9da">LDNS_STATUS_INTERNAL_ERR</a>; <a name="l00416"></a>00416 } <a name="l00417"></a>00417 } <a name="l00418"></a>00418 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="packet_8c.html#a45ad46caf5027284947fe58b77b2a93a" title="Return the packet's ar count.">ldns_pkt_arcount</a>(packet); i++) { <a name="l00419"></a>00419 status = <a class="code" href="wire2host_8c.html#a5e32cefa04dd6b44e342556c46d4f02f" title="converts the data on the uint8_t bytearray (in wire format) to a DNS resource record.">ldns_wire2rr</a>(&rr, wire, max, &pos, <a class="code" href="packet_8h.html#adad42096a5200b78a988227bd8c59b71a9bf00ce2a238c55f94ceeaf64aecdfbb">LDNS_SECTION_ADDITIONAL</a>); <a name="l00420"></a>00420 <span class="keywordflow">if</span> (status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad0a3d207d418643d04247ebfc0f92661">LDNS_STATUS_PACKET_OVERFLOW</a>) { <a name="l00421"></a>00421 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa1dc38015a1d6a6009be4f597c323b871">LDNS_STATUS_WIRE_INCOMPLETE_ADDITIONAL</a>; <a name="l00422"></a>00422 } <a name="l00423"></a>00423 <a class="code" href="wire2host_8c.html#a89509cf0223950762a81638f0a826713">LDNS_STATUS_CHECK_GOTO</a>(status, status_error); <a name="l00424"></a>00424 <a name="l00425"></a>00425 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(rr) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa0cf8c9717f510a211a3e271891553e10" title="Pseudo OPT record...">LDNS_RR_TYPE_OPT</a>) { <a name="l00426"></a>00426 <a class="code" href="packet_8c.html#a2f838fd8f8a7d2e1c1039df0869cdc66" title="Set the packet's edns udp size.">ldns_pkt_set_edns_udp_size</a>(packet, <a class="code" href="rr_8c.html#a9674642920718eda5c65483e03587fff" title="returns the class of the rr.">ldns_rr_get_class</a>(rr)); <a name="l00427"></a>00427 ldns_write_uint32(data, <a class="code" href="rr_8c.html#a144e619c75e8cef52fa5a1de7d74c695" title="returns the ttl of an rr structure.">ldns_rr_ttl</a>(rr)); <a name="l00428"></a>00428 <a class="code" href="packet_8c.html#ad3b45ffeeb71506329547e976d720a72" title="Set the packet's edns extended rcode.">ldns_pkt_set_edns_extended_rcode</a>(packet, data[0]); <a name="l00429"></a>00429 <a class="code" href="packet_8c.html#afcdf029dbbced3e04fa6696a3773102c" title="Set the packet's edns version.">ldns_pkt_set_edns_version</a>(packet, data[1]); <a name="l00430"></a>00430 <a class="code" href="packet_8c.html#a9890540c35fba9eebbb42c7cdc56fee6" title="Set the packet's edns z value.">ldns_pkt_set_edns_z</a>(packet, ldns_read_uint16(&data[2])); <a name="l00431"></a>00431 <span class="comment">/* edns might not have rdfs */</span> <a name="l00432"></a>00432 <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#aed836e7b90f7c11993d92a4569d7e29b" title="returns the rdata field member counter.">ldns_rr_rdf</a>(rr, 0)) { <a name="l00433"></a>00433 <a class="code" href="packet_8c.html#ab4a4e43ac8288fcf2d44beea87c10613" title="Set the packet's edns data.">ldns_pkt_set_edns_data</a>(packet, <a class="code" href="rdata_8c.html#af9a39f2f8b749efa6a20ba91cb696961" title="clones a rdf structure.">ldns_rdf_clone</a>(<a class="code" href="rr_8c.html#aed836e7b90f7c11993d92a4569d7e29b" title="returns the rdata field member counter.">ldns_rr_rdf</a>(rr, 0))); <a name="l00434"></a>00434 } <a name="l00435"></a>00435 <a class="code" href="rr_8c.html#a277ccb85853d3c527ff3bc963cdde505" title="frees an RR structure">ldns_rr_free</a>(rr); <a name="l00436"></a>00436 have_edns += 1; <a name="l00437"></a>00437 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="rr_8c.html#a849c616b8e8d87b8c047a8b41be21228" title="returns the type of the rr.">ldns_rr_get_type</a>(rr) == <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daa46daaae4a76c2af7f42135aa2cb4c6b9">LDNS_RR_TYPE_TSIG</a>) { <a name="l00438"></a>00438 <a class="code" href="packet_8c.html#a19d8214fc5305aea0403fd70c529b151" title="Set the packet's tsig rr.">ldns_pkt_set_tsig</a>(packet, rr); <a name="l00439"></a>00439 <a class="code" href="packet_8c.html#af3c11171cf7981f75f68ac1e02b0fed3" title="Set the packet's arcount.">ldns_pkt_set_arcount</a>(packet, <a class="code" href="packet_8c.html#a45ad46caf5027284947fe58b77b2a93a" title="Return the packet's ar count.">ldns_pkt_arcount</a>(packet) - 1); <a name="l00440"></a>00440 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!<a class="code" href="rr_8c.html#a8bdc038678e7492ae3facf83283f8d04" title="pushes an rr to an rrlist.">ldns_rr_list_push_rr</a>(<a class="code" href="packet_8c.html#a9419e23858eddcd58bd61fcf39cffd61" title="Return the packet's additional section.">ldns_pkt_additional</a>(packet), rr)) { <a name="l00441"></a>00441 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(packet); <a name="l00442"></a>00442 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa9029a7994da0e2f27cff8848a6c6f9da">LDNS_STATUS_INTERNAL_ERR</a>; <a name="l00443"></a>00443 } <a name="l00444"></a>00444 } <a name="l00445"></a>00445 <a class="code" href="packet_8c.html#a64bc812fa152d07c2913aa9f635cf33c" title="Set the packet's size.">ldns_pkt_set_size</a>(packet, max); <a name="l00446"></a>00446 <span class="keywordflow">if</span>(have_edns) <a name="l00447"></a>00447 <a class="code" href="packet_8c.html#af3c11171cf7981f75f68ac1e02b0fed3" title="Set the packet's arcount.">ldns_pkt_set_arcount</a>(packet, <a class="code" href="packet_8c.html#a45ad46caf5027284947fe58b77b2a93a" title="Return the packet's ar count.">ldns_pkt_arcount</a>(packet) <a name="l00448"></a>00448 - have_edns); <a name="l00449"></a>00449 <a name="l00450"></a>00450 *packet_p = packet; <a name="l00451"></a>00451 <span class="keywordflow">return</span> status; <a name="l00452"></a>00452 <a name="l00453"></a>00453 status_error: <a name="l00454"></a>00454 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(packet); <a name="l00455"></a>00455 <span class="keywordflow">return</span> status; <a name="l00456"></a>00456 } </pre></div></div> </div> <hr class="footer"/><address class="footer"><small>Generated on Wed Jan 11 2012 for ldns by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address> </body> </html>