<?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>rlazo&#039;s blog &#187; C/C++</title>
	<atom:link href="http://www.rlazo.org/category/cpp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rlazo.org</link>
	<description></description>
	<lastBuildDate>Sat, 08 May 2010 18:24:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Querying for an ethernet address in the arp cache</title>
		<link>http://www.rlazo.org/2008/12/18/querying-for-an-ethernet-address-in-the-arp-cache/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.rlazo.org/2008/12/18/querying-for-an-ethernet-address-in-the-arp-cache/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 21:15:54 +0000</pubDate>
		<dc:creator>Rodrigo</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://www.rlazo.org/?p=59</guid>
		<description><![CDATA[Just a quick note for myself, and for anybody looking to do the
   same. If you have an IP address and you want the corresponding MAC,
   using the ARP cache, here is the function:


#include &#60;stdio.h&#62;
#include &#60;sys/types.h&#62;
#include &#60;net/if_arp.h&#62;
#include &#60;sys/ioctl.h&#62;
#include &#60;arpa/inet.h&#62;
#include &#60;sys/socket.h&#62;
#include &#60;string.h&#62;

void print_eth_addr(const char* ip)
{
     int s;
  [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick note for myself, and for anybody looking to do the<br />
   same. If you have an IP address and you want the corresponding MAC,<br />
   using the ARP cache, here is the function:
</p>
<div >
<pre name="code" class="cpp">#include &lt;stdio.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;net/if_arp.h&gt;
#include &lt;sys/ioctl.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;string.h&gt;

void print_eth_addr(const char* ip)
{
     int s;
     struct sockaddr_in *sin;
     struct arpreq a;
     struct in_addr addr;

     s = socket(AF_INET, SOCK_DGRAM,0);

     memset(&amp;a, 0, sizeof(a));
     strcpy(a.arp_dev, &quot;wlan0&quot;);
     sin = (struct sockaddr_in*)&amp;(a.arp_pa);
     sin-&gt;sin_family = AF_INET;
     a.arp_flags = ATF_PUBL;

     inet_aton(ip, &amp;addr);

     memcpy(&amp;sin-&gt;sin_addr, &amp;addr, sizeof(struct in_addr));

     if (ioctl(s,SIOCGARP,&amp;a)) {
          perror(&quot;ioctl&quot;);
     }
     unsigned char* hw_addr = (unsigned char *) a.arp_ha.sa_data;
     printf(&quot;HWAddr found : %x:%x:%x:%x:%x:%x\n&quot;, hw_addr[0],
        hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]);

}
</pre>
</div>
<p>Just change &#8220;wlan0&#8243; for &#8220;eth0&#8243; or your favorite network interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlazo.org/2008/12/18/querying-for-an-ethernet-address-in-the-arp-cache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Yasnippet for C style comments</title>
		<link>http://www.rlazo.org/2008/12/12/yasnippet-for-c-style-comments/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.rlazo.org/2008/12/12/yasnippet-for-c-style-comments/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 01:09:56 +0000</pubDate>
		<dc:creator>Rodrigo</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://www.rlazo.org/?p=55</guid>
		<description><![CDATA[Are you using yasnippet right?
   No? Well, in a nutshell is an awesome template system for Emacs, I
   really recommend it. The template language is very easy to learn and
   there are templates for a lot of programming languages.

Yasnippet stores your snippets in the filesystem, a single snippet per
 [...]]]></description>
			<content:encoded><![CDATA[<p>Are you using <a href="http://code.google.com/p/yasnippet/">yasnippet</a> right?<br />
   No? Well, in a nutshell is an awesome template system for Emacs, I<br />
   <strong>really recommend it</strong>. The template <em>language</em> is very easy to learn and<br />
   there are templates for a lot of programming languages.
</p>
<p>Yasnippet stores your snippets in the filesystem, a single snippet per<br />
   file and inside a directory structure that mirrors the major mode<br />
   hierarchy. For example, the snippet for the <code>using namespace std</code> C++<br />
   idiom is stored in a file named <code>using</code>, and it&#8217;s located in the<br />
   directory <code>snippets/text-mode/cc-mode/c++-mode</code>. The file name (in<br />
   this example <code>using</code>) is used as the key for the expansion. You know,<br />
   convention over configuration .
</p>
<p>Because yasnippets uses filenames as keys, you face filesystem&#8217;s<br />
   naming restrictions, and this is a problem if you want to define a<br />
   snippet for C comments, you can&#8217;t name a file <code>/*</code> for obvious<br />
   reasons. What do you do then? Well, yasnippet allows you to define<br />
   your snippets in elisp code directly, so if you want to create your C<br />
   sytle comments template, you can do something like this
</p>
<div class="codehilite">
<pre>  <span class="c1">;; $0 defines where the cursor will be left after the expansion</span>
  <span class="p">(</span><span class="nv">yas/define</span> <span class="ss">&#39;cc-mode</span> <span class="s">&quot;/*&quot;</span> <span class="s">&quot;/* $0 */&quot;</span><span class="p">)</span>
  <span class="p">(</span><span class="nv">yas/define</span> <span class="ss">&#39;cc-mode</span> <span class="s">&quot;/**&quot;</span> <span class="s">&quot;/**\n * $0\n **/&quot;</span><span class="p">)</span>
</pre>
</div>
<p>The first argument is the major mode where this snippet will be available, the second is the key you will use to expand the template, and the last argument is the template itself.
</p>
<p>For more about writting snippets for this system, <a href="http://pluskid.lifegoo.com/upload/project/yasnippet/doc/define_snippet.html">go here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rlazo.org/2008/12/12/yasnippet-for-c-style-comments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
