Boost C++ Libraries: Ticket #4690: boost::asio::ip::tcp::resolver fails to resolve query if service_name is empty https://svn.boost.org/trac10/ticket/4690 <p> Documentation: <a href="http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/reference/ip__basic_resolver_query/basic_resolver_query/overload3.html">http://www.boost.org/doc/libs/1_44_0/doc/html/boost_asio/reference/ip__basic_resolver_query/basic_resolver_query/overload3.html</a> </p> <p> service_name </p> <blockquote> <p> A string identifying the requested service. This may be a descriptive name or a numeric string corresponding to a port number. May be an empty string, in which case all resolved endpoints will have a port number of 0. </p> </blockquote> <p> If empty service_name is specified, resolver returns error. According to documentation, it should resolve to endpoint which will have port number of 0. </p> <p> Test program attached. </p> <p> My system: 2.6-RELEASE <a class="missing wiki">DragonFly</a> v2.6.3.43.gb67e7-RELEASE Boost 1.44 from pkgsrc. I think all systems are affected. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4690 Trac 1.4.3 Gennady Proskurin <gpr@…> Tue, 28 Sep 2010 16:05:17 GMT attachment set https://svn.boost.org/trac10/ticket/4690 https://svn.boost.org/trac10/ticket/4690 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">resolv.cc</span> </li> </ul> Ticket chris_kohlhoff Sat, 16 Oct 2010 08:59:58 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4690#comment:1 https://svn.boost.org/trac10/ticket/4690#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> I assume this is some sort of linux system? I cannot reproduce any such error on mine. </p> <p> Using the following slightly modified version of your testcase: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; void print_result(const char* serv, boost::asio::ip::tcp::resolver::iterator iter, const boost::system::error_code&amp; ec) { if( ec ) std::cerr &lt;&lt; "service: '" &lt;&lt; serv &lt;&lt; "' FAIL: " &lt;&lt; ec.message() &lt;&lt; "\n"; else { std::cerr &lt;&lt; "service: '" &lt;&lt; serv &lt;&lt; "' OK\n"; std::cerr &lt;&lt; "endpoint: " &lt;&lt; iter-&gt;endpoint() &lt;&lt; "\n"; } } void do_resolv(const char* serv) { boost::asio::io_service io; boost::asio::ip::tcp::resolver resolver(io); boost::asio::ip::tcp::resolver::query q("127.0.0.1", serv); boost::system::error_code ec; boost::asio::ip::tcp::resolver::iterator iter = resolver.resolve(q,ec); print_result(serv, iter, ec); } int main() { do_resolv(""); do_resolv("12345"); do_resolv("ftp"); return 0; } </pre><p> I get the following output: </p> <pre class="wiki">service: '' OK endpoint: 127.0.0.1:0 service: '12345' OK endpoint: 127.0.0.1:12345 service: 'ftp' OK endpoint: 127.0.0.1:21 </pre><p> The problem may be specific to your target platform, in which case you will probably need to do some debugging to find out what is going on. Please reopen the bug if you find more information. </p> Ticket Gennady Proskurin <gprspb@…> Sat, 16 Oct 2010 12:40:36 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/4690#comment:2 https://svn.boost.org/trac10/ticket/4690#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">worksforme</span> </li> </ul> <p> gdb output of my program attached This is FreeBSD 9-CURRENT The same result under DragonFlyBSD, and some Linuxes </p> <p> If it is not obvious to you from gdb output, what's the problem, I can try to look at boost sources when I have time. If you have suggestions how I can get more useful info, please let me know. </p> Ticket Gennady Proskurin <gprspb@…> Sat, 16 Oct 2010 12:42:07 GMT attachment set https://svn.boost.org/trac10/ticket/4690 https://svn.boost.org/trac10/ticket/4690 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">resolv.gdb</span> </li> </ul> <p> gdb debug session </p> Ticket Gennady Proskurin <gprspb@…> Sat, 16 Oct 2010 12:46:59 GMT <link>https://svn.boost.org/trac10/ticket/4690#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4690#comment:3</guid> <description> <p> As you see from debug, empty servname is propagated down to getaddrinfo, which causes error. I think boost should replace empty string with something like "0" somewhere on the path to getaddrinfo. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Sat, 16 Oct 2010 13:16:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4690#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4690#comment:4</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/66022" title="Pass NULL for servname rather than empty string, as per POSIX. Refs #4690. ">[66022]</a>) Pass NULL for servname rather than empty string, as per POSIX. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4690" title="#4690: Bugs: boost::asio::ip::tcp::resolver fails to resolve query if service_name ... (closed: fixed)">#4690</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Sat, 16 Oct 2010 13:16:50 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4690#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4690#comment:5</guid> <description> <p> Can you please try changeset <a class="changeset" href="https://svn.boost.org/trac10/changeset/66022" title="Pass NULL for servname rather than empty string, as per POSIX. Refs #4690. ">[66022]</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 18 Oct 2010 12:26:13 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4690#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4690#comment:6</guid> <description> <p> Problem reproduced and fix tested under FreeBSD 6.0. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>chris_kohlhoff</dc:creator> <pubDate>Mon, 18 Oct 2010 20:47:59 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4690#comment:7 https://svn.boost.org/trac10/ticket/4690#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Fixed in <a class="changeset" href="https://svn.boost.org/trac10/changeset/66080" title="Merge from trunk. ........ r66022 | chris_kohlhoff | 2010-10-17 ...">[66080]</a>. </p> Ticket