<?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: simple gethostbyname example</title>
	<atom:link href="http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/feed/" rel="self" type="application/rss+xml" />
	<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/</link>
	<description>tagline goes here</description>
	<lastBuildDate>Thu, 09 Feb 2012 05:50:48 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: adeel shafi</title>
		<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/comment-page-1/#comment-314069</link>
		<dc:creator>adeel shafi</dc:creator>
		<pubDate>Tue, 13 Dec 2011 05:32:02 +0000</pubDate>
		<guid isPermaLink="false">http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/#comment-314069</guid>
		<description>i need the program for the gethostbyname</description>
		<content:encoded><![CDATA[<p>i need the program for the gethostbyname</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Can&#8217;t obtain local IP using gethostbyname() &#124; SeekPHP.com</title>
		<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/comment-page-1/#comment-314063</link>
		<dc:creator>Can&#8217;t obtain local IP using gethostbyname() &#124; SeekPHP.com</dc:creator>
		<pubDate>Sat, 12 Nov 2011 20:02:56 +0000</pubDate>
		<guid isPermaLink="false">http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/#comment-314063</guid>
		<description>[...] friend used the following snippet of code to retrieve the local IP address of the host in his [...]</description>
		<content:encoded><![CDATA[<p>[...] friend used the following snippet of code to retrieve the local IP address of the host in his [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: test30</title>
		<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/comment-page-1/#comment-295524</link>
		<dc:creator>test30</dc:creator>
		<pubDate>Mon, 10 May 2010 21:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/#comment-295524</guid>
		<description>Thank you, I used this for Windows, for those, who will find this page, here is what you need to get it working under Windows
[code]
#include
#include
WSADATA wsaData;
WORD version;
int error;
version = MAKEWORD( 2, 0 );
error = WSAStartup( version, &amp;wsaData );
    if (argc &lt; 2) {
        printf(&quot;Usage: %s hostname&quot;, argv[0]);
        exit(-1);
    }[/code]</description>
		<content:encoded><![CDATA[<p>Thank you, I used this for Windows, for those, who will find this page, here is what you need to get it working under Windows</p>
<p>[code]<br />
#include<br />
#include<br />
WSADATA wsaData;<br />
WORD version;<br />
int error;<br />
version = MAKEWORD( 2, 0 );<br />
error = WSAStartup( version, &amp;wsaData );</p>
<p>    if (argc &lt; 2) {<br />
        printf(&quot;Usage: %s hostname&quot;, argv[0]);<br />
        exit(-1);<br />
    }[/code]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Henri MICHEL</title>
		<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/comment-page-1/#comment-259865</link>
		<dc:creator>Henri MICHEL</dc:creator>
		<pubDate>Sun, 25 Oct 2009 08:18:54 +0000</pubDate>
		<guid isPermaLink="false">http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/#comment-259865</guid>
		<description>Oops hit the return button to quickly
3) exit (-1) doest not make much sense, what you get is the same as if you had written exit(255), since -1  representation is 0xffffffff in general on a 32bit system and the status returned to the parent process is truncated to the last 8 bits, exit(1) is what is used in general
To summarize all those cosmetics changes I would recommend the following:
&lt;pre&gt;
/* for inet_ntoa() */
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
int main(int argc, char **argv) {
 if (argc &lt; 2) {
   fprintf(stderr,&quot;Usage: %s hostname\n&quot;, argv[0]);
   exit(1);
 }
 struct hostent *hp = gethostbyname(argv[1]);
 if (hp == NULL) {
   fprintf(stderr,&quot;gethostbyname() failed\n&quot;);
   exit(1);
 } else {
   printf(&quot;%s = &quot;, hp-&gt;h_name);
   unsigned int i=0;
   while ( hp -&gt; h_addr_list[i] != NULL) {
     printf( &quot;%s &quot;, inet_ntoa( *( struct in_addr*)( hp -&gt; h_addr_list[i])));
     i++;
   }
   printf(&quot;\n&quot;);
   exit(0);
 }
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Oops hit the return button to quickly<br />
3) exit (-1) doest not make much sense, what you get is the same as if you had written exit(255), since -1  representation is 0xffffffff in general on a 32bit system and the status returned to the parent process is truncated to the last 8 bits, exit(1) is what is used in general</p>
<p>To summarize all those cosmetics changes I would recommend the following:</p>
<pre>
/* for inet_ntoa() */
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
int main(int argc, char **argv) {
 if (argc &lt; 2) {
   fprintf(stderr,"Usage: %s hostname\n", argv[0]);
   exit(1);
 }
 struct hostent *hp = gethostbyname(argv[1]);
 if (hp == NULL) {
   fprintf(stderr,"gethostbyname() failed\n");
   exit(1);
 } else {
   printf("%s = ", hp-&gt;h_name);
   unsigned int i=0;
   while ( hp -&gt; h_addr_list[i] != NULL) {
     printf( "%s ", inet_ntoa( *( struct in_addr*)( hp -&gt; h_addr_list[i])));
     i++;
   }
   printf("\n");
   exit(0);
 }
}
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michal</title>
		<link>http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/comment-page-1/#comment-252231</link>
		<dc:creator>Michal</dc:creator>
		<pubDate>Mon, 14 Sep 2009 20:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/#comment-252231</guid>
		<description>Thank you for the example Paul!</description>
		<content:encoded><![CDATA[<p>Thank you for the example Paul!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

