<!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">net.c</div> </div> </div> <div class="contents"> <a href="net_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"> * net.c</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * Network implementation</span> <a name="l00005"></a>00005 <span class="comment"> * All network related functions are grouped here</span> <a name="l00006"></a>00006 <span class="comment"> *</span> <a name="l00007"></a>00007 <span class="comment"> * a Net::DNS like library for C</span> <a name="l00008"></a>00008 <span class="comment"> *</span> <a name="l00009"></a>00009 <span class="comment"> * (c) NLnet Labs, 2004-2006</span> <a name="l00010"></a>00010 <span class="comment"> *</span> <a name="l00011"></a>00011 <span class="comment"> * See the file LICENSE for the license</span> <a name="l00012"></a>00012 <span class="comment"> */</span> <a name="l00013"></a>00013 <a name="l00014"></a>00014 <span class="preprocessor">#include <<a class="code" href="ldns_2config_8h.html">ldns/config.h</a>></span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <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="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#ifdef HAVE_NETINET_IN_H</span> <a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">#include <netinet/in.h></span> <a name="l00020"></a>00020 <span class="preprocessor">#endif</span> <a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_SYS_SOCKET_H</span> <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#include <sys/socket.h></span> <a name="l00023"></a>00023 <span class="preprocessor">#endif</span> <a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_NETDB_H</span> <a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#include <netdb.h></span> <a name="l00026"></a>00026 <span class="preprocessor">#endif</span> <a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#ifdef HAVE_ARPA_INET_H</span> <a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#include <arpa/inet.h></span> <a name="l00029"></a>00029 <span class="preprocessor">#endif</span> <a name="l00030"></a>00030 <span class="preprocessor"></span><span class="preprocessor">#include <sys/time.h></span> <a name="l00031"></a>00031 <span class="preprocessor">#include <errno.h></span> <a name="l00032"></a>00032 <span class="preprocessor">#include <fcntl.h></span> <a name="l00033"></a>00033 <a name="l00034"></a>00034 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00035"></a><a class="code" href="net_8h.html#ae8d445949587087d2c91748f5e39c8c1">00035</a> <a class="code" href="net_8c.html#a42475d77dddb17b023b3fd026b32df02" title="Sends ptk to the nameserver at the resolver object.">ldns_send</a>(<a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> **result_packet, <a class="code" href="structldns__struct__resolver.html" title="DNS stub resolver structure.">ldns_resolver</a> *r, <span class="keyword">const</span> <a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> *query_pkt) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qb; <a name="l00038"></a>00038 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> result; <a name="l00039"></a>00039 <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *tsig_mac = NULL; <a name="l00040"></a>00040 <a name="l00041"></a>00041 qb = <a class="code" href="buffer_8c.html#ac6d413e9a76bf7e7c2022f13e36b9900" title="creates a new buffer with the specified capacity.">ldns_buffer_new</a>(<a class="code" href="buffer_8h.html#af725b95a81365884b13c31a2f5d4c107" title="number of initial bytes in buffer of which we cannot tell the size before hand">LDNS_MIN_BUFLEN</a>); <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="keywordflow">if</span> (query_pkt && <a class="code" href="packet_8c.html#ad7dead450927dc5d6db4dd4ef7c738e1" title="Return the packet's tsig pseudo rr's.">ldns_pkt_tsig</a>(query_pkt)) { <a name="l00044"></a>00044 tsig_mac = <a class="code" href="rr_8c.html#aed836e7b90f7c11993d92a4569d7e29b" title="returns the rdata field member counter.">ldns_rr_rdf</a>(<a class="code" href="packet_8c.html#ad7dead450927dc5d6db4dd4ef7c738e1" title="Return the packet's tsig pseudo rr's.">ldns_pkt_tsig</a>(query_pkt), 3); <a name="l00045"></a>00045 } <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="keywordflow">if</span> (!query_pkt || <a name="l00048"></a>00048 <a class="code" href="host2wire_8c.html#aa40d4e3f29ccf46535901c5d5010054b" title="Copies the packet data to the buffer in wire format.">ldns_pkt2buffer_wire</a>(qb, query_pkt) != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00049"></a>00049 result = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa804a996d5f13cda0806bf1d54114d2ca">LDNS_STATUS_ERR</a>; <a name="l00050"></a>00050 } <span class="keywordflow">else</span> { <a name="l00051"></a>00051 result = <a class="code" href="net_8c.html#a807e96a5b5ba8e01e642a9a1ce2712e1" title="Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object...">ldns_send_buffer</a>(result_packet, r, qb, tsig_mac); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a>00054 <a class="code" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44" title="frees the buffer.">ldns_buffer_free</a>(qb); <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="keywordflow">return</span> result; <a name="l00057"></a>00057 } <a name="l00058"></a>00058 <a name="l00059"></a>00059 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00060"></a><a class="code" href="net_8h.html#a1c79e22528bdea08ec1e16ddb7bca1ec">00060</a> <a class="code" href="net_8c.html#a807e96a5b5ba8e01e642a9a1ce2712e1" title="Sends and ldns_buffer (presumably containing a packet to the nameserver at the resolver object...">ldns_send_buffer</a>(<a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> **result, <a class="code" href="structldns__struct__resolver.html" title="DNS stub resolver structure.">ldns_resolver</a> *r, <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qb, <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *tsig_mac) <a name="l00061"></a>00061 { <a name="l00062"></a>00062 uint8_t i; <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="keyword">struct </span>sockaddr_storage *ns; <a name="l00065"></a>00065 <span class="keywordtype">size_t</span> ns_len; <a name="l00066"></a>00066 <span class="keyword">struct </span>timeval tv_s; <a name="l00067"></a>00067 <span class="keyword">struct </span>timeval tv_e; <a name="l00068"></a>00068 <a name="l00069"></a>00069 <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> **ns_array; <a name="l00070"></a>00070 <span class="keywordtype">size_t</span> *rtt; <a name="l00071"></a>00071 <a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> *reply; <a name="l00072"></a>00072 <span class="keywordtype">bool</span> all_servers_rtt_inf; <a name="l00073"></a>00073 uint8_t retries; <a name="l00074"></a>00074 <a name="l00075"></a>00075 uint8_t *reply_bytes = NULL; <a name="l00076"></a>00076 <span class="keywordtype">size_t</span> reply_size = 0; <a name="l00077"></a>00077 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status, send_status; <a name="l00078"></a>00078 <a name="l00079"></a>00079 assert(r != NULL); <a name="l00080"></a>00080 <a name="l00081"></a>00081 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00082"></a>00082 rtt = <a class="code" href="resolver_8c.html#a9d5f40f133fd13433603e15eea5a077b" title="Return the used round trip times for the nameservers.">ldns_resolver_rtt</a>(r); <a name="l00083"></a>00083 ns_array = <a class="code" href="resolver_8c.html#ac8068f8b2fa8621abb1557c3b4d95688" title="Return the configured nameserver ip address.">ldns_resolver_nameservers</a>(r); <a name="l00084"></a>00084 reply = NULL; <a name="l00085"></a>00085 ns_len = 0; <a name="l00086"></a>00086 <a name="l00087"></a>00087 all_servers_rtt_inf = <span class="keyword">true</span>; <a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="keywordflow">if</span> (<a class="code" href="resolver_8c.html#a96748f05895afe899f44aabbe839d9ea" title="Does the resolver randomize the nameserver before usage.">ldns_resolver_random</a>(r)) { <a name="l00090"></a>00090 <a class="code" href="resolver_8c.html#a8550c5d04235608d78910e99a9a86f3c" title="Randomize the nameserver list in the resolver.">ldns_resolver_nameservers_randomize</a>(r); <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="comment">/* loop through all defined nameservers */</span> <a name="l00094"></a>00094 <span class="keywordflow">for</span> (i = 0; i < <a class="code" href="resolver_8c.html#a64e6087bcfc88459e34da80077bad7eb" title="How many nameserver are configured in the resolver.">ldns_resolver_nameserver_count</a>(r); i++) { <a name="l00095"></a>00095 <span class="keywordflow">if</span> (rtt[i] == <a class="code" href="resolver_8h.html#a4217a153c5d931ab49a47d4b3e1c8ad7">LDNS_RESOLV_RTT_INF</a>) { <a name="l00096"></a>00096 <span class="comment">/* not reachable nameserver! */</span> <a name="l00097"></a>00097 <span class="keywordflow">continue</span>; <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">/* maybe verbosity setting?</span> <a name="l00101"></a>00101 <span class="comment"> printf("Sending to ");</span> <a name="l00102"></a>00102 <span class="comment"> ldns_rdf_print(stdout, ns_array[i]);</span> <a name="l00103"></a>00103 <span class="comment"> printf("\n");</span> <a name="l00104"></a>00104 <span class="comment"> */</span> <a name="l00105"></a>00105 ns = <a class="code" href="net_8c.html#a897b9376491b14bb57cdda6e6511464f" title="returns the native sockaddr representation from the rdf.">ldns_rdf2native_sockaddr_storage</a>(ns_array[i], <a name="l00106"></a>00106 <a class="code" href="resolver_8c.html#ae8062e9bb7436dc91717915686f28a60" title="Get the port the resolver should use.">ldns_resolver_port</a>(r), &ns_len); <a name="l00107"></a>00107 <a name="l00108"></a>00108 <a name="l00109"></a>00109 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00110"></a>00110 <span class="preprocessor"></span> <span class="keywordflow">if</span> ((ns->ss_family == AF_INET) && <a name="l00111"></a>00111 (<a class="code" href="resolver_8c.html#aa32acefa4cdf90e11b26024b55416618" title="Does the resolver use ip6 or ip4.">ldns_resolver_ip6</a>(r) == <a class="code" href="resolver_8h.html#ae95e3ef02e5ebd9dbda1d70ae87092ab">LDNS_RESOLV_INET6</a>)) { <a name="l00112"></a>00112 <span class="comment">/* not reachable */</span> <a name="l00113"></a>00113 <span class="keywordflow">continue</span>; <a name="l00114"></a>00114 } <a name="l00115"></a>00115 <a name="l00116"></a>00116 <span class="keywordflow">if</span> ((ns->ss_family == AF_INET6) && <a name="l00117"></a>00117 (<a class="code" href="resolver_8c.html#aa32acefa4cdf90e11b26024b55416618" title="Does the resolver use ip6 or ip4.">ldns_resolver_ip6</a>(r) == <a class="code" href="resolver_8h.html#acb999b027046ea367c0dafc63baf67cc">LDNS_RESOLV_INET</a>)) { <a name="l00118"></a>00118 <span class="comment">/* not reachable */</span> <a name="l00119"></a>00119 <span class="keywordflow">continue</span>; <a name="l00120"></a>00120 } <a name="l00121"></a>00121 <span class="preprocessor">#endif</span> <a name="l00122"></a>00122 <span class="preprocessor"></span> <a name="l00123"></a>00123 all_servers_rtt_inf = <span class="keyword">false</span>; <a name="l00124"></a>00124 <a name="l00125"></a>00125 gettimeofday(&tv_s, NULL); <a name="l00126"></a>00126 <a name="l00127"></a>00127 send_status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa804a996d5f13cda0806bf1d54114d2ca">LDNS_STATUS_ERR</a>; <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="comment">/* reply_bytes implicitly handles our error */</span> <a name="l00130"></a>00130 <span class="keywordflow">if</span> (1 == <a class="code" href="resolver_8c.html#a45a83b6f43d816b98c176c23d7772e07" title="Does the resolver use tcp or udp.">ldns_resolver_usevc</a>(r)) { <a name="l00131"></a>00131 <span class="keywordflow">for</span> (retries = <a class="code" href="resolver_8c.html#aa8ab6ca6295b9b2744e1e2a14fb95bca" title="Get the number of retries.">ldns_resolver_retry</a>(r); retries > 0; retries--) { <a name="l00132"></a>00132 send_status = <a name="l00133"></a>00133 <a class="code" href="net_8c.html#add29437506d01b49c5d2d84cd0589999" title="Sends a buffer to an ip using tcp and return the respons as a ldns_pkt.">ldns_tcp_send</a>(&reply_bytes, qb, ns, <a name="l00134"></a>00134 (socklen_t)ns_len, <a class="code" href="resolver_8c.html#a9958f4244f667c71f069524eb0720f5c" title="What is the timeout on socket connections.">ldns_resolver_timeout</a>(r), <a name="l00135"></a>00135 &reply_size); <a name="l00136"></a>00136 <span class="keywordflow">if</span> (send_status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00137"></a>00137 <span class="keywordflow">break</span>; <a name="l00138"></a>00138 } <a name="l00139"></a>00139 } <a name="l00140"></a>00140 } <span class="keywordflow">else</span> { <a name="l00141"></a>00141 <span class="keywordflow">for</span> (retries = <a class="code" href="resolver_8c.html#aa8ab6ca6295b9b2744e1e2a14fb95bca" title="Get the number of retries.">ldns_resolver_retry</a>(r); retries > 0; retries--) { <a name="l00142"></a>00142 <span class="comment">/* ldns_rdf_print(stdout, ns_array[i]); */</span> <a name="l00143"></a>00143 send_status = <a name="l00144"></a>00144 <a class="code" href="net_8c.html#abd60865d343250317ff4edf7c8b775d0" title="Sends a buffer to an ip using udp and return the respons as a ldns_pkt.">ldns_udp_send</a>(&reply_bytes, qb, ns, <a name="l00145"></a>00145 (socklen_t)ns_len, <a class="code" href="resolver_8c.html#a9958f4244f667c71f069524eb0720f5c" title="What is the timeout on socket connections.">ldns_resolver_timeout</a>(r), <a name="l00146"></a>00146 &reply_size); <a name="l00147"></a>00147 <a name="l00148"></a>00148 <span class="keywordflow">if</span> (send_status == <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00149"></a>00149 <span class="keywordflow">break</span>; <a name="l00150"></a>00150 } <a name="l00151"></a>00151 } <a name="l00152"></a>00152 } <a name="l00153"></a>00153 <a name="l00154"></a>00154 <span class="keywordflow">if</span> (send_status != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00155"></a>00155 <a class="code" href="resolver_8c.html#a3c5903d145c7e078f5688294cce92b1d" title="Set round trip time for a specific nameserver.">ldns_resolver_set_nameserver_rtt</a>(r, i, <a class="code" href="resolver_8h.html#a4217a153c5d931ab49a47d4b3e1c8ad7">LDNS_RESOLV_RTT_INF</a>); <a name="l00156"></a>00156 status = send_status; <a name="l00157"></a>00157 } <a name="l00158"></a>00158 <a name="l00159"></a>00159 <span class="comment">/* obey the fail directive */</span> <a name="l00160"></a>00160 <span class="keywordflow">if</span> (!reply_bytes) { <a name="l00161"></a>00161 <span class="comment">/* the current nameserver seems to have a problem, blacklist it */</span> <a name="l00162"></a>00162 <span class="keywordflow">if</span> (<a class="code" href="resolver_8c.html#ab41d8f3a683763660862f89f985fcfe4" title="Does the resolver only try the first nameserver.">ldns_resolver_fail</a>(r)) { <a name="l00163"></a>00163 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00164"></a>00164 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa804a996d5f13cda0806bf1d54114d2ca">LDNS_STATUS_ERR</a>; <a name="l00165"></a>00165 } <span class="keywordflow">else</span> { <a name="l00166"></a>00166 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00167"></a>00167 <span class="keywordflow">continue</span>; <a name="l00168"></a>00168 } <a name="l00169"></a>00169 } <a name="l00170"></a>00170 <a name="l00171"></a>00171 status = <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>(&reply, reply_bytes, reply_size); <a name="l00172"></a>00172 <span class="keywordflow">if</span> (status != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00173"></a>00173 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(reply_bytes); <a name="l00174"></a>00174 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00175"></a>00175 <span class="keywordflow">return</span> status; <a name="l00176"></a>00176 } <a name="l00177"></a>00177 <a name="l00178"></a>00178 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00179"></a>00179 gettimeofday(&tv_e, NULL); <a name="l00180"></a>00180 <a name="l00181"></a>00181 <span class="keywordflow">if</span> (reply) { <a name="l00182"></a>00182 <a class="code" href="packet_8c.html#a192078cf50d0b8ca13098441d34fe60d" title="Set the packet's query time.">ldns_pkt_set_querytime</a>(reply, (uint32_t) <a name="l00183"></a>00183 ((tv_e.tv_sec - tv_s.tv_sec) * 1000) + <a name="l00184"></a>00184 (tv_e.tv_usec - tv_s.tv_usec) / 1000); <a name="l00185"></a>00185 <a class="code" href="packet_8c.html#ae11de27759e56ecff62e928a0e52e520" title="Set the packet's answering server.">ldns_pkt_set_answerfrom</a>(reply, ns_array[i]); <a name="l00186"></a>00186 <a class="code" href="packet_8c.html#a5568dc152297e14f728d8f94fa66edbe" title="Set the packet's timestamp.">ldns_pkt_set_timestamp</a>(reply, tv_s); <a name="l00187"></a>00187 <a class="code" href="packet_8c.html#a64bc812fa152d07c2913aa9f635cf33c" title="Set the packet's size.">ldns_pkt_set_size</a>(reply, reply_size); <a name="l00188"></a>00188 <span class="keywordflow">break</span>; <a name="l00189"></a>00189 } <span class="keywordflow">else</span> { <a name="l00190"></a>00190 <span class="keywordflow">if</span> (<a class="code" href="resolver_8c.html#ab41d8f3a683763660862f89f985fcfe4" title="Does the resolver only try the first nameserver.">ldns_resolver_fail</a>(r)) { <a name="l00191"></a>00191 <span class="comment">/* if fail is set bail out, after the first</span> <a name="l00192"></a>00192 <span class="comment"> * one */</span> <a name="l00193"></a>00193 <span class="keywordflow">break</span>; <a name="l00194"></a>00194 } <a name="l00195"></a>00195 } <a name="l00196"></a>00196 <a name="l00197"></a>00197 <span class="comment">/* wait retrans seconds... */</span> <a name="l00198"></a>00198 <a class="code" href="config_8h.html#a82b8e21bd452d01ad6d32a0d73fbfdc8">sleep</a>((<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>) <a class="code" href="resolver_8c.html#a7e3c2ea266cc050427622b54c641b6e2" title="Get the retransmit interval.">ldns_resolver_retrans</a>(r)); <a name="l00199"></a>00199 } <a name="l00200"></a>00200 <a name="l00201"></a>00201 <span class="keywordflow">if</span> (all_servers_rtt_inf) { <a name="l00202"></a>00202 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(reply_bytes); <a name="l00203"></a>00203 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afad32d0804440e92c91eecb4bd79da4960">LDNS_STATUS_RES_NO_NS</a>; <a name="l00204"></a>00204 } <a name="l00205"></a>00205 <span class="preprocessor">#ifdef HAVE_SSL</span> <a name="l00206"></a>00206 <span class="preprocessor"></span> <span class="keywordflow">if</span> (tsig_mac && reply_bytes) { <a name="l00207"></a>00207 <span class="keywordflow">if</span> (!<a class="code" href="tsig_8c.html#a586dcebbdc6982d05d27277b4972849d" title="verifies the tsig rr for the given packet and key.">ldns_pkt_tsig_verify</a>(reply, <a name="l00208"></a>00208 reply_bytes, <a name="l00209"></a>00209 reply_size, <a name="l00210"></a>00210 <a class="code" href="resolver_8c.html#a262ac7450159c115060ec464a4a5af6e" title="Return the tsig keyname as used by the nameserver.">ldns_resolver_tsig_keyname</a>(r), <a name="l00211"></a>00211 <a class="code" href="resolver_8c.html#abc7e0d0e3960348f774164d34af3013b" title="Return the tsig keydata as used by the nameserver.">ldns_resolver_tsig_keydata</a>(r), tsig_mac)) { <a name="l00212"></a>00212 status = <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa9c2069af2fcbd62ee59324909b2722ad">LDNS_STATUS_CRYPTO_TSIG_BOGUS</a>; <a name="l00213"></a>00213 } <a name="l00214"></a>00214 } <a name="l00215"></a>00215 <span class="preprocessor">#else</span> <a name="l00216"></a>00216 <span class="preprocessor"></span> (void)tsig_mac; <a name="l00217"></a>00217 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_SSL */</span> <a name="l00218"></a>00218 <a name="l00219"></a>00219 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(reply_bytes); <a name="l00220"></a>00220 <span class="keywordflow">if</span> (result) { <a name="l00221"></a>00221 *result = reply; <a name="l00222"></a>00222 } <a name="l00223"></a>00223 <a name="l00224"></a>00224 <span class="keywordflow">return</span> status; <a name="l00225"></a>00225 } <a name="l00226"></a>00226 <a name="l00228"></a>00228 <span class="keyword">static</span> <span class="keywordtype">void</span> <a name="l00229"></a>00229 ldns_sock_nonblock(<span class="keywordtype">int</span> sockfd) <a name="l00230"></a>00230 { <a name="l00231"></a>00231 <span class="preprocessor">#ifdef HAVE_FCNTL</span> <a name="l00232"></a>00232 <span class="preprocessor"></span> <span class="keywordtype">int</span> flag; <a name="l00233"></a>00233 <span class="keywordflow">if</span>((flag = fcntl(sockfd, F_GETFL)) != -1) { <a name="l00234"></a>00234 flag |= O_NONBLOCK; <a name="l00235"></a>00235 <span class="keywordflow">if</span>(fcntl(sockfd, F_SETFL, flag) == -1) { <a name="l00236"></a>00236 <span class="comment">/* ignore error, continue blockingly */</span> <a name="l00237"></a>00237 } <a name="l00238"></a>00238 } <a name="l00239"></a>00239 <span class="preprocessor">#elif defined(HAVE_IOCTLSOCKET)</span> <a name="l00240"></a>00240 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> on = 1; <a name="l00241"></a>00241 <span class="keywordflow">if</span>(ioctlsocket(sockfd, FIONBIO, &on) != 0) { <a name="l00242"></a>00242 <span class="comment">/* ignore error, continue blockingly */</span> <a name="l00243"></a>00243 } <a name="l00244"></a>00244 <span class="preprocessor">#endif</span> <a name="l00245"></a>00245 <span class="preprocessor"></span>} <a name="l00246"></a>00246 <a name="l00248"></a>00248 <span class="keyword">static</span> <span class="keywordtype">void</span> <a name="l00249"></a>00249 ldns_sock_block(<span class="keywordtype">int</span> sockfd) <a name="l00250"></a>00250 { <a name="l00251"></a>00251 <span class="preprocessor">#ifdef HAVE_FCNTL</span> <a name="l00252"></a>00252 <span class="preprocessor"></span> <span class="keywordtype">int</span> flag; <a name="l00253"></a>00253 <span class="keywordflow">if</span>((flag = fcntl(sockfd, F_GETFL)) != -1) { <a name="l00254"></a>00254 flag &= ~O_NONBLOCK; <a name="l00255"></a>00255 <span class="keywordflow">if</span>(fcntl(sockfd, F_SETFL, flag) == -1) { <a name="l00256"></a>00256 <span class="comment">/* ignore error, continue */</span> <a name="l00257"></a>00257 } <a name="l00258"></a>00258 } <a name="l00259"></a>00259 <span class="preprocessor">#elif defined(HAVE_IOCTLSOCKET)</span> <a name="l00260"></a>00260 <span class="preprocessor"></span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> off = 0; <a name="l00261"></a>00261 <span class="keywordflow">if</span>(ioctlsocket(sockfd, FIONBIO, &off) != 0) { <a name="l00262"></a>00262 <span class="comment">/* ignore error, continue */</span> <a name="l00263"></a>00263 } <a name="l00264"></a>00264 <span class="preprocessor">#endif</span> <a name="l00265"></a>00265 <span class="preprocessor"></span>} <a name="l00266"></a>00266 <a name="l00268"></a>00268 <span class="keyword">static</span> <span class="keywordtype">int</span> <a name="l00269"></a>00269 ldns_sock_wait(<span class="keywordtype">int</span> sockfd, <span class="keyword">struct</span> timeval timeout, <span class="keywordtype">int</span> write) <a name="l00270"></a>00270 { <a name="l00271"></a>00271 <span class="keywordtype">int</span> ret; <a name="l00272"></a>00272 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00273"></a>00273 <span class="preprocessor"></span> fd_set fds; <a name="l00274"></a>00274 FD_ZERO(&fds); <a name="l00275"></a>00275 FD_SET(<a class="code" href="config_8h.html#a812bc9975f0e93c62b773e21af494006">FD_SET_T</a> sockfd, &fds); <a name="l00276"></a>00276 <span class="keywordflow">if</span>(write) <a name="l00277"></a>00277 ret = select(sockfd+1, NULL, &fds, NULL, &timeout); <a name="l00278"></a>00278 <span class="keywordflow">else</span> <a name="l00279"></a>00279 ret = select(sockfd+1, &fds, NULL, NULL, &timeout); <a name="l00280"></a>00280 <span class="preprocessor">#endif</span> <a name="l00281"></a>00281 <span class="preprocessor"></span> <span class="keywordflow">if</span>(ret == 0) <a name="l00282"></a>00282 <span class="comment">/* timeout expired */</span> <a name="l00283"></a>00283 <span class="keywordflow">return</span> 0; <a name="l00284"></a>00284 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(ret == -1) <a name="l00285"></a>00285 <span class="comment">/* error */</span> <a name="l00286"></a>00286 <span class="keywordflow">return</span> 0; <a name="l00287"></a>00287 <span class="keywordflow">return</span> 1; <a name="l00288"></a>00288 } <a name="l00289"></a>00289 <a name="l00290"></a>00290 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00291"></a><a class="code" href="net_8h.html#ae4a781d456d0971265b773f18f4c6ecc">00291</a> <a class="code" href="net_8c.html#abd60865d343250317ff4edf7c8b775d0" title="Sends a buffer to an ip using udp and return the respons as a ldns_pkt.">ldns_udp_send</a>(uint8_t **result, <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, <a name="l00292"></a>00292 socklen_t tolen, <span class="keyword">struct</span> timeval timeout, <span class="keywordtype">size_t</span> *answer_size) <a name="l00293"></a>00293 { <a name="l00294"></a>00294 <span class="keywordtype">int</span> sockfd; <a name="l00295"></a>00295 uint8_t *answer; <a name="l00296"></a>00296 <a name="l00297"></a>00297 sockfd = <a class="code" href="net_8c.html#a84751182c6fa8f75ff79da83c18c0954" title="Send an udp query and don't wait for an answer but return the socket.">ldns_udp_bgsend</a>(qbin, to, tolen, timeout); <a name="l00298"></a>00298 <a name="l00299"></a>00299 <span class="keywordflow">if</span> (sockfd == 0) { <a name="l00300"></a>00300 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa5e6d09e60bd58f655364e55c053ff13a">LDNS_STATUS_SOCKET_ERROR</a>; <a name="l00301"></a>00301 } <a name="l00302"></a>00302 <a name="l00303"></a>00303 <span class="comment">/* wait for an response*/</span> <a name="l00304"></a>00304 <span class="keywordflow">if</span>(!ldns_sock_wait(sockfd, timeout, 0)) { <a name="l00305"></a>00305 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00306"></a>00306 <span class="preprocessor"></span> close(sockfd); <a name="l00307"></a>00307 <span class="preprocessor">#else</span> <a name="l00308"></a>00308 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00309"></a>00309 <span class="preprocessor">#endif</span> <a name="l00310"></a>00310 <span class="preprocessor"></span> <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa0e6b44ad0292df31d103cab274cf0024">LDNS_STATUS_NETWORK_ERR</a>; <a name="l00311"></a>00311 } <a name="l00312"></a>00312 <a name="l00313"></a>00313 <span class="comment">/* set to nonblocking, so if the checksum is bad, it becomes</span> <a name="l00314"></a>00314 <span class="comment"> * an EGAIN error and the ldns_udp_send function does not block,</span> <a name="l00315"></a>00315 <span class="comment"> * but returns a 'NETWORK_ERROR' much like a timeout. */</span> <a name="l00316"></a>00316 ldns_sock_nonblock(sockfd); <a name="l00317"></a>00317 <a name="l00318"></a>00318 answer = <a class="code" href="net_8c.html#a555370e0ed25b4b254eb26463e52b629" title="Gives back a raw packet from the wire and reads the header data from the given socket.">ldns_udp_read_wire</a>(sockfd, answer_size, NULL, NULL); <a name="l00319"></a>00319 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00320"></a>00320 <span class="preprocessor"></span> close(sockfd); <a name="l00321"></a>00321 <span class="preprocessor">#else</span> <a name="l00322"></a>00322 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00323"></a>00323 <span class="preprocessor">#endif</span> <a name="l00324"></a>00324 <span class="preprocessor"></span> <a name="l00325"></a>00325 <span class="keywordflow">if</span> (*answer_size == 0) { <a name="l00326"></a>00326 <span class="comment">/* oops */</span> <a name="l00327"></a>00327 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa0e6b44ad0292df31d103cab274cf0024">LDNS_STATUS_NETWORK_ERR</a>; <a name="l00328"></a>00328 } <a name="l00329"></a>00329 <a name="l00330"></a>00330 *result = answer; <a name="l00331"></a>00331 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00332"></a>00332 } <a name="l00333"></a>00333 <a name="l00334"></a>00334 <span class="keywordtype">int</span> <a name="l00335"></a><a class="code" href="net_8h.html#a84751182c6fa8f75ff79da83c18c0954">00335</a> <a class="code" href="net_8c.html#a84751182c6fa8f75ff79da83c18c0954" title="Send an udp query and don't wait for an answer but return the socket.">ldns_udp_bgsend</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, socklen_t tolen, <a name="l00336"></a>00336 <span class="keyword">struct</span> timeval timeout) <a name="l00337"></a>00337 { <a name="l00338"></a>00338 <span class="keywordtype">int</span> sockfd; <a name="l00339"></a>00339 <a name="l00340"></a>00340 sockfd = <a class="code" href="net_8c.html#a0f6a8295466fbecd78ae1a601398b15c">ldns_udp_connect</a>(to, timeout); <a name="l00341"></a>00341 <a name="l00342"></a>00342 <span class="keywordflow">if</span> (sockfd == 0) { <a name="l00343"></a>00343 <span class="keywordflow">return</span> 0; <a name="l00344"></a>00344 } <a name="l00345"></a>00345 <a name="l00346"></a>00346 <span class="keywordflow">if</span> (<a class="code" href="net_8c.html#af4cb429eb90f49cab4cb8e61081682c6" title="send a query via udp to a server.">ldns_udp_send_query</a>(qbin, sockfd, to, tolen) == 0) { <a name="l00347"></a>00347 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00348"></a>00348 <span class="preprocessor"></span> close(sockfd); <a name="l00349"></a>00349 <span class="preprocessor">#else</span> <a name="l00350"></a>00350 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00351"></a>00351 <span class="preprocessor">#endif</span> <a name="l00352"></a>00352 <span class="preprocessor"></span> <span class="keywordflow">return</span> 0; <a name="l00353"></a>00353 } <a name="l00354"></a>00354 <span class="keywordflow">return</span> sockfd; <a name="l00355"></a>00355 } <a name="l00356"></a>00356 <a name="l00357"></a>00357 <span class="keywordtype">int</span> <a name="l00358"></a><a class="code" href="net_8c.html#a0f6a8295466fbecd78ae1a601398b15c">00358</a> <a class="code" href="net_8c.html#a0f6a8295466fbecd78ae1a601398b15c">ldns_udp_connect</a>(<span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, <span class="keyword">struct</span> timeval <a class="code" href="common_8h.html#ade436d89899edbffbc53514d440d28b9">ATTR_UNUSED</a>(timeout)) <a name="l00359"></a>00359 { <a name="l00360"></a>00360 <span class="keywordtype">int</span> sockfd; <a name="l00361"></a>00361 <a name="l00362"></a>00362 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00363"></a>00363 <span class="preprocessor"></span> <span class="keywordflow">if</span> ((sockfd = socket((<span class="keywordtype">int</span>)((<span class="keyword">struct</span> sockaddr*)to)->sa_family, SOCK_DGRAM, <a name="l00364"></a>00364 IPPROTO_UDP)) <a name="l00365"></a>00365 == -1) { <a name="l00366"></a>00366 <span class="keywordflow">return</span> 0; <a name="l00367"></a>00367 } <a name="l00368"></a>00368 <span class="preprocessor">#endif</span> <a name="l00369"></a>00369 <span class="preprocessor"></span> <span class="keywordflow">return</span> sockfd; <a name="l00370"></a>00370 } <a name="l00371"></a>00371 <a name="l00372"></a>00372 <span class="keywordtype">int</span> <a name="l00373"></a><a class="code" href="net_8h.html#a734323eed74db2d1db4404a061686a6b">00373</a> <a class="code" href="net_8c.html#a734323eed74db2d1db4404a061686a6b" title="Create a tcp socket to the specified address.">ldns_tcp_connect</a>(<span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, socklen_t tolen, <a name="l00374"></a>00374 <span class="keyword">struct</span> timeval timeout) <a name="l00375"></a>00375 { <a name="l00376"></a>00376 <span class="keywordtype">int</span> sockfd; <a name="l00377"></a>00377 <a name="l00378"></a>00378 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00379"></a>00379 <span class="preprocessor"></span> <span class="keywordflow">if</span> ((sockfd = socket((<span class="keywordtype">int</span>)((<span class="keyword">struct</span> sockaddr*)to)->sa_family, SOCK_STREAM, <a name="l00380"></a>00380 IPPROTO_TCP)) == -1) { <a name="l00381"></a>00381 <span class="keywordflow">return</span> 0; <a name="l00382"></a>00382 } <a name="l00383"></a>00383 <span class="preprocessor">#endif</span> <a name="l00384"></a>00384 <span class="preprocessor"></span> <a name="l00385"></a>00385 <span class="comment">/* perform nonblocking connect, to be able to wait with select() */</span> <a name="l00386"></a>00386 ldns_sock_nonblock(sockfd); <a name="l00387"></a>00387 <span class="keywordflow">if</span> (connect(sockfd, (<span class="keyword">struct</span> sockaddr*)to, tolen) == -1) { <a name="l00388"></a>00388 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00389"></a>00389 <span class="preprocessor"></span><span class="preprocessor">#ifdef EINPROGRESS</span> <a name="l00390"></a>00390 <span class="preprocessor"></span> <span class="keywordflow">if</span>(errno != EINPROGRESS) { <a name="l00391"></a>00391 <span class="preprocessor">#else</span> <a name="l00392"></a>00392 <span class="preprocessor"></span> <span class="keywordflow">if</span>(1) { <a name="l00393"></a>00393 <span class="preprocessor">#endif</span> <a name="l00394"></a>00394 <span class="preprocessor"></span> close(sockfd); <a name="l00395"></a>00395 <span class="keywordflow">return</span> 0; <a name="l00396"></a>00396 } <a name="l00397"></a>00397 <span class="preprocessor">#else </span><span class="comment">/* USE_WINSOCK */</span> <a name="l00398"></a>00398 <span class="keywordflow">if</span>(WSAGetLastError() != WSAEINPROGRESS && <a name="l00399"></a>00399 WSAGetLastError() != WSAEWOULDBLOCK) { <a name="l00400"></a>00400 closesocket(sockfd); <a name="l00401"></a>00401 <span class="keywordflow">return</span> 0; <a name="l00402"></a>00402 } <a name="l00403"></a>00403 <span class="preprocessor">#endif</span> <a name="l00404"></a>00404 <span class="preprocessor"></span> <span class="comment">/* error was only telling us that it would block */</span> <a name="l00405"></a>00405 } <a name="l00406"></a>00406 <a name="l00407"></a>00407 <span class="comment">/* wait(write) until connected or error */</span> <a name="l00408"></a>00408 <span class="keywordflow">while</span>(1) { <a name="l00409"></a>00409 <span class="keywordtype">int</span> error = 0; <a name="l00410"></a>00410 socklen_t len = (socklen_t)<span class="keyword">sizeof</span>(error); <a name="l00411"></a>00411 <a name="l00412"></a>00412 <span class="keywordflow">if</span>(!ldns_sock_wait(sockfd, timeout, 1)) { <a name="l00413"></a>00413 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00414"></a>00414 <span class="preprocessor"></span> close(sockfd); <a name="l00415"></a>00415 <span class="preprocessor">#else</span> <a name="l00416"></a>00416 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00417"></a>00417 <span class="preprocessor">#endif</span> <a name="l00418"></a>00418 <span class="preprocessor"></span> <span class="keywordflow">return</span> 0; <a name="l00419"></a>00419 } <a name="l00420"></a>00420 <a name="l00421"></a>00421 <span class="comment">/* check if there is a pending error for nonblocking connect */</span> <a name="l00422"></a>00422 <span class="keywordflow">if</span>(getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (<span class="keywordtype">void</span>*)&error, <a name="l00423"></a>00423 &len) < 0) { <a name="l00424"></a>00424 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00425"></a>00425 <span class="preprocessor"></span> error = errno; <span class="comment">/* on solaris errno is error */</span> <a name="l00426"></a>00426 <span class="preprocessor">#else</span> <a name="l00427"></a>00427 <span class="preprocessor"></span> error = WSAGetLastError(); <a name="l00428"></a>00428 <span class="preprocessor">#endif</span> <a name="l00429"></a>00429 <span class="preprocessor"></span> } <a name="l00430"></a>00430 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00431"></a>00431 <span class="preprocessor"></span><span class="preprocessor">#if defined(EINPROGRESS) && defined(EWOULDBLOCK)</span> <a name="l00432"></a>00432 <span class="preprocessor"></span> <span class="keywordflow">if</span>(error == EINPROGRESS || error == EWOULDBLOCK) <a name="l00433"></a>00433 <span class="keywordflow">continue</span>; <span class="comment">/* try again */</span> <a name="l00434"></a>00434 <span class="preprocessor">#endif</span> <a name="l00435"></a>00435 <span class="preprocessor"></span> <span class="keywordflow">else</span> <span class="keywordflow">if</span>(error != 0) { <a name="l00436"></a>00436 close(sockfd); <a name="l00437"></a>00437 <span class="comment">/* error in errno for our user */</span> <a name="l00438"></a>00438 errno = error; <a name="l00439"></a>00439 <span class="keywordflow">return</span> 0; <a name="l00440"></a>00440 } <a name="l00441"></a>00441 <span class="preprocessor">#else </span><span class="comment">/* USE_WINSOCK */</span> <a name="l00442"></a>00442 <span class="keywordflow">if</span>(error == WSAEINPROGRESS) <a name="l00443"></a>00443 <span class="keywordflow">continue</span>; <a name="l00444"></a>00444 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(error == WSAEWOULDBLOCK) <a name="l00445"></a>00445 <span class="keywordflow">continue</span>; <a name="l00446"></a>00446 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(error != 0) { <a name="l00447"></a>00447 closesocket(sockfd); <a name="l00448"></a>00448 errno = error; <a name="l00449"></a>00449 <span class="keywordflow">return</span> 0; <a name="l00450"></a>00450 } <a name="l00451"></a>00451 <span class="preprocessor">#endif </span><span class="comment">/* USE_WINSOCK */</span> <a name="l00452"></a>00452 <span class="comment">/* connected */</span> <a name="l00453"></a>00453 <span class="keywordflow">break</span>; <a name="l00454"></a>00454 } <a name="l00455"></a>00455 <a name="l00456"></a>00456 <span class="comment">/* set the socket blocking again */</span> <a name="l00457"></a>00457 ldns_sock_block(sockfd); <a name="l00458"></a>00458 <a name="l00459"></a>00459 <span class="keywordflow">return</span> sockfd; <a name="l00460"></a>00460 } <a name="l00461"></a>00461 <a name="l00462"></a>00462 ssize_t <a name="l00463"></a><a class="code" href="net_8h.html#a690205442102fe4b606b5679241fce04">00463</a> <a class="code" href="net_8c.html#a690205442102fe4b606b5679241fce04" title="send a query via tcp to a server.">ldns_tcp_send_query</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keywordtype">int</span> sockfd, <a name="l00464"></a>00464 <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, socklen_t tolen) <a name="l00465"></a>00465 { <a name="l00466"></a>00466 uint8_t *sendbuf; <a name="l00467"></a>00467 ssize_t bytes; <a name="l00468"></a>00468 <a name="l00469"></a>00469 <span class="comment">/* add length of packet */</span> <a name="l00470"></a>00470 sendbuf = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, ldns_buffer_position(qbin) + 2); <a name="l00471"></a>00471 <span class="keywordflow">if</span>(!sendbuf) <span class="keywordflow">return</span> 0; <a name="l00472"></a>00472 ldns_write_uint16(sendbuf, ldns_buffer_position(qbin)); <a name="l00473"></a>00473 memcpy(sendbuf + 2, <a class="code" href="buffer_8c.html#aedc3ca34290f5faad3cca548bb7125ab" title="Makes the buffer fixed and returns a pointer to the data.">ldns_buffer_export</a>(qbin), ldns_buffer_position(qbin)); <a name="l00474"></a>00474 <a name="l00475"></a>00475 bytes = sendto(sockfd, (<span class="keywordtype">void</span>*)sendbuf, <a name="l00476"></a>00476 ldns_buffer_position(qbin) + 2, 0, (<span class="keyword">struct</span> sockaddr *)to, tolen); <a name="l00477"></a>00477 <a name="l00478"></a>00478 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(sendbuf); <a name="l00479"></a>00479 <a name="l00480"></a>00480 <span class="keywordflow">if</span> (bytes == -1 || (<span class="keywordtype">size_t</span>) bytes != ldns_buffer_position(qbin) + 2 ) { <a name="l00481"></a>00481 <span class="keywordflow">return</span> 0; <a name="l00482"></a>00482 } <a name="l00483"></a>00483 <span class="keywordflow">return</span> bytes; <a name="l00484"></a>00484 } <a name="l00485"></a>00485 <a name="l00486"></a>00486 <span class="comment">/* don't wait for an answer */</span> <a name="l00487"></a>00487 ssize_t <a name="l00488"></a><a class="code" href="net_8h.html#af4cb429eb90f49cab4cb8e61081682c6">00488</a> <a class="code" href="net_8c.html#af4cb429eb90f49cab4cb8e61081682c6" title="send a query via udp to a server.">ldns_udp_send_query</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keywordtype">int</span> sockfd, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, <a name="l00489"></a>00489 socklen_t tolen) <a name="l00490"></a>00490 { <a name="l00491"></a>00491 ssize_t bytes; <a name="l00492"></a>00492 <a name="l00493"></a>00493 bytes = sendto(sockfd, (<span class="keywordtype">void</span>*)ldns_buffer_begin(qbin), <a name="l00494"></a>00494 ldns_buffer_position(qbin), 0, (<span class="keyword">struct</span> sockaddr *)to, tolen); <a name="l00495"></a>00495 <a name="l00496"></a>00496 <span class="keywordflow">if</span> (bytes == -1 || (<span class="keywordtype">size_t</span>)bytes != ldns_buffer_position(qbin)) { <a name="l00497"></a>00497 <span class="keywordflow">return</span> 0; <a name="l00498"></a>00498 } <a name="l00499"></a>00499 <span class="keywordflow">if</span> ((<span class="keywordtype">size_t</span>) bytes != ldns_buffer_position(qbin)) { <a name="l00500"></a>00500 <span class="keywordflow">return</span> 0; <a name="l00501"></a>00501 } <a name="l00502"></a>00502 <span class="keywordflow">return</span> bytes; <a name="l00503"></a>00503 } <a name="l00504"></a>00504 <a name="l00505"></a>00505 uint8_t * <a name="l00506"></a><a class="code" href="net_8h.html#aafca8bce8ea9febd9797c8dbb3931fbb">00506</a> <a class="code" href="net_8c.html#a555370e0ed25b4b254eb26463e52b629" title="Gives back a raw packet from the wire and reads the header data from the given socket.">ldns_udp_read_wire</a>(<span class="keywordtype">int</span> sockfd, <span class="keywordtype">size_t</span> *size, <span class="keyword">struct</span> sockaddr_storage *from, <a name="l00507"></a>00507 socklen_t *fromlen) <a name="l00508"></a>00508 { <a name="l00509"></a>00509 uint8_t *wire, *wireout; <a name="l00510"></a>00510 ssize_t wire_size; <a name="l00511"></a>00511 <a name="l00512"></a>00512 wire = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, <a class="code" href="packet_8h.html#a0335fad1ab5f49839cd6c5a71e3d721b">LDNS_MAX_PACKETLEN</a>); <a name="l00513"></a>00513 <span class="keywordflow">if</span> (!wire) { <a name="l00514"></a>00514 *size = 0; <a name="l00515"></a>00515 <span class="keywordflow">return</span> NULL; <a name="l00516"></a>00516 } <a name="l00517"></a>00517 <a name="l00518"></a>00518 wire_size = recvfrom(sockfd, (<span class="keywordtype">void</span>*)wire, <a class="code" href="packet_8h.html#a0335fad1ab5f49839cd6c5a71e3d721b">LDNS_MAX_PACKETLEN</a>, 0, <a name="l00519"></a>00519 (<span class="keyword">struct</span> sockaddr *)from, fromlen); <a name="l00520"></a>00520 <a name="l00521"></a>00521 <span class="comment">/* recvfrom can also return 0 */</span> <a name="l00522"></a>00522 <span class="keywordflow">if</span> (wire_size == -1 || wire_size == 0) { <a name="l00523"></a>00523 *size = 0; <a name="l00524"></a>00524 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00525"></a>00525 <span class="keywordflow">return</span> NULL; <a name="l00526"></a>00526 } <a name="l00527"></a>00527 <a name="l00528"></a>00528 *size = (size_t)wire_size; <a name="l00529"></a>00529 wireout = <a class="code" href="util_8h.html#aef91214266c90875fa06e4a47e734538">LDNS_XREALLOC</a>(wire, uint8_t, (<span class="keywordtype">size_t</span>)wire_size); <a name="l00530"></a>00530 <span class="keywordflow">if</span>(!wireout) <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00531"></a>00531 <a name="l00532"></a>00532 <span class="keywordflow">return</span> wireout; <a name="l00533"></a>00533 } <a name="l00534"></a>00534 <a name="l00535"></a>00535 uint8_t * <a name="l00536"></a><a class="code" href="net_8h.html#a0ec64fcdbe349ca15283fee443d06737">00536</a> <a class="code" href="net_8c.html#a0ec64fcdbe349ca15283fee443d06737" title="Gives back a raw packet from the wire and reads the header data from the given socket.">ldns_tcp_read_wire_timeout</a>(<span class="keywordtype">int</span> sockfd, <span class="keywordtype">size_t</span> *size, <span class="keyword">struct</span> timeval timeout) <a name="l00537"></a>00537 { <a name="l00538"></a>00538 uint8_t *wire; <a name="l00539"></a>00539 uint16_t wire_size; <a name="l00540"></a>00540 ssize_t bytes = 0, rc = 0; <a name="l00541"></a>00541 <a name="l00542"></a>00542 wire = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, 2); <a name="l00543"></a>00543 <span class="keywordflow">if</span> (!wire) { <a name="l00544"></a>00544 *size = 0; <a name="l00545"></a>00545 <span class="keywordflow">return</span> NULL; <a name="l00546"></a>00546 } <a name="l00547"></a>00547 <a name="l00548"></a>00548 <span class="keywordflow">while</span> (bytes < 2) { <a name="l00549"></a>00549 <span class="keywordflow">if</span>(!ldns_sock_wait(sockfd, timeout, 0)) { <a name="l00550"></a>00550 *size = 0; <a name="l00551"></a>00551 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00552"></a>00552 <span class="keywordflow">return</span> NULL; <a name="l00553"></a>00553 } <a name="l00554"></a>00554 rc = recv(sockfd, (<span class="keywordtype">void</span>*) (wire + bytes), <a name="l00555"></a>00555 (<span class="keywordtype">size_t</span>) (2 - bytes), 0); <a name="l00556"></a>00556 <span class="keywordflow">if</span> (rc == -1 || rc == 0) { <a name="l00557"></a>00557 *size = 0; <a name="l00558"></a>00558 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00559"></a>00559 <span class="keywordflow">return</span> NULL; <a name="l00560"></a>00560 } <a name="l00561"></a>00561 bytes += rc; <a name="l00562"></a>00562 } <a name="l00563"></a>00563 <a name="l00564"></a>00564 wire_size = ldns_read_uint16(wire); <a name="l00565"></a>00565 <a name="l00566"></a>00566 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00567"></a>00567 wire = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, wire_size); <a name="l00568"></a>00568 <span class="keywordflow">if</span> (!wire) { <a name="l00569"></a>00569 *size = 0; <a name="l00570"></a>00570 <span class="keywordflow">return</span> NULL; <a name="l00571"></a>00571 } <a name="l00572"></a>00572 bytes = 0; <a name="l00573"></a>00573 <a name="l00574"></a>00574 <span class="keywordflow">while</span> (bytes < (ssize_t) wire_size) { <a name="l00575"></a>00575 <span class="keywordflow">if</span>(!ldns_sock_wait(sockfd, timeout, 0)) { <a name="l00576"></a>00576 *size = 0; <a name="l00577"></a>00577 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00578"></a>00578 <span class="keywordflow">return</span> NULL; <a name="l00579"></a>00579 } <a name="l00580"></a>00580 rc = recv(sockfd, (<span class="keywordtype">void</span>*) (wire + bytes), <a name="l00581"></a>00581 (<span class="keywordtype">size_t</span>) (wire_size - bytes), 0); <a name="l00582"></a>00582 <span class="keywordflow">if</span> (rc == -1 || rc == 0) { <a name="l00583"></a>00583 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00584"></a>00584 *size = 0; <a name="l00585"></a>00585 <span class="keywordflow">return</span> NULL; <a name="l00586"></a>00586 } <a name="l00587"></a>00587 bytes += rc; <a name="l00588"></a>00588 } <a name="l00589"></a>00589 <a name="l00590"></a>00590 *size = (size_t) bytes; <a name="l00591"></a>00591 <span class="keywordflow">return</span> wire; <a name="l00592"></a>00592 } <a name="l00593"></a>00593 <a name="l00594"></a>00594 uint8_t * <a name="l00595"></a><a class="code" href="net_8h.html#a3f7bd944f2cb1ea28bd8dd056c16e07d">00595</a> <a class="code" href="net_8c.html#a3f7bd944f2cb1ea28bd8dd056c16e07d" title="This routine may block.">ldns_tcp_read_wire</a>(<span class="keywordtype">int</span> sockfd, <span class="keywordtype">size_t</span> *size) <a name="l00596"></a>00596 { <a name="l00597"></a>00597 uint8_t *wire; <a name="l00598"></a>00598 uint16_t wire_size; <a name="l00599"></a>00599 ssize_t bytes = 0, rc = 0; <a name="l00600"></a>00600 <a name="l00601"></a>00601 wire = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, 2); <a name="l00602"></a>00602 <span class="keywordflow">if</span> (!wire) { <a name="l00603"></a>00603 *size = 0; <a name="l00604"></a>00604 <span class="keywordflow">return</span> NULL; <a name="l00605"></a>00605 } <a name="l00606"></a>00606 <a name="l00607"></a>00607 <span class="keywordflow">while</span> (bytes < 2) { <a name="l00608"></a>00608 rc = recv(sockfd, (<span class="keywordtype">void</span>*) (wire + bytes), <a name="l00609"></a>00609 (<span class="keywordtype">size_t</span>) (2 - bytes), 0); <a name="l00610"></a>00610 <span class="keywordflow">if</span> (rc == -1 || rc == 0) { <a name="l00611"></a>00611 *size = 0; <a name="l00612"></a>00612 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00613"></a>00613 <span class="keywordflow">return</span> NULL; <a name="l00614"></a>00614 } <a name="l00615"></a>00615 bytes += rc; <a name="l00616"></a>00616 } <a name="l00617"></a>00617 <a name="l00618"></a>00618 wire_size = ldns_read_uint16(wire); <a name="l00619"></a>00619 <a name="l00620"></a>00620 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00621"></a>00621 wire = <a class="code" href="util_8h.html#aaad6949daea3c6cefd01d19300f6e21a">LDNS_XMALLOC</a>(uint8_t, wire_size); <a name="l00622"></a>00622 <span class="keywordflow">if</span> (!wire) { <a name="l00623"></a>00623 *size = 0; <a name="l00624"></a>00624 <span class="keywordflow">return</span> NULL; <a name="l00625"></a>00625 } <a name="l00626"></a>00626 bytes = 0; <a name="l00627"></a>00627 <a name="l00628"></a>00628 <span class="keywordflow">while</span> (bytes < (ssize_t) wire_size) { <a name="l00629"></a>00629 rc = recv(sockfd, (<span class="keywordtype">void</span>*) (wire + bytes), <a name="l00630"></a>00630 (<span class="keywordtype">size_t</span>) (wire_size - bytes), 0); <a name="l00631"></a>00631 <span class="keywordflow">if</span> (rc == -1 || rc == 0) { <a name="l00632"></a>00632 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(wire); <a name="l00633"></a>00633 *size = 0; <a name="l00634"></a>00634 <span class="keywordflow">return</span> NULL; <a name="l00635"></a>00635 } <a name="l00636"></a>00636 bytes += rc; <a name="l00637"></a>00637 } <a name="l00638"></a>00638 <a name="l00639"></a>00639 *size = (size_t) bytes; <a name="l00640"></a>00640 <span class="keywordflow">return</span> wire; <a name="l00641"></a>00641 } <a name="l00642"></a>00642 <a name="l00643"></a>00643 <span class="comment">/* keep in mind that in DNS tcp messages the first 2 bytes signal the</span> <a name="l00644"></a>00644 <span class="comment"> * amount data to expect</span> <a name="l00645"></a>00645 <span class="comment"> */</span> <a name="l00646"></a>00646 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00647"></a><a class="code" href="net_8h.html#a8eef624207f9e36c10f0805b46b80e62">00647</a> <a class="code" href="net_8c.html#add29437506d01b49c5d2d84cd0589999" title="Sends a buffer to an ip using tcp and return the respons as a ldns_pkt.">ldns_tcp_send</a>(uint8_t **result, <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, <a name="l00648"></a>00648 socklen_t tolen, <span class="keyword">struct</span> timeval timeout, <span class="keywordtype">size_t</span> *answer_size) <a name="l00649"></a>00649 { <a name="l00650"></a>00650 <span class="keywordtype">int</span> sockfd; <a name="l00651"></a>00651 uint8_t *answer; <a name="l00652"></a>00652 <a name="l00653"></a>00653 sockfd = <a class="code" href="net_8c.html#a8c4de333a55065818703c26c4464ba70" title="Send an tcp query and don't wait for an answer but return the socket.">ldns_tcp_bgsend</a>(qbin, to, tolen, timeout); <a name="l00654"></a>00654 <a name="l00655"></a>00655 <span class="keywordflow">if</span> (sockfd == 0) { <a name="l00656"></a>00656 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa804a996d5f13cda0806bf1d54114d2ca">LDNS_STATUS_ERR</a>; <a name="l00657"></a>00657 } <a name="l00658"></a>00658 <a name="l00659"></a>00659 answer = <a class="code" href="net_8c.html#a0ec64fcdbe349ca15283fee443d06737" title="Gives back a raw packet from the wire and reads the header data from the given socket.">ldns_tcp_read_wire_timeout</a>(sockfd, answer_size, timeout); <a name="l00660"></a>00660 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00661"></a>00661 <span class="preprocessor"></span> close(sockfd); <a name="l00662"></a>00662 <span class="preprocessor">#else</span> <a name="l00663"></a>00663 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00664"></a>00664 <span class="preprocessor">#endif</span> <a name="l00665"></a>00665 <span class="preprocessor"></span> <a name="l00666"></a>00666 <span class="keywordflow">if</span> (*answer_size == 0) { <a name="l00667"></a>00667 <span class="comment">/* oops */</span> <a name="l00668"></a>00668 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa0e6b44ad0292df31d103cab274cf0024">LDNS_STATUS_NETWORK_ERR</a>; <a name="l00669"></a>00669 } <a name="l00670"></a>00670 <a name="l00671"></a>00671 <span class="comment">/* resize accordingly */</span> <a name="l00672"></a>00672 *result = (uint8_t*)<a class="code" href="util_8h.html#aef91214266c90875fa06e4a47e734538">LDNS_XREALLOC</a>(answer, uint8_t *, (<span class="keywordtype">size_t</span>)*answer_size); <a name="l00673"></a>00673 <span class="keywordflow">if</span>(!*result) { <a name="l00674"></a>00674 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(answer); <a name="l00675"></a>00675 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa81e80e66a14551db514726fa49290498">LDNS_STATUS_MEM_ERR</a>; <a name="l00676"></a>00676 } <a name="l00677"></a>00677 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00678"></a>00678 } <a name="l00679"></a>00679 <a name="l00680"></a>00680 <span class="keywordtype">int</span> <a name="l00681"></a><a class="code" href="net_8h.html#a8c4de333a55065818703c26c4464ba70">00681</a> <a class="code" href="net_8c.html#a8c4de333a55065818703c26c4464ba70" title="Send an tcp query and don't wait for an answer but return the socket.">ldns_tcp_bgsend</a>(<a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *qbin, <span class="keyword">const</span> <span class="keyword">struct</span> sockaddr_storage *to, socklen_t tolen, <a name="l00682"></a>00682 <span class="keyword">struct</span> timeval timeout) <a name="l00683"></a>00683 { <a name="l00684"></a>00684 <span class="keywordtype">int</span> sockfd; <a name="l00685"></a>00685 <a name="l00686"></a>00686 sockfd = <a class="code" href="net_8c.html#a734323eed74db2d1db4404a061686a6b" title="Create a tcp socket to the specified address.">ldns_tcp_connect</a>(to, tolen, timeout); <a name="l00687"></a>00687 <a name="l00688"></a>00688 <span class="keywordflow">if</span> (sockfd == 0) { <a name="l00689"></a>00689 <span class="keywordflow">return</span> 0; <a name="l00690"></a>00690 } <a name="l00691"></a>00691 <a name="l00692"></a>00692 <span class="keywordflow">if</span> (<a class="code" href="net_8c.html#a690205442102fe4b606b5679241fce04" title="send a query via tcp to a server.">ldns_tcp_send_query</a>(qbin, sockfd, to, tolen) == 0) { <a name="l00693"></a>00693 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00694"></a>00694 <span class="preprocessor"></span> close(sockfd); <a name="l00695"></a>00695 <span class="preprocessor">#else</span> <a name="l00696"></a>00696 <span class="preprocessor"></span> closesocket(sockfd); <a name="l00697"></a>00697 <span class="preprocessor">#endif</span> <a name="l00698"></a>00698 <span class="preprocessor"></span> <span class="keywordflow">return</span> 0; <a name="l00699"></a>00699 } <a name="l00700"></a>00700 <a name="l00701"></a>00701 <span class="keywordflow">return</span> sockfd; <a name="l00702"></a>00702 } <a name="l00703"></a>00703 <a name="l00704"></a>00704 <span class="comment">/* code from rdata.c */</span> <a name="l00705"></a>00705 <span class="keyword">struct </span>sockaddr_storage * <a name="l00706"></a><a class="code" href="net_8h.html#a897b9376491b14bb57cdda6e6511464f">00706</a> <a class="code" href="net_8c.html#a897b9376491b14bb57cdda6e6511464f" title="returns the native sockaddr representation from the rdf.">ldns_rdf2native_sockaddr_storage</a>(<span class="keyword">const</span> <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *rd, uint16_t port, <span class="keywordtype">size_t</span> *size) <a name="l00707"></a>00707 { <a name="l00708"></a>00708 <span class="keyword">struct </span>sockaddr_storage *data; <a name="l00709"></a>00709 <span class="keyword">struct </span>sockaddr_in *data_in; <a name="l00710"></a>00710 <span class="keyword">struct </span>sockaddr_in6 *data_in6; <a name="l00711"></a>00711 <a name="l00712"></a>00712 data = <a class="code" href="util_8h.html#a828619b138fdeb9756cd3c874d0551c1" title="Memory management macros.">LDNS_MALLOC</a>(<span class="keyword">struct</span> sockaddr_storage); <a name="l00713"></a>00713 <span class="keywordflow">if</span> (!data) { <a name="l00714"></a>00714 <span class="keywordflow">return</span> NULL; <a name="l00715"></a>00715 } <a name="l00716"></a>00716 <span class="comment">/* zero the structure for portability */</span> <a name="l00717"></a>00717 memset(data, 0, <span class="keyword">sizeof</span>(<span class="keyword">struct</span> sockaddr_storage)); <a name="l00718"></a>00718 <span class="keywordflow">if</span> (port == 0) { <a name="l00719"></a>00719 port = <a class="code" href="ldns_8h.html#af09fdea9d1f2f008a650be45ac3332c7">LDNS_PORT</a>; <a name="l00720"></a>00720 } <a name="l00721"></a>00721 <a name="l00722"></a>00722 <span class="keywordflow">switch</span>(<a class="code" href="rdata_8c.html#a240f7f36c145f6189df4f14ca5bc3a82" title="returns the type of the rdf.">ldns_rdf_get_type</a>(rd)) { <a name="l00723"></a>00723 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a8ab64a730a4d6b7a717e6a3dbdc6123d" title="A record.">LDNS_RDF_TYPE_A</a>: <a name="l00724"></a>00724 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00725"></a>00725 <span class="preprocessor"></span> data->ss_family = AF_INET; <a name="l00726"></a>00726 <span class="preprocessor">#endif</span> <a name="l00727"></a>00727 <span class="preprocessor"></span> data_in = (<span class="keyword">struct </span>sockaddr_in*) data; <a name="l00728"></a>00728 data_in->sin_port = (in_port_t)htons(port); <a name="l00729"></a>00729 memcpy(&(data_in->sin_addr), <a class="code" href="rdata_8c.html#adc126e8f5417a3c1049242f93fde3602" title="returns the data of the rdf.">ldns_rdf_data</a>(rd), <a class="code" href="rdata_8c.html#acccb19af8b71b0c8d341d17946b46e8b" title="returns the size of the rdf.">ldns_rdf_size</a>(rd)); <a name="l00730"></a>00730 *size = <span class="keyword">sizeof</span>(<span class="keyword">struct </span>sockaddr_in); <a name="l00731"></a>00731 <span class="keywordflow">return</span> data; <a name="l00732"></a>00732 <span class="keywordflow">case</span> <a class="code" href="rdata_8h.html#aaa92376014f0abbf0110ca6efd587bb9a5959b86d3aacff828167e6dca5a935fd" title="AAAA record.">LDNS_RDF_TYPE_AAAA</a>: <a name="l00733"></a>00733 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00734"></a>00734 <span class="preprocessor"></span> data->ss_family = AF_INET6; <a name="l00735"></a>00735 <span class="preprocessor">#endif</span> <a name="l00736"></a>00736 <span class="preprocessor"></span> data_in6 = (<span class="keyword">struct </span>sockaddr_in6*) data; <a name="l00737"></a>00737 data_in6->sin6_port = (in_port_t)htons(port); <a name="l00738"></a>00738 memcpy(&data_in6->sin6_addr, <a class="code" href="rdata_8c.html#adc126e8f5417a3c1049242f93fde3602" title="returns the data of the rdf.">ldns_rdf_data</a>(rd), <a class="code" href="rdata_8c.html#acccb19af8b71b0c8d341d17946b46e8b" title="returns the size of the rdf.">ldns_rdf_size</a>(rd)); <a name="l00739"></a>00739 *size = <span class="keyword">sizeof</span>(<span class="keyword">struct </span>sockaddr_in6); <a name="l00740"></a>00740 <span class="keywordflow">return</span> data; <a name="l00741"></a>00741 <span class="keywordflow">default</span>: <a name="l00742"></a>00742 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(data); <a name="l00743"></a>00743 <span class="keywordflow">return</span> NULL; <a name="l00744"></a>00744 } <a name="l00745"></a>00745 } <a name="l00746"></a>00746 <a name="l00747"></a>00747 <span class="preprocessor">#ifndef S_SPLINT_S</span> <a name="l00748"></a>00748 <span class="preprocessor"></span><a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> * <a name="l00749"></a><a class="code" href="net_8h.html#a88f2c363ffaec397410555b4f2fb9668">00749</a> <a class="code" href="net_8c.html#a88f2c363ffaec397410555b4f2fb9668" title="returns an rdf with the sockaddr info.">ldns_sockaddr_storage2rdf</a>(<span class="keyword">struct</span> sockaddr_storage *sock, uint16_t *port) <a name="l00750"></a>00750 { <a name="l00751"></a>00751 <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *addr; <a name="l00752"></a>00752 <span class="keyword">struct </span>sockaddr_in *data_in; <a name="l00753"></a>00753 <span class="keyword">struct </span>sockaddr_in6 *data_in6; <a name="l00754"></a>00754 <a name="l00755"></a>00755 <span class="keywordflow">switch</span>(sock->ss_family) { <a name="l00756"></a>00756 <span class="keywordflow">case</span> AF_INET: <a name="l00757"></a>00757 data_in = (<span class="keyword">struct </span>sockaddr_in*)sock; <a name="l00758"></a>00758 <span class="keywordflow">if</span> (port) { <a name="l00759"></a>00759 *port = ntohs((uint16_t)data_in->sin_port); <a name="l00760"></a>00760 } <a name="l00761"></a>00761 addr = <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#aaa92376014f0abbf0110ca6efd587bb9a8ab64a730a4d6b7a717e6a3dbdc6123d" title="A record.">LDNS_RDF_TYPE_A</a>, <a name="l00762"></a>00762 <a class="code" href="ldns_8h.html#acb7ea70554416f9777e65f1b229af901">LDNS_IP4ADDRLEN</a>, &data_in->sin_addr); <a name="l00763"></a>00763 <span class="keywordflow">break</span>; <a name="l00764"></a>00764 <span class="keywordflow">case</span> AF_INET6: <a name="l00765"></a>00765 data_in6 = (<span class="keyword">struct </span>sockaddr_in6*)sock; <a name="l00766"></a>00766 <span class="keywordflow">if</span> (port) { <a name="l00767"></a>00767 *port = ntohs((uint16_t)data_in6->sin6_port); <a name="l00768"></a>00768 } <a name="l00769"></a>00769 addr = <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#aaa92376014f0abbf0110ca6efd587bb9a5959b86d3aacff828167e6dca5a935fd" title="AAAA record.">LDNS_RDF_TYPE_AAAA</a>, <a name="l00770"></a>00770 <a class="code" href="ldns_8h.html#acf0d0da09570eb66d348db9a14f62e75">LDNS_IP6ADDRLEN</a>, &data_in6->sin6_addr); <a name="l00771"></a>00771 <span class="keywordflow">break</span>; <a name="l00772"></a>00772 <span class="keywordflow">default</span>: <a name="l00773"></a>00773 <span class="keywordflow">if</span> (port) { <a name="l00774"></a>00774 *port = 0; <a name="l00775"></a>00775 } <a name="l00776"></a>00776 <span class="keywordflow">return</span> NULL; <a name="l00777"></a>00777 } <a name="l00778"></a>00778 <span class="keywordflow">return</span> addr; <a name="l00779"></a>00779 } <a name="l00780"></a>00780 <span class="preprocessor">#endif</span> <a name="l00781"></a>00781 <span class="preprocessor"></span> <a name="l00782"></a>00782 <span class="comment">/* code from resolver.c */</span> <a name="l00783"></a>00783 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> <a name="l00784"></a><a class="code" href="net_8h.html#a31ceb08c8123dbac5c02cab63502ceb4">00784</a> <a class="code" href="net_8c.html#a28efbc4d7b37d8e25db8d524e0ae1a54" title="Prepares the resolver for an axfr query The query is sent and the answers can be read with ldns_axfr_...">ldns_axfr_start</a>(<a class="code" href="structldns__struct__resolver.html" title="DNS stub resolver structure.">ldns_resolver</a> *resolver, <a class="code" href="structldns__struct__rdf.html" title="Resource record data field.">ldns_rdf</a> *domain, <a class="code" href="rr_8h.html#aa11e99c7e7c630e03373f2a2cafc4ee9">ldns_rr_class</a> <span class="keyword">class</span>) <a name="l00785"></a>00785 { <a name="l00786"></a>00786 <a class="code" href="structldns__struct__pkt.html" title="DNS packet.">ldns_pkt</a> *query; <a name="l00787"></a>00787 <a class="code" href="structldns__struct__buffer.html" title="implementation of buffers to ease operations">ldns_buffer</a> *query_wire; <a name="l00788"></a>00788 <a name="l00789"></a>00789 <span class="keyword">struct </span>sockaddr_storage *ns = NULL; <a name="l00790"></a>00790 <span class="keywordtype">size_t</span> ns_len = 0; <a name="l00791"></a>00791 <span class="keywordtype">size_t</span> ns_i; <a name="l00792"></a>00792 <a class="code" href="error_8h.html#aaa6d98f86f535cf87b83b89e91f488f9">ldns_status</a> status; <a name="l00793"></a>00793 <a name="l00794"></a>00794 <span class="keywordflow">if</span> (!resolver || <a class="code" href="resolver_8c.html#a64e6087bcfc88459e34da80077bad7eb" title="How many nameserver are configured in the resolver.">ldns_resolver_nameserver_count</a>(resolver) < 1) { <a name="l00795"></a>00795 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa804a996d5f13cda0806bf1d54114d2ca">LDNS_STATUS_ERR</a>; <a name="l00796"></a>00796 } <a name="l00797"></a>00797 <a name="l00798"></a>00798 query = <a class="code" href="packet_8c.html#af7eee9c15b0f645d5b5855ef15c4596c" title="creates a packet with a query in it for the given name, type and class.">ldns_pkt_query_new</a>(<a class="code" href="rdata_8c.html#af9a39f2f8b749efa6a20ba91cb696961" title="clones a rdf structure.">ldns_rdf_clone</a>(domain), <a class="code" href="rr_8h.html#a640100112b0009efe3d61bbf799b33daaac2bbbc7ed35b0a360ced7cc8a833a5b">LDNS_RR_TYPE_AXFR</a>, <span class="keyword">class</span>, 0); <a name="l00799"></a>00799 <a name="l00800"></a>00800 <span class="keywordflow">if</span> (!query) { <a name="l00801"></a>00801 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afaae9d2b2c6c46e88d6e9ab7c9435a3b37">LDNS_STATUS_ADDRESS_ERR</a>; <a name="l00802"></a>00802 } <a name="l00803"></a>00803 <span class="comment">/* For AXFR, we have to make the connection ourselves */</span> <a name="l00804"></a>00804 <span class="comment">/* try all nameservers (which usually would mean v4 fallback if</span> <a name="l00805"></a>00805 <span class="comment"> * @hostname is used */</span> <a name="l00806"></a>00806 <span class="keywordflow">for</span> (ns_i = 0; <a name="l00807"></a>00807 ns_i < <a class="code" href="resolver_8c.html#a64e6087bcfc88459e34da80077bad7eb" title="How many nameserver are configured in the resolver.">ldns_resolver_nameserver_count</a>(resolver) && <a name="l00808"></a>00808 resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> == 0; <a name="l00809"></a>00809 ns_i++) { <a name="l00810"></a>00810 ns = <a class="code" href="net_8c.html#a897b9376491b14bb57cdda6e6511464f" title="returns the native sockaddr representation from the rdf.">ldns_rdf2native_sockaddr_storage</a>( <a name="l00811"></a>00811 resolver-><a class="code" href="structldns__struct__resolver.html#a8988cc24d2a4bb3b7fa98394047a6524" title="Array of nameservers to query (IP addresses or dnames)">_nameservers</a>[ns_i], <a name="l00812"></a>00812 <a class="code" href="resolver_8c.html#ae8062e9bb7436dc91717915686f28a60" title="Get the port the resolver should use.">ldns_resolver_port</a>(resolver), &ns_len); <a name="l00813"></a>00813 <a name="l00814"></a>00814 resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> = <a class="code" href="net_8c.html#a734323eed74db2d1db4404a061686a6b" title="Create a tcp socket to the specified address.">ldns_tcp_connect</a>(ns, (socklen_t)ns_len, <a name="l00815"></a>00815 <a class="code" href="resolver_8c.html#a9958f4244f667c71f069524eb0720f5c" title="What is the timeout on socket connections.">ldns_resolver_timeout</a>(resolver)); <a name="l00816"></a>00816 } <a name="l00817"></a>00817 <a name="l00818"></a>00818 <span class="keywordflow">if</span> (resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> == 0) { <a name="l00819"></a>00819 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(query); <a name="l00820"></a>00820 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00821"></a>00821 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa0e6b44ad0292df31d103cab274cf0024">LDNS_STATUS_NETWORK_ERR</a>; <a name="l00822"></a>00822 } <a name="l00823"></a>00823 <a name="l00824"></a>00824 <span class="preprocessor">#ifdef HAVE_SSL</span> <a name="l00825"></a>00825 <span class="preprocessor"></span> <span class="keywordflow">if</span> (<a class="code" href="resolver_8c.html#a262ac7450159c115060ec464a4a5af6e" title="Return the tsig keyname as used by the nameserver.">ldns_resolver_tsig_keyname</a>(resolver) && <a class="code" href="resolver_8c.html#abc7e0d0e3960348f774164d34af3013b" title="Return the tsig keydata as used by the nameserver.">ldns_resolver_tsig_keydata</a>(resolver)) { <a name="l00826"></a>00826 status = <a class="code" href="tsig_8c.html#a77501f37821c68328382bccdca956805" title="creates a tsig rr for the given packet and key.">ldns_pkt_tsig_sign</a>(query, <a name="l00827"></a>00827 <a class="code" href="resolver_8c.html#a262ac7450159c115060ec464a4a5af6e" title="Return the tsig keyname as used by the nameserver.">ldns_resolver_tsig_keyname</a>(resolver), <a name="l00828"></a>00828 <a class="code" href="resolver_8c.html#abc7e0d0e3960348f774164d34af3013b" title="Return the tsig keydata as used by the nameserver.">ldns_resolver_tsig_keydata</a>(resolver), <a name="l00829"></a>00829 300, <a class="code" href="resolver_8c.html#a1fd4b31d628081e3d6dafdd389bfea0a" title="Return the tsig algorithm as used by the nameserver.">ldns_resolver_tsig_algorithm</a>(resolver), NULL); <a name="l00830"></a>00830 <span class="keywordflow">if</span> (status != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00831"></a>00831 <span class="comment">/* RoRi: to prevent problems on subsequent calls to ldns_axfr_start</span> <a name="l00832"></a>00832 <span class="comment"> we have to close the socket here! */</span> <a name="l00833"></a>00833 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00834"></a>00834 <span class="preprocessor"></span> close(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00835"></a>00835 <span class="preprocessor">#else</span> <a name="l00836"></a>00836 <span class="preprocessor"></span> closesocket(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00837"></a>00837 <span class="preprocessor">#endif</span> <a name="l00838"></a>00838 <span class="preprocessor"></span> resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> = 0; <a name="l00839"></a>00839 <a name="l00840"></a>00840 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afacc0113e61fc41216a1f417d7e894ed88">LDNS_STATUS_CRYPTO_TSIG_ERR</a>; <a name="l00841"></a>00841 } <a name="l00842"></a>00842 } <a name="l00843"></a>00843 <span class="preprocessor">#endif </span><span class="comment">/* HAVE_SSL */</span> <a name="l00844"></a>00844 <a name="l00845"></a>00845 <span class="comment">/* Convert the query to a buffer</span> <a name="l00846"></a>00846 <span class="comment"> * Is this necessary?</span> <a name="l00847"></a>00847 <span class="comment"> */</span> <a name="l00848"></a>00848 query_wire = <a class="code" href="buffer_8c.html#ac6d413e9a76bf7e7c2022f13e36b9900" title="creates a new buffer with the specified capacity.">ldns_buffer_new</a>(<a class="code" href="packet_8h.html#a0335fad1ab5f49839cd6c5a71e3d721b">LDNS_MAX_PACKETLEN</a>); <a name="l00849"></a>00849 <span class="keywordflow">if</span>(!query_wire) { <a name="l00850"></a>00850 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(query); <a name="l00851"></a>00851 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00852"></a>00852 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00853"></a>00853 <span class="preprocessor"></span> close(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00854"></a>00854 <span class="preprocessor">#else</span> <a name="l00855"></a>00855 <span class="preprocessor"></span> closesocket(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00856"></a>00856 <span class="preprocessor">#endif</span> <a name="l00857"></a>00857 <span class="preprocessor"></span> resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> = 0; <a name="l00858"></a>00858 <a name="l00859"></a>00859 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa81e80e66a14551db514726fa49290498">LDNS_STATUS_MEM_ERR</a>; <a name="l00860"></a>00860 } <a name="l00861"></a>00861 status = <a class="code" href="host2wire_8c.html#aa40d4e3f29ccf46535901c5d5010054b" title="Copies the packet data to the buffer in wire format.">ldns_pkt2buffer_wire</a>(query_wire, query); <a name="l00862"></a>00862 <span class="keywordflow">if</span> (status != <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>) { <a name="l00863"></a>00863 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(query); <a name="l00864"></a>00864 <a class="code" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44" title="frees the buffer.">ldns_buffer_free</a>(query_wire); <a name="l00865"></a>00865 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00866"></a>00866 <a name="l00867"></a>00867 <span class="comment">/* RoRi: to prevent problems on subsequent calls to ldns_axfr_start</span> <a name="l00868"></a>00868 <span class="comment"> we have to close the socket here! */</span> <a name="l00869"></a>00869 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00870"></a>00870 <span class="preprocessor"></span> close(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00871"></a>00871 <span class="preprocessor">#else</span> <a name="l00872"></a>00872 <span class="preprocessor"></span> closesocket(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00873"></a>00873 <span class="preprocessor">#endif</span> <a name="l00874"></a>00874 <span class="preprocessor"></span> resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> = 0; <a name="l00875"></a>00875 <a name="l00876"></a>00876 <span class="keywordflow">return</span> status; <a name="l00877"></a>00877 } <a name="l00878"></a>00878 <span class="comment">/* Send the query */</span> <a name="l00879"></a>00879 <span class="keywordflow">if</span> (<a class="code" href="net_8c.html#a690205442102fe4b606b5679241fce04" title="send a query via tcp to a server.">ldns_tcp_send_query</a>(query_wire, resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>, ns, <a name="l00880"></a>00880 (socklen_t)ns_len) == 0) { <a name="l00881"></a>00881 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(query); <a name="l00882"></a>00882 <a class="code" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44" title="frees the buffer.">ldns_buffer_free</a>(query_wire); <a name="l00883"></a>00883 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00884"></a>00884 <a name="l00885"></a>00885 <span class="comment">/* RoRi: to prevent problems on subsequent calls to ldns_axfr_start</span> <a name="l00886"></a>00886 <span class="comment"> we have to close the socket here! */</span> <a name="l00887"></a>00887 <a name="l00888"></a>00888 <span class="preprocessor">#ifndef USE_WINSOCK</span> <a name="l00889"></a>00889 <span class="preprocessor"></span> close(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00890"></a>00890 <span class="preprocessor">#else</span> <a name="l00891"></a>00891 <span class="preprocessor"></span> closesocket(resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a>); <a name="l00892"></a>00892 <span class="preprocessor">#endif</span> <a name="l00893"></a>00893 <span class="preprocessor"></span> resolver-><a class="code" href="structldns__struct__resolver.html#a081c69a516208b5270a1cfa33c94185c" title="Keep some things to make AXFR possible.">_socket</a> = 0; <a name="l00894"></a>00894 <a name="l00895"></a>00895 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afa0e6b44ad0292df31d103cab274cf0024">LDNS_STATUS_NETWORK_ERR</a>; <a name="l00896"></a>00896 } <a name="l00897"></a>00897 <a name="l00898"></a>00898 <a class="code" href="packet_8c.html#a05bd6d99b1f608238c67b84449724c16" title="frees the packet structure and all data that it contains.">ldns_pkt_free</a>(query); <a name="l00899"></a>00899 <a class="code" href="buffer_8c.html#a1615da957ad5a24a8b5cc1ba2f2b7f44" title="frees the buffer.">ldns_buffer_free</a>(query_wire); <a name="l00900"></a>00900 <a class="code" href="util_8h.html#a5e13054aa9b3843e97514228a0bbe909">LDNS_FREE</a>(ns); <a name="l00901"></a>00901 <a name="l00902"></a>00902 <span class="comment">/*</span> <a name="l00903"></a>00903 <span class="comment"> * The AXFR is done once the second SOA record is sent</span> <a name="l00904"></a>00904 <span class="comment"> */</span> <a name="l00905"></a>00905 resolver-><a class="code" href="structldns__struct__resolver.html#aaedcf2f47f8c62eac7a75fbe5d6a7b43" title="Count the number of LDNS_RR_TYPE_SOA RRs we have seen so far (the second one signifies the end of the...">_axfr_soa_count</a> = 0; <a name="l00906"></a>00906 <span class="keywordflow">return</span> <a class="code" href="error_8h.html#a11f34802bb1624af46054952e3b853afac58492ee3fc8d23f33c79824ed08c465">LDNS_STATUS_OK</a>; <a name="l00907"></a>00907 } </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>