<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Get ip address from hostname in C with Linux sockets	</title>
	<atom:link href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/</link>
	<description>News, Technology, Entertainment and more</description>
	<lastBuildDate>Fri, 31 Jul 2020 10:58:53 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>
		By: Clark		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-165072</link>

		<dc:creator><![CDATA[Clark]]></dc:creator>
		<pubDate>Mon, 23 Jul 2018 01:04:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-165072</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67302&quot;&gt;thisisbazz&lt;/a&gt;.

I noticed the same problem. I used a similar fix. If I did the example with www.google.com, the original code, printed &quot;0.0.0.0&quot;.  It appears the last entry given by default name server is broken.  The first entry is correct.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67302">thisisbazz</a>.</p>
<p>I noticed the same problem. I used a similar fix. If I did the example with <a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a>, the original code, printed &#8220;0.0.0.0&#8221;.  It appears the last entry given by default name server is broken.  The first entry is correct.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: ROSELIN		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-87359</link>

		<dc:creator><![CDATA[ROSELIN]]></dc:creator>
		<pubDate>Tue, 05 Jul 2016 06:58:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-87359</guid>

					<description><![CDATA[Explain the program]]></description>
			<content:encoded><![CDATA[<p>Explain the program</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: srikanta		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-75312</link>

		<dc:creator><![CDATA[srikanta]]></dc:creator>
		<pubDate>Wed, 27 Apr 2016 16:51:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-75312</guid>

					<description><![CDATA[Thank you 
anyone checking this code while running the output....
./a.out www.google.com]]></description>
			<content:encoded><![CDATA[<p>Thank you<br />
anyone checking this code while running the output&#8230;.<br />
./a.out <a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: thisisbazz		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67317</link>

		<dc:creator><![CDATA[thisisbazz]]></dc:creator>
		<pubDate>Sun, 17 Aug 2014 00:59:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-67317</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67302&quot;&gt;thisisbazz&lt;/a&gt;.

Actually, having learned a little more, I&#039;ve reverted to the newer inet_ntop. Simpler to use, I&#039;m unsure if any power is lost from using it. I think it will be alright. Just thought I would leave evidence of my trail.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67302">thisisbazz</a>.</p>
<p>Actually, having learned a little more, I&#8217;ve reverted to the newer inet_ntop. Simpler to use, I&#8217;m unsure if any power is lost from using it. I think it will be alright. Just thought I would leave evidence of my trail.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: thisisbazz		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-67302</link>

		<dc:creator><![CDATA[thisisbazz]]></dc:creator>
		<pubDate>Wed, 13 Aug 2014 18:21:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-67302</guid>

					<description><![CDATA[First of all, thanks for putting this tutorial up! I have used it as a basis for my next-gen code! Having stated that, let me show you how I have improved it.

Your getaddrinfo example continuously overwrites the &quot;ip&quot; C-string, until interating through the linked list is finished. Why not simply write to it once at end of the loop, if only getting the last entry is what you REALLY want, but that&#039;s hardly useful! What you want is to make sure you&#039;re using an IP that works!

&quot;man getaddrinfo&quot; from the terminal. On my OSX, it has nice example of iterating through the list and trying to test a socket connection for TCP. I have turned that example into usable code, integrated with your tutorial&#039;s code: 

http://pastebin.com/cfUw5sG6

 For UDP you can do similar things by implementing a &quot;test&quot; msg for the server to receive and acknowledge with adaptive retransmission timeout.]]></description>
			<content:encoded><![CDATA[<p>First of all, thanks for putting this tutorial up! I have used it as a basis for my next-gen code! Having stated that, let me show you how I have improved it.</p>
<p>Your getaddrinfo example continuously overwrites the &#8220;ip&#8221; C-string, until interating through the linked list is finished. Why not simply write to it once at end of the loop, if only getting the last entry is what you REALLY want, but that&#8217;s hardly useful! What you want is to make sure you&#8217;re using an IP that works!</p>
<p>&#8220;man getaddrinfo&#8221; from the terminal. On my OSX, it has nice example of iterating through the list and trying to test a socket connection for TCP. I have turned that example into usable code, integrated with your tutorial&#8217;s code: </p>
<p><a href="http://pastebin.com/cfUw5sG6" rel="nofollow ugc">http://pastebin.com/cfUw5sG6</a></p>
<p> For UDP you can do similar things by implementing a &#8220;test&#8221; msg for the server to receive and acknowledge with adaptive retransmission timeout.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65013</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Tue, 26 Mar 2013 11:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65013</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65009&quot;&gt;Yu Jing&lt;/a&gt;.

i am not sure how AF_UNSPEC is supposed to behave exactly. It probably checks for both and based on the availability and priority it will return one of the addresses.

you can check out these links for more information on it

http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#ip4to6

http://stackoverflow.com/questions/8149601/what-would-be-the-disadvantages-risks-of-using-af-unspec]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65009">Yu Jing</a>.</p>
<p>i am not sure how AF_UNSPEC is supposed to behave exactly. It probably checks for both and based on the availability and priority it will return one of the addresses.</p>
<p>you can check out these links for more information on it</p>
<p><a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#ip4to6" rel="nofollow ugc">http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#ip4to6</a></p>
<p><a href="http://stackoverflow.com/questions/8149601/what-would-be-the-disadvantages-risks-of-using-af-unspec" rel="nofollow ugc">http://stackoverflow.com/questions/8149601/what-would-be-the-disadvantages-risks-of-using-af-unspec</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yu Jing		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65009</link>

		<dc:creator><![CDATA[Yu Jing]]></dc:creator>
		<pubDate>Tue, 26 Mar 2013 02:53:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65009</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65005&quot;&gt;Silver Moon&lt;/a&gt;.

Thanks for your patient , while ,what makes me confuse is ...

I mean, 
if the ai_family&#039;s value is &quot;AF_UNSPEC&quot;,

how the code judge using IPv4 or IPv6 ?

For example , if only my pc support IPv6 , will the code trying return the IPv6 address ?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65005">Silver Moon</a>.</p>
<p>Thanks for your patient , while ,what makes me confuse is &#8230;</p>
<p>I mean,<br />
if the ai_family&#8217;s value is &#8220;AF_UNSPEC&#8221;,</p>
<p>how the code judge using IPv4 or IPv6 ?</p>
<p>For example , if only my pc support IPv6 , will the code trying return the IPv6 address ?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65005</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Sun, 24 Mar 2013 02:56:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65005</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65004&quot;&gt;Yu Jing&lt;/a&gt;.

for using ipv6, the server, your isp, your computer - all 3 should support ipv6]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65004">Yu Jing</a>.</p>
<p>for using ipv6, the server, your isp, your computer &#8211; all 3 should support ipv6</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yu Jing		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65004</link>

		<dc:creator><![CDATA[Yu Jing]]></dc:creator>
		<pubDate>Sat, 23 Mar 2013 23:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65004</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65001&quot;&gt;Silver Moon&lt;/a&gt;.

Thank you, It works !
In the manual,
&quot;The  value  AF_UNSPEC  indicates  that getaddrinfo() should return socket addresses for any address family (either IPv4 or IPv6, for example) that can be used with node and service.&quot;
What is the basis of the judgments using IPv4 or IPv6?

The server support ipv6 ？ or  just my pc support IPv6?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65001">Silver Moon</a>.</p>
<p>Thank you, It works !<br />
In the manual,<br />
&#8220;The  value  AF_UNSPEC  indicates  that getaddrinfo() should return socket addresses for any address family (either IPv4 or IPv6, for example) that can be used with node and service.&#8221;<br />
What is the basis of the judgments using IPv4 or IPv6?</p>
<p>The server support ipv6 ？ or  just my pc support IPv6?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65002</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Sat, 23 Mar 2013 17:28:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65002</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65000&quot;&gt;Yu Jing&lt;/a&gt;.

or call the getaddrinfo function like this


getaddrinfo( hostname , NULL , NULL , &#038;servinfo);



that should give the correct ip of the hostname.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65000">Yu Jing</a>.</p>
<p>or call the getaddrinfo function like this</p>
<p>getaddrinfo( hostname , NULL , NULL , &amp;servinfo);</p>
<p>that should give the correct ip of the hostname.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65001</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Sat, 23 Mar 2013 17:08:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65001</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65000&quot;&gt;Yu Jing&lt;/a&gt;.

try changing the following line

hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6

to this

hints.ai_family = AF_INET;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65000">Yu Jing</a>.</p>
<p>try changing the following line</p>
<p>hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6</p>
<p>to this</p>
<p>hints.ai_family = AF_INET;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yu Jing		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-65000</link>

		<dc:creator><![CDATA[Yu Jing]]></dc:creator>
		<pubDate>Sat, 23 Mar 2013 15:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-65000</guid>

					<description><![CDATA[Thanks very much,  while getaddinfo is not always work:

[yu@argcandargv-com gethostbyname]$ ./gethostbyname www.google.com

www.google.com resolved to 173.194.72.99

[yu@argcandargv-com gethostbyname]$ ./getaddrinfo www.google.com

www.google.com resolved to 0.0.0.0

[yu@argcandargv-com gethostbyname]$ ./getaddrinfo www.msn.com

www.msn.com resolved to 131.253.13.140

[yu@argcandargv-com gethostbyname]$

WHY?]]></description>
			<content:encoded><![CDATA[<p>Thanks very much,  while getaddinfo is not always work:</p>
<p>[yu@argcandargv-com gethostbyname]$ ./gethostbyname <a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a></p>
<p><a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a> resolved to 173.194.72.99</p>
<p>[yu@argcandargv-com gethostbyname]$ ./getaddrinfo <a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a></p>
<p><a href="http://www.google.com" rel="nofollow ugc">http://www.google.com</a> resolved to 0.0.0.0</p>
<p>[yu@argcandargv-com gethostbyname]$ ./getaddrinfo <a href="http://www.msn.com" rel="nofollow ugc">http://www.msn.com</a></p>
<p><a href="http://www.msn.com" rel="nofollow ugc">http://www.msn.com</a> resolved to 131.253.13.140</p>
<p>[yu@argcandargv-com gethostbyname]$</p>
<p>WHY?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64967</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 15:37:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-64967</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64965&quot;&gt;mantra&lt;/a&gt;.

check your internet connectivity by pinging the host first.
use the following command at terminal/console


ping hostname


if ping replies come correctly, then try the program again and let me know the results.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64965">mantra</a>.</p>
<p>check your internet connectivity by pinging the host first.<br />
use the following command at terminal/console</p>
<p>ping hostname</p>
<p>if ping replies come correctly, then try the program again and let me know the results.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mantra		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64965</link>

		<dc:creator><![CDATA[mantra]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 14:29:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-64965</guid>

					<description><![CDATA[sir I have error like this----
gethostbyname: unknown host
please resolve this..]]></description>
			<content:encoded><![CDATA[<p>sir I have error like this&#8212;-<br />
gethostbyname: unknown host<br />
please resolve this..</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Silver Moon		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64962</link>

		<dc:creator><![CDATA[Silver Moon]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 03:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-64962</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64961&quot;&gt;shy&lt;/a&gt;.

for more information on how to get ip address of local interface check this post

http://www.binarytides.com/get-local-ip-c-linux/]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64961">shy</a>.</p>
<p>for more information on how to get ip address of local interface check this post</p>
<p><a href="http://www.binarytides.com/get-local-ip-c-linux/" rel="ugc">http://www.binarytides.com/get-local-ip-c-linux/</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: shy		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64961</link>

		<dc:creator><![CDATA[shy]]></dc:creator>
		<pubDate>Wed, 06 Mar 2013 00:25:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-64961</guid>

					<description><![CDATA[how to get our own ip address?? am getting only loopback address]]></description>
			<content:encoded><![CDATA[<p>how to get our own ip address?? am getting only loopback address</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jyothi		</title>
		<link>https://www.binarytides.com/hostname-to-ip-address-c-sockets-linux/comment-page-1/#comment-64006</link>

		<dc:creator><![CDATA[jyothi]]></dc:creator>
		<pubDate>Sat, 29 Dec 2012 09:12:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=1194#comment-64006</guid>

					<description><![CDATA[its really helpful]]></description>
			<content:encoded><![CDATA[<p>its really helpful</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
