<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WiredRevolution.com &#187; socket</title>
	<atom:link href="http://www.wiredrevolution.com/tag/socket/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wiredrevolution.com</link>
	<description>A Bit of Linux Wisdom</description>
	<lastBuildDate>Wed, 18 Jan 2012 22:45:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Find IP address from remote end of a TCP socket</title>
		<link>http://www.wiredrevolution.com/c/find-ip-address-from-remote-end-of-a-tcp-socket?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-ip-address-from-remote-end-of-a-tcp-socket</link>
		<comments>http://www.wiredrevolution.com/c/find-ip-address-from-remote-end-of-a-tcp-socket#comments</comments>
		<pubDate>Fri, 31 Oct 2008 12:49:34 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[getpeername]]></category>
		<category><![CDATA[inet_ntoa]]></category>
		<category><![CDATA[IP address]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sockaddr]]></category>
		<category><![CDATA[sockaddr_in]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[TCP]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=560</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/c_icon.png" width="80" height="80" alt="" title="C" /><br/>In C or C++ it is fairly simple to find the IP address of the remote end of a TCP socket. The following example shows how to do this using the getpeername() and inet_ntoa() system calls. int sockfd; int len; char * hostip; struct sockaddr_in sin; len = sizeof(sin); if (0 != getpeername(sockfd, (struct sockaddr [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/c/display-hostname-and-ip-address-in-c' rel='bookmark' title='Permanent Link: Display hostname and IP address in C'>Display hostname and IP address in C</a></li>
<li><a href='http://www.wiredrevolution.com/windows/find-the-mac-address-on-a-windows-machine' rel='bookmark' title='Permanent Link: Find the MAC address on a Windows machine'>Find the MAC address on a Windows machine</a></li>
<li><a href='http://www.wiredrevolution.com/c/format-output-using-printf' rel='bookmark' title='Permanent Link: Format output using printf'>Format output using printf</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/c_icon.png" width="80" height="80" alt="" title="C" /><br/><p>In C or C++ it is fairly simple to find the IP address of the remote end of a TCP socket.</p>
<p>The following example shows how to do this using the <strong>getpeername</strong>() and <strong>inet_ntoa</strong>() system calls.</p>
<pre>
int sockfd;
int len;
char * hostip;
struct sockaddr_in sin;

len = sizeof(sin);

if (0 != getpeername(sockfd, (struct sockaddr *) &#038;sin, &#038;len))
        perror("getpeername");
}

hostip = inet_ntoa(sin.sin_addr);

printf("client IP: %s\n", hostip);
</pre>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/c/display-hostname-and-ip-address-in-c' rel='bookmark' title='Permanent Link: Display hostname and IP address in C'>Display hostname and IP address in C</a></li>
<li><a href='http://www.wiredrevolution.com/windows/find-the-mac-address-on-a-windows-machine' rel='bookmark' title='Permanent Link: Find the MAC address on a Windows machine'>Find the MAC address on a Windows machine</a></li>
<li><a href='http://www.wiredrevolution.com/c/format-output-using-printf' rel='bookmark' title='Permanent Link: Format output using printf'>Format output using printf</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/c/find-ip-address-from-remote-end-of-a-tcp-socket/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

