<?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"
	>

<channel>
	<title>Codefidence Ltd.</title>
	<atom:link href="http://codefidence.com/feed" rel="self" type="application/rss+xml" />
	<link>http://codefidence.com</link>
	<description>Open Source Development and Support</description>
	<pubDate>Sun, 08 Jun 2008 09:29:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Tuxology is born</title>
		<link>http://codefidence.com/posts/tuxology-is-born</link>
		<comments>http://codefidence.com/posts/tuxology-is-born#comments</comments>
		<pubDate>Sun, 08 Jun 2008 09:29:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://codefidence.com/?p=50</guid>
		<description><![CDATA[

Those of you who keep track of this blog, knows that we use it for two purposes: announcements about Codefidence and it&#8217;s activities, as well as sharing technical tips and tricks related to  Linux and Open Source based software development for our consultancy and training customers to enjoy (and of course everyone else).
As these [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://tuxology.net"><br />
<img src="http://codefidence.com/wp-content/uploads/tuxology_small.jpg" alt="" title="Tuxology mascot" align="right"/></a></p>
<p>Those of you who keep track of this blog, knows that we use it for two purposes: announcements about Codefidence and it&#8217;s activities, as well as sharing technical tips and tricks related to  Linux and Open Source based software development for our consultancy and training customers to enjoy (and of course everyone else).</p>
<p>As these posts have been very successful, at least judging from the amount of positive responses we&#8217;ve been getting, we decided to give them some more elbow room, thus <a href="http://tuxology.net">Tuxology</a> was born.</p>
<p><a href="http://tuxology.net">Tuxology</a> is a web site dedicated to the Linux training courses and consultancy provided by <a href="http://codefidence.com">Codefidence</a> and <a href="http://http://www.hi-tech.co.il/college/">Hi-Tech College</a>. It aims to provide an on-line counterpart to the courses material for students and and consultancy clients who wish to expand their knowledge and keep their skills up to date both during and after the training courses.</p>
<p><a href="http://tuxology.net">Tuxology</a> was created as a result of our belief that training is a process and therefore should be conducted in the context of a long term relationship between the instructor and the students and not a one off transaction.</p>
<p>In the spirit of the Free and Open Source software world which Linux is a part of, all the site facilities are free for all to access and enjoy, including updated course slides, forums and articles about the different course topics.</p>
<p>So, if you liked the tecnical tips and tricks in we&#8217;ve been providing thus far on the Codefidence web site and blog, make sure to head over to <a href="http://tuxology.net">Tuxology.net</a> to get the full Monty.</p>
<p>Hope to see you there!<br />
<strong>The Codefidence team</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/tuxology-is-born/feed</wfw:commentRss>
		</item>
		<item>
		<title>Penguin In a Box 2008</title>
		<link>http://codefidence.com/posts/penguin-in-a-box-2008</link>
		<comments>http://codefidence.com/posts/penguin-in-a-box-2008#comments</comments>
		<pubDate>Thu, 29 May 2008 13:31:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[News]]></category>

		<category><![CDATA[Training]]></category>

		<category><![CDATA[confrence]]></category>

		<category><![CDATA[embedded linux]]></category>

		<category><![CDATA[seminar]]></category>

		<guid isPermaLink="false">http://codefidence.com/?p=46</guid>
		<description><![CDATA[We are proud to announce that the third annual Penguin In A Box embedded Linux seminar organized by Codefidence ltd. in cooperation with Hi Tech College, will be held at the 03/07/2008 in the Daniel hotel and convention center in Herzelia, Israel.
As the use of Linux in the embedded market is on the rise and [...]]]></description>
			<content:encoded><![CDATA[<p>We are proud to announce that the third annual Penguin In A Box embedded Linux seminar organized by Codefidence ltd. in cooperation with <a href="http://www.hi-tech.co.il/college/">Hi Tech College</a>, will be held at the 03/07/2008 in the Daniel hotel and convention center in Herzelia, Israel.</p>
<p>As the <a href="http://www.linuxdevices.com/news/NS4920597981.html">use of Linux in the embedded market is on the rise</a> and it&#8217;s <a href="http://www.linux-foundation.org/publications/linuxkerneldevelopment.php">development continues at an extraordinary rate</a>, the seminar will cover, as in previous years, a broad range of topics relevant to Linux based embedded system developers wishing to keep abreast of recent developments.</p>
<p>For further details, check out the seminar <a href="http://www.hi-tech.co.il/college/promotion/linux_jul.htm">web page</a> (in Hebrew).</p>
<p>See you all there,<br />
Codefidence Team</p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/penguin-in-a-box-2008/feed</wfw:commentRss>
		</item>
		<item>
		<title>Reducing the size of dynamic libraries</title>
		<link>http://codefidence.com/posts/reducing-the-size-of-dynamic-libraries</link>
		<comments>http://codefidence.com/posts/reducing-the-size-of-dynamic-libraries#comments</comments>
		<pubDate>Sun, 27 Apr 2008 13:44:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Readers Questions]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/reducing-the-size-of-dynamic-libraries</guid>
		<description><![CDATA[Today we have a special reader request from an anonymous reader (slightly edited):

Hello,
Can you help me with some link issue which i face?
I  need to compile tree of  c-sources which produce  .so files and exe
files. I want to decrease the sizes of .so by throwing away unused symbols.
I can compile my tree [...]]]></description>
			<content:encoded><![CDATA[<p>Today we have a special reader request from an anonymous reader (slightly edited):</p>
<p><i><br />
Hello,</p>
<p>Can you help me with some link issue which i face?</p>
<p>I  need to compile tree of  c-sources which produce  .so files and exe<br />
files. I want to decrease the sizes of .so by throwing away unused symbols.</p>
<p>I can compile my tree statically  and used  as compiler flags   &#8211;static -ffunction-sections -fdata-sections    and link with &#8211;gc-sections option and it reduces all the unneeded symbols but I want to achieve the same effect in dynamic linking.</p>
<p>Do you know some efficient way to do it?</p>
<p>Thanks,<br />
Anonymous Reader<br />
</i></p>
<p>So the question is: how to make a minimal set of dynamic libraries for a known set of executables that only contain the code for those symbols which the executables actually use, thus saving expensive storage?</p>
<p>The quite simple answer is that there exists a Python utility that does exactly what you want called mklibs - It produces cut-down shared libraries that contain only the routines required by a particular set of executables.  </p>
<p>On Debian just go &#8220;sudo apt-get install mklibs&#8221;, or you can get the source straight from the Buildroot source repository <a href="http://www.uclibc.org/cgi-bin/viewcvs.cgi/trunk/buildroot/toolchain/mklibs/mklibs.py?rev=15764&#038;view=markup">here</a>.</p>
<p>If you don&#8217;t like Python (you really should!) you can try an older, shell script based variation on the same theme found <a href="http://www.rocklinux.net/svn/rock-linux/branches/2.0-stable/misc/archive/mklibs.sh">here</a>.</p>
<p>Note that you can pass the cross compiler prefix with the &#8220;&#8211;target&#8221; option, which is of course needed for supporting cross compilation.</p>
<p>Hope you found it useful and if you have more questions about Linux development you&#8217;d like answered, just <a href="http://codefidence.com/contact">let us know</a>.</p>
<p>The Codefidence team.</p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/reducing-the-size-of-dynamic-libraries/feed</wfw:commentRss>
		</item>
		<item>
		<title>We&#8217;ve Moved!</title>
		<link>http://codefidence.com/posts/weve-moved-2</link>
		<comments>http://codefidence.com/posts/weve-moved-2#comments</comments>
		<pubDate>Fri, 04 Apr 2008 08:59:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/weve-moved-2</guid>
		<description><![CDATA[That&#8217;s right, the Codefidence team have happily moved to our new offices in Tamar science park in Ness Ziona. The full address can be found in the updated contact page.
 
The move brings about a new shiny office with an amazing view, smack in the heart of the high tech district of Rehovot/Ness Ziona and [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s right, the Codefidence team have happily moved to our new offices in Tamar science park in Ness Ziona. The full address can be found in the updated <a href="http://codefidence.com/contact">contact</a> page.</p>
<p><a href="http://www.flickr.com/photos/firstpost/2387271622/" title="New Codefidence office, on Flickr"><img src="http://farm3.static.flickr.com/2069/2387271622_e8c82bf181_o.jpg" width="240" height="180" alt="New Codefidence office" /></a> </p>
<p>The move brings about a new shiny office with an amazing view, smack in the heart of the high tech district of Rehovot/Ness Ziona and within a relatively short driving distance from the Ben Gurion airport for our guests from abroad.</p>
<p><a href="http://www.flickr.com/photos/firstpost/2386442821/" title="View from new office, on Flickr"><img src="http://farm4.static.flickr.com/3196/2386442821_fc8d68f320_m.jpg" width="240" height="180" alt="View from new office" /></a></p>
<p>Please note that with the move we have also changed phone numbers. The new numbers are as follows:</p>
<address>Tel: +972-8-9316883</br><br />
Fax: +972-8-9316884<br />
</address>
<p>Wish us a happy stay in our new offices.</p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/weve-moved-2/feed</wfw:commentRss>
		</item>
		<item>
		<title>Remote Debugging with Eclipse</title>
		<link>http://codefidence.com/posts/remote-debugging-with-eclipse</link>
		<comments>http://codefidence.com/posts/remote-debugging-with-eclipse#comments</comments>
		<pubDate>Sun, 09 Mar 2008 09:08:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Presentations]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/remote-debugging-with-eclipse</guid>
		<description><![CDATA[Eclipse is an open source development platform comprised of extensible frameworks, tools and run times for building, deploying and managing software across the life cycle.
CDT is the name of the C/C++ development plug-in. It includes a graphical GDB front end.
The following slides are a short visual &#8220;how to&#8221; demonstrating configuring and using CDT to debug [...]]]></description>
			<content:encoded><![CDATA[<p>Eclipse is an open source development platform comprised of extensible frameworks, tools and run times for building, deploying and managing software across the life cycle.</p>
<p>CDT is the name of the C/C++ development plug-in. It includes a graphical GDB front end.</p>
<p>The following slides are a short visual &#8220;how to&#8221; demonstrating configuring and using CDT to debug a remote target with GDB.</p>
<p><a href='http://codefidence.com/wp-content/uploads/eclipse_debug.pdf' title='Remote debugging with Eclipse'>eclipse_debug.pdf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/remote-debugging-with-eclipse/feed</wfw:commentRss>
		</item>
		<item>
		<title>Using a shared library constructor</title>
		<link>http://codefidence.com/posts/using-a-shared-library-constructor</link>
		<comments>http://codefidence.com/posts/using-a-shared-library-constructor#comments</comments>
		<pubDate>Wed, 13 Feb 2008 14:55:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[constructor]]></category>

		<category><![CDATA[DLL]]></category>

		<category><![CDATA[DSO]]></category>

		<category><![CDATA[LD_PRELOAD]]></category>

		<category><![CDATA[shared library]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/using-a-shared-library-constructor</guid>
		<description><![CDATA[Shared libraries, sometime also referred to as DSO (for Dynamic Shared Objects) or DLL (for Dynamically Loadable Modules), offer an easy way to pack together useful functions and data as a code library that can be easily reused, updated separately from all the application making use of it and most important - under certain conditions [...]]]></description>
			<content:encoded><![CDATA[<p>Shared libraries, sometime also referred to as DSO (for Dynamic Shared Objects) or DLL (for Dynamically Loadable Modules), offer an easy way to pack together useful functions and data as a code library that can be easily reused, updated separately from all the application making use of it and most important - under certain conditions allows most the code and data  of the library to only be loaded once to the machine RAM regardless of the number of applications using it.</p>
<p>A shared library is thus normally comprised of a set of global functions which may be called by applications (or other libraries) that link with the library. </p>
<p>Given the shared nature of shared libraries, it is often useful to provide a constructor for the code library which will run each time the library is loaded by an application. Doing this is very simple, using the GNU specific constructor attribute. </p>
<p>Here is a code example:</p>

<div class="wp_syntax"><div class="code"><pre class="c">&nbsp;
<span style="color: #808080; font-style: italic;">/* init_demo.c */</span>
&nbsp;
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __attribute__ <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>constructor<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> \
  lib_init<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> lib_init<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #000066;">printf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Library ready. <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">return</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Then build the the shared library using the following GNU Makefile:</p>

<div class="wp_syntax"><div class="code"><pre>&nbsp;
.PHONY: clean
&nbsp;
libinitdemo.so.1.0.0: init_demo.c 
  $(CC) -fPIC init_demo.c -shared \
  -Wl,-soname,libinitdemo.so.1 -o \
  libinitdemo.so.1.0.0
&nbsp;
clean:
  $(RM) -f libinitdemo.so.1.0.0</pre></div></div>

<p><strong>TIP</strong><br />
Combining a shared library constructor as shown above with use of LD_PRELOAD can be a powerful way to add construction code to existing programs without changing their source code and indeed, without requiring access to their source code at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/using-a-shared-library-constructor/feed</wfw:commentRss>
		</item>
		<item>
		<title>Forcing connections through a specific interface</title>
		<link>http://codefidence.com/posts/forcing-connections-through-a-specific-interface</link>
		<comments>http://codefidence.com/posts/forcing-connections-through-a-specific-interface#comments</comments>
		<pubDate>Tue, 11 Dec 2007 10:51:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tips]]></category>

		<category><![CDATA[embedded]]></category>

		<category><![CDATA[LD_PRELOAD]]></category>

		<category><![CDATA[Linux]]></category>

		<category><![CDATA[management]]></category>

		<category><![CDATA[network interface]]></category>

		<category><![CDATA[routing]]></category>

		<category><![CDATA[socket option]]></category>

		<category><![CDATA[SO_BIDTODEVICE]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/forcing-connection-through-a-specific-interface</guid>
		<description><![CDATA[It can sometime be very useful to force an application to force to use a specific network interface for routing traffic, the regular routing tables not withstanding.
An example for such cases is where an embedded Linux system has a management network interface and a separate regular network interface where regular traffic should go:
So long as [...]]]></description>
			<content:encoded><![CDATA[<p>It can sometime be very useful to force an application to force to use a specific network interface for routing traffic, the regular routing tables not withstanding.</p>
<p>An example for such cases is where an embedded Linux system has a management network interface and a separate regular network interface where regular traffic should go:</p>
<p>So long as the two interfaces  use two different IP addresses from non overlapping network it is very easy - simply bind the management application socket to the management IP and let the routing table do the rest.</p>
<p>What to do, however, if product definition calls for supporting two different and separate, default gateway settings for management and media traffic? Although we can assign multiple default gateway routing table entries, how to make sure the management applications use one and all other traffic use another?</p>
<p>This is where the SO_BINDTODEVICE socket option comes to our rescue. We will install two default gateway entries: a normal one for the media traffic and another one for the management traffic, for which we will define a high metric so it will normally will not be used. </p>
<p>Then, we will set the SO_BINDTODEVICE socket option on sockets opened in management application, thus forcing the Linux networking stack to disregard any routing table entries not going through the specific device, but only for those specific sockets.</p>
<p>It  looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#include &lt;sys/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;net/if.h&gt;</span>
<span style="color: #993333;">struct</span> ifreq interface;
<span style="color: #993333;">struct</span> socket sock;
<span style="color: #808080; font-style: italic;">/* Management net interface name */</span>
<span style="color: #339933;">#define IFNAME &quot;eth3&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Acquire socket here ... */</span>
&nbsp;
strncpy<span style="color: #66cc66;">&#40;</span>interface.<span style="color: #202020;">ifr_ifrn</span>.<span style="color: #202020;">ifrn_name</span>, IFNAME, \
  IFNAMSIZ<span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>setsockopt<span style="color: #66cc66;">&#40;</span>sock, SOL_SOCKET, SO_BINDTODEVICE, \
  <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> *<span style="color: #66cc66;">&#41;</span>&amp;interface, <span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span>interface<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>  &lt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
       perror<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;SO_BINDTODEVICE failed&quot;</span><span style="color: #66cc66;">&#41;</span>;
      <span style="color: #808080; font-style: italic;">/* Deal with error... */</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>But wait! this is all well and good when we have the management application source code. This however is not always the case. Fear not! this too can be dealt with by hijacking the socket library call:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/types.h&gt;</span>
<span style="color: #339933;">#include &lt;sys/socket.h&gt;</span>
<span style="color: #339933;">#include &lt;net/if.h&gt;</span>
<span style="color: #339933;">#define __USE_GNU // Get RTLD_NEXT definition</span>
<span style="color: #339933;">#include &lt;dlfcn.h&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Management interface */</span>
<span style="color: #339933;">#define IFNAME &quot;eth3&quot;</span>
&nbsp;
<span style="color: #993333;">int</span> socket<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> domain, <span style="color: #993333;">int</span> type, <span style="color: #993333;">int</span> protocol<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
<span style="color: #993333;">int</span> <span style="color: #66cc66;">&#40;</span>*origsock<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">int</span> domain, <span style="color: #993333;">int</span> type, <span style="color: #993333;">int</span> protocol<span style="color: #66cc66;">&#41;</span>;
<span style="color: #993333;">char</span> * error;
<span style="color: #993333;">int</span> sock;
&nbsp;
origsock = dlsym<span style="color: #66cc66;">&#40;</span>RTLD_NEXT, <span style="color: #ff0000;">&quot;socket&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>error = dlerror<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #000000; font-weight: bold;">NULL</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
fprintf <span style="color: #66cc66;">&#40;</span>stderr, <span style="color: #ff0000;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, error<span style="color: #66cc66;">&#41;</span>;
exit<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
sock = origsock<span style="color: #66cc66;">&#40;</span>domain, type, protocol<span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>sock != <span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #993333;">struct</span> ifreq interface;
  strncpy<span style="color: #66cc66;">&#40;</span>interface.<span style="color: #202020;">ifr_ifrn</span>.<span style="color: #202020;">ifrn_name</span>, IFNAME, \
  IFNAMSIZ<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>setsockopt<span style="color: #66cc66;">&#40;</span>sock, SOL_SOCKET, SO_BINDTODEVICE, \
    <span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> *<span style="color: #66cc66;">&#41;</span>&amp;interface, <span style="color: #993333;">sizeof</span><span style="color: #66cc66;">&#40;</span>interface<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> &lt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
      perror<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;sendpacket: setting SO_BINDTODEVICE&quot;</span><span style="color: #66cc66;">&#41;</span>;
      exit<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> sock;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Compile this small library with (or create a proper Makefile)</p>

<div class="wp_syntax"><div class="code"><pre class="bash">$ <span style="color: #c20cb9; font-weight: bold;">gcc</span> sendto.c -fPIC -o sendto.so -ldl -shared</pre></div></div>

<p>To use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #007800;">LD_PRELOAD=</span>sendto.so ./management_app</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/forcing-connections-through-a-specific-interface/feed</wfw:commentRss>
		</item>
		<item>
		<title>Kernel panic messages</title>
		<link>http://codefidence.com/posts/kernel-panic-messages</link>
		<comments>http://codefidence.com/posts/kernel-panic-messages#comments</comments>
		<pubDate>Thu, 06 Dec 2007 15:06:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/kernel-panic-messages</guid>
		<description><![CDATA[It is sometime useful to be able to store the text of kernel panic messages in non volatile memory for postmortem fault analysis, in lieu of big enough storage device or network medium to store or send these message in the field.
The following code examples shows how this can be accomplished.
Some notes and caveats are [...]]]></description>
			<content:encoded><![CDATA[<p>It is sometime useful to be able to store the text of kernel panic messages in non volatile memory for postmortem fault analysis, in lieu of big enough storage device or network medium to store or send these message in the field.</p>
<p>The following code examples shows how this can be accomplished.</p>
<p>Some notes and caveats are due: the code does not deal with initializing the non volatile memory, if applicable. To use this example with NOR flash, as an example, code handling flash erasing will need to be added. In addition, this example does not display or clear saved messages and implementing this is left as an exercise to the reader.</p>
<p>Here is the Makefile:</p>

<div class="wp_syntax"><div class="code"><pre>default:
   $(MAKE) -C /lib/modules/`uname -r`/build \
      SUBDIRS=`pwd` modules
&nbsp;
clean:
  $(MAKE) -C /lib/modules/`uname -r`/build \
      SUBDIRS=`pwd` clean</pre></div></div>

<p>The simple Kbuild file is:</p>

<div class="wp_syntax"><div class="code"><pre>obj-m := panic_msg.o</pre></div></div>

<p>And the panic_msg.c is:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/moduleparam.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/notifier.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/ioport.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/io.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define LOG_PREFIX &quot;panic_msg: &quot;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> buf_address = <span style="color: #cc66cc;">0</span>;
module_param<span style="color: #66cc66;">&#40;</span>buf_address, ulong, S_IRUSR<span style="color: #66cc66;">&#41;</span>;
MODULE_PARM_DESC<span style="color: #66cc66;">&#40;</span>buf_address, 
  <span style="color: #ff0000;">&quot;The physical address of the panic message buffer.&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> buf_size = <span style="color: #cc66cc;">0</span>;
module_param<span style="color: #66cc66;">&#40;</span>buf_size, ulong, S_IRUSR<span style="color: #66cc66;">&#41;</span>;
MODULE_PARM_DESC<span style="color: #66cc66;">&#40;</span>buf_size, 
  <span style="color: #ff0000;">&quot;The size in bytes of the panic message buffer.&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> notifier_priority = INT_MAX;
module_param<span style="color: #66cc66;">&#40;</span>notifier_priority, uint, S_IRUSR<span style="color: #66cc66;">&#41;</span>;
MODULE_PARM_DESC<span style="color: #66cc66;">&#40;</span>notifier_priority, 
  <span style="color: #ff0000;">&quot;Notifier priority: INT_MAX &amp;gt;= x &amp;gt;= 0.&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">char</span> * buf;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> panic_msg_handler<span style="color: #66cc66;">&#40;</span>
  <span style="color: #993333;">struct</span> notifier_block *this, 
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> event,<span style="color: #993333;">void</span> *msg<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> panic_event_handled = <span style="color: #cc66cc;">0</span>;
  <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> msg_size = min<span style="color: #66cc66;">&#40;</span>strlen<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>, buf_size<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!panic_event_handled<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
     panic_event_handled = <span style="color: #cc66cc;">1</span>;
     memcpy_toio<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #993333;">char</span> *<span style="color: #66cc66;">&#41;</span>msg, buf, msg_size<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  <span style="color: #b1b100;">return</span> NOTIFY_OK;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> notifier_block panic_msg_notifier = <span style="color: #66cc66;">&#123;</span>
  .<span style="color: #202020;">notifier_call</span>  = panic_msg_handler,
  .<span style="color: #202020;">next</span>           = <span style="color: #000000; font-weight: bold;">NULL</span>,
  .<span style="color: #202020;">priority</span>       = INT_MAX
<span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> __init panic_msg_init<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
  <span style="color: #993333;">int</span> ret = <span style="color: #cc66cc;">0</span>;
  <span style="color: #993333;">struct</span> resource * res = <span style="color: #000000; font-weight: bold;">NULL</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>!buf_address<span style="color: #66cc66;">&#41;</span> || <span style="color: #66cc66;">&#40;</span>!buf_size<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    printk<span style="color: #66cc66;">&#40;</span>KERN_ERR LOG_PREFIX 
      <span style="color: #ff0000;">&quot;Address and size parameters are mandatory.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, 
      buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
    ret = -EINVAL;
    <span style="color: #b1b100;">goto</span> error;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  panic_msg_notifier.<span style="color: #202020;">priority</span> = notifier_priority;
&nbsp;
  res = request_mem_region<span style="color: #66cc66;">&#40;</span>buf_address, buf_size, 
    <span style="color: #ff0000;">&quot;Panic message handler&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!res<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    printk<span style="color: #66cc66;">&#40;</span>KERN_ERR LOG_PREFIX 
      <span style="color: #ff0000;">&quot;Failed requesting panic message buffer &quot;</span> \
      <span style="color: #ff0000;">&quot;at address  0x%lx of size %ld.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,
      buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
    ret = -EINVAL;
    <span style="color: #b1b100;">goto</span> error;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  buf = ioremap<span style="color: #66cc66;">&#40;</span>buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!buf<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    printk<span style="color: #66cc66;">&#40;</span>KERN_ERR LOG_PREFIX 
      <span style="color: #ff0000;">&quot;Failed mapping panic msg buf at address&quot;</span> \
      <span style="color: #ff0000;">&quot; 0x%lx of size %ld<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, 
      buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
    ret = -EINVAL;
    <span style="color: #b1b100;">goto</span> error;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>atomic_notifier_chain_register<span style="color: #66cc66;">&#40;</span>
     &amp;panic_notifier_list, &amp;panic_msg_notifier<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    printk<span style="color: #66cc66;">&#40;</span>KERN_ERR LOG_PREFIX 
      <span style="color: #ff0000;">&quot;Failed registering panic message notifier.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
    ret = -EINVAL;
    <span style="color: #b1b100;">goto</span> error;
  <span style="color: #66cc66;">&#125;</span>
&nbsp;
  printk<span style="color: #66cc66;">&#40;</span>KERN_INFO LOG_PREFIX 
   <span style="color: #ff0000;">&quot;Panic message buffer handler initialized.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span>;
&nbsp;
error:
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>res<span style="color: #66cc66;">&#41;</span> release_mem_region<span style="color: #66cc66;">&#40;</span>buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>buf<span style="color: #66cc66;">&#41;</span> iounmap<span style="color: #66cc66;">&#40;</span>buf<span style="color: #66cc66;">&#41;</span>;
  <span style="color: #b1b100;">return</span> ret;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __exit panic_msg_exit<span style="color: #66cc66;">&#40;</span><span style="color: #993333;">void</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>atomic_notifier_chain_unregister<span style="color: #66cc66;">&#40;</span>
     &amp;panic_notifier_list, &amp;panic_msg_notifier<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    printk<span style="color: #66cc66;">&#40;</span>KERN_ERR LOG_PREFIX 
      <span style="color: #ff0000;">&quot;Failed removing panic msg buf mapping.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
  <span style="color: #66cc66;">&#125;</span>
  iounmap<span style="color: #66cc66;">&#40;</span>buf<span style="color: #66cc66;">&#41;</span>;
  release_mem_region<span style="color: #66cc66;">&#40;</span>buf_address, buf_size<span style="color: #66cc66;">&#41;</span>;
&nbsp;
  printk<span style="color: #66cc66;">&#40;</span>KERN_INFO LOG_PREFIX 
     <span style="color: #ff0000;">&quot;Panic message buffer handler unloaded.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  <span style="color: #b1b100;">return</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
module_init<span style="color: #66cc66;">&#40;</span>panic_msg_init<span style="color: #66cc66;">&#41;</span>;
module_exit<span style="color: #66cc66;">&#40;</span>panic_msg_exit<span style="color: #66cc66;">&#41;</span>;
&nbsp;
MODULE_LICENSE<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;GPL&quot;</span><span style="color: #66cc66;">&#41;</span>;
MODULE_AUTHOR<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Gilad Ben-Yossef&quot;</span> \
  <span style="color: #ff0000;">&quot; &lt;gilad@codefidence.com&gt;&quot;</span><span style="color: #66cc66;">&#41;</span>;
MODULE_DESCRIPTION<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;This module stores kernel  &quot;</span> \
   <span style="color: #ff0000;">&quot;panic messages in non volatile memory.&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><a href='http://codefidence.com/wp-content/uploads/panic_msgtar.bz2' title='Panic message example kernel module source code'>Panic message example kernel module source code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/kernel-panic-messages/feed</wfw:commentRss>
		</item>
		<item>
		<title>Dynamic Linker Demystified From WindRiver Conference</title>
		<link>http://codefidence.com/posts/windriver-dynamic-linker</link>
		<comments>http://codefidence.com/posts/windriver-dynamic-linker#comments</comments>
		<pubDate>Tue, 04 Dec 2007 10:05:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Presentations]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/dynamic-linker-demystified-from-windriver-confrence</guid>
		<description><![CDATA[The following slides are from a presentation on the Linux dynamic linker and tips and tricks for its use in Linux based embedded system which was given by Gilad Ben-Yossef, Codedfidence CTO,  at the Wind River Embedded Linux Conference in Ramat Ilan, Israel at December 4, 2007:
Let’s Play The Weakest Link Slides (PDF)
]]></description>
			<content:encoded><![CDATA[<p>The following slides are from a presentation on the Linux dynamic linker and tips and tricks for its use in Linux based embedded system which was given by Gilad Ben-Yossef, Codedfidence CTO,  at the Wind River Embedded Linux Conference in Ramat Ilan, Israel at December 4, 2007:</p>
<p><a href="http://codefidence.com/wp-content/uploads/dlink-wr.pdf" title="Let’s Play The Weakest Link Slides (PDF)">Let’s Play The Weakest Link Slides (PDF)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/windriver-dynamic-linker/feed</wfw:commentRss>
		</item>
		<item>
		<title>Setting tasks CPU affinity</title>
		<link>http://codefidence.com/posts/setting-tasks-cpu-affinity</link>
		<comments>http://codefidence.com/posts/setting-tasks-cpu-affinity#comments</comments>
		<pubDate>Wed, 28 Nov 2007 10:17:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Code]]></category>

		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://codefidence.com/posts/setting-tasks-cpu-affinity</guid>
		<description><![CDATA[Linux kernel 2.6 and latest versions of 2.4 support two system calls that allow one to limit processes to specific CPUs.
The system calls are:

#include &#60;sched.h&#62;
&#160;
int sched_setaffinity&#40;pid_t  pid, unsigned int len, 
   unsigned long *mask&#41;;
&#160;
int sched_getaffinity&#40;pid_t pid, unsigned int len, 
   unsigned long *mask&#41;;

pid is the process id of the process [...]]]></description>
			<content:encoded><![CDATA[<p>Linux kernel 2.6 and latest versions of 2.4 support two system calls that allow one to limit processes to specific CPUs.</p>
<p>The system calls are:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#include &lt;sched.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> sched_setaffinity<span style="color: #66cc66;">&#40;</span>pid_t  pid, <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len, 
   <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> *mask<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #993333;">int</span> sched_getaffinity<span style="color: #66cc66;">&#40;</span>pid_t pid, <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> len, 
   <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> *mask<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><em>pid</em> is the process id of the process to assign to certain CPUs. Use &#8216;0&#8242; here to denote the current process.</p>
<p><em>len</em> is the length of the CPU bit mask, and  mask is a pointer to a bit mask denoting which CPU can the process run on.</p>
<p>For a good discussion and a code example, look here:</p>
<p><a href="http://www-128.ibm.com/developerworks/linux/library/l-affinity.html" title="http://www-128.ibm.com/developerworks/linux/library/l-affinity.html">http://www-128.ibm.com/developerworks/linux/library/l-affinity.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codefidence.com/posts/setting-tasks-cpu-affinity/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
