<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2360160807570351211</id><updated>2012-02-16T19:53:31.138+02:00</updated><category term='C++'/><category term='manpages'/><category term='android'/><category term='posix'/><category term='protocol'/><category term='tcpdump'/><category term='kernel'/><category term='scp'/><category term='wireshark'/><category term='links'/><category term='beagle'/><category term='networking'/><category term='cross-compile'/><category term='tar'/><title type='text'>Philosoft</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://istphilosoft.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>philosoft</name><uri>http://www.blogger.com/profile/16144246053433259150</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2360160807570351211.post-6297856637972123344</id><published>2011-09-29T12:40:00.007+03:00</published><updated>2011-09-30T09:56:08.861+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C++'/><title type='text'>Initializer Lists in C++0x</title><content type='html'>&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;In C++0x, there's a new language feature called initializer_list. In this post, we will see some hints about this helpful feature.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;We have not a uniform initializing method in the previous C++ standards. For example:&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt; i = 0;&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt; j(0);&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;char&lt;/span&gt; a[6] = &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;C++0x&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;; &lt;span class="comment" style="color: #969696;"&gt;// ={'C', '+', '+', '0', 'x'};&lt;/span&gt;&lt;br /&gt;    Student s(&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;Bjarne&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;Stroustrup&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;);&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;or&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;vector&amp;lt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt;&amp;gt; v(5); &lt;span class="comment" style="color: #969696;"&gt;// 5 items&lt;/span&gt;&lt;br /&gt;    v.push_back(8);&lt;br /&gt;    v.push_back(1);&lt;br /&gt;    &lt;span class="comment" style="color: #969696;"&gt;//other 3 items are 0&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;There are different styles of initilizing which is confusing programmers. So, a uniform initializing method would be great: Thanks to C++0x.&lt;/span&gt;&lt;/div&gt;&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;First, we will see some quick usages of this feature to warm up:&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;vector&amp;lt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt;&amp;gt; v = {8, 1, 7, 9}; &lt;span class="comment" style="color: #969696;"&gt;//see the difference in previous vector initialization&lt;/span&gt;&lt;br /&gt;    list&amp;lt;string&amp;gt; cities = {&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;Ankara&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;Istanbul&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;Izmir&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;};&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt; a[3][4] = {&lt;br /&gt;        {0, 1, 2, 3},&lt;br /&gt;        {4, 5, 6, 7},&lt;br /&gt;        {8, 9, 10, 11}&lt;br /&gt;    };&lt;br /&gt;&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;void&lt;/span&gt; f(initializer_list&amp;lt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt;&amp;gt; args) &lt;span class="comment" style="color: #969696;"&gt;//This function takes an initializer list as argument(an immutable sequence)&lt;/span&gt;&lt;br /&gt;    {&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;for&lt;/span&gt; (&lt;span class="keyword-directive" style="color: #0000e6;"&gt;auto&lt;/span&gt; p = args.begin(); p != args.end(); ++p) cout &amp;lt;&amp;lt; *p &amp;lt;&amp;lt; &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="ST0" style="color: #ce7b00; font-family: Monospaced; font-weight: bold;"&gt;\n&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;    f({1, 2}); &lt;span class="comment" style="color: #969696;"&gt;// passing a list on the fly&lt;/span&gt;&lt;br /&gt;    vector&amp;lt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;double&lt;/span&gt;&amp;gt; v1&lt;br /&gt;    {&lt;br /&gt;        7&lt;br /&gt;    }; &lt;span class="comment" style="color: #969696;"&gt;// ok: v1 has 1 element (with its value 7)&lt;/span&gt;&lt;br /&gt;    v1 = {9}; &lt;span class="comment" style="color: #969696;"&gt;// ok v1 now has 1 element (with its value 9). how can we do that without initializer_list?&lt;/span&gt;&lt;br /&gt;    &lt;span class="comment" style="color: #969696;"&gt;// we should first clear the vector and then push '9' to the vector&lt;/span&gt;&lt;br /&gt;    vector&amp;lt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;double&lt;/span&gt;&amp;gt; v2 = {9}; &lt;span class="comment" style="color: #969696;"&gt;// ok: v2 has 1 element (with its value 9)&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;Of course this new feature is widely used in standard library of C++0x. Here are two samples taken from GCC implementation of C++0x:&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; * std::string class:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In GCC implementation there's a new constructor that makes use of initializer_list,&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;ifdef&lt;/span&gt; __GXX_EXPERIMENTAL_CXX0X__&lt;br /&gt;    &lt;span class="comment" style="color: #969696;"&gt;/**&lt;/span&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt;     *  &lt;/span&gt;&lt;span class="ST1" style="color: #969696; font-family: Monospaced; font-weight: bold;"&gt;@brief&lt;/span&gt;  &lt;span class="comment" style="color: #969696;"&gt;Construct&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;string&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;from&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;an&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;initializer&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;list&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt;     *  &lt;/span&gt;&lt;span class="ST1" style="color: #969696; font-family: Monospaced; font-weight: bold;"&gt;@param&lt;/span&gt;  &lt;span class="comment" style="color: #969696;"&gt;l&lt;/span&gt;  &lt;span class="comment" style="color: #969696;"&gt;std&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;::&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;initializer_list&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;of&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;characters&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;.&lt;/span&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt;     *  &lt;/span&gt;&lt;span class="ST1" style="color: #969696; font-family: Monospaced; font-weight: bold;"&gt;@param&lt;/span&gt;  &lt;span class="comment" style="color: #969696;"&gt;a&lt;/span&gt;  &lt;span class="comment" style="color: #969696;"&gt;Allocator&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;to&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;use&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt; (&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;default&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;is&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;default&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;allocator&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;)&lt;/span&gt;&lt;span class="comment" style="color: #969696;"&gt;.&lt;/span&gt;&lt;br /&gt;     &lt;span class="comment" style="color: #969696;"&gt;*/&lt;/span&gt;&lt;br /&gt;    basic_string(initializer_list&amp;lt;_CharT&amp;gt; __l, &lt;span class="keyword-directive" style="color: #0000e6;"&gt;const&lt;/span&gt; _Alloc&amp;amp; __a = _Alloc());&lt;br /&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;endif&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;// __GXX_EXPERIMENTAL_CXX0X__&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #073763; font-family: Arial,Helvetica,sans-serif; font-size: large;"&gt;Let's create a string object with this new style constructor,&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;std::string s({&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;C&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;+&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;+&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;0&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;, &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;x&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;'&lt;/span&gt;});&lt;br /&gt;    std::cout &amp;lt;&amp;lt; s &amp;lt;&amp;lt; &lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;&lt;span class="ST0" style="color: #ce7b00; font-family: Monospaced; font-weight: bold;"&gt;\n&lt;/span&gt;&lt;span class="preprocessor-system-include-literal" style="color: #ce7b00;"&gt;"&lt;/span&gt;;&lt;/pre&gt;&lt;/span&gt; &lt;br /&gt;&amp;nbsp; &amp;nbsp; Output:&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; C++0x&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; * vector class:&lt;br /&gt;&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;&lt;span style="color: #073763; font-family: Arial,Helvetica,sans-serif; font-size: large;"&gt;Assignment operator in vector class shows us how to use initializer_list,&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;ifdef&lt;/span&gt; __GXX_EXPERIMENTAL_CXX0X__&lt;br /&gt;&lt;br /&gt;    vector&amp;amp; &lt;span class="keyword-directive" style="color: #0000e6;"&gt;operator&lt;/span&gt;=(initializer_list&amp;lt;value_type&amp;gt; __l) {&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;this&lt;/span&gt;-&amp;gt;assign(__l.begin(), __l.end());&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;return&lt;/span&gt; *&lt;span class="keyword-directive" style="color: #0000e6;"&gt;this&lt;/span&gt;;&lt;br /&gt;    }&lt;br /&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;endif&lt;/span&gt; &lt;span class="comment" style="color: #969696;"&gt;// __GXX_EXPERIMENTAL_CXX0X__&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #073763; font-family: Arial,Helvetica,sans-serif; font-size: large;"&gt;When we assign an initializer_list to the vector object, this operator=() function is called:&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;v1 = {9};&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="color: #073763; font-family: Arial,Helvetica,sans-serif;"&gt;&lt;span style="font-size: large;"&gt;Analyzing the std::initializer_list implementation is a good work to understand the inner details.&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Reference:&lt;br /&gt;&lt;a href="http://www2.research.att.com/%7Ebs/C++0xFAQ.html#init-list"&gt;http://www2.research.att.com/~bs/C++0xFAQ.html#init-list&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2360160807570351211-6297856637972123344?l=istphilosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/6297856637972123344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/6297856637972123344'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/2011/09/in-c0x-theres-new-language-feature.html' title='Initializer Lists in C++0x'/><author><name>Bahadır Doğan</name><uri>http://www.blogger.com/profile/12688737400201446138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-2360160807570351211.post-9103678203401999016</id><published>2011-08-17T03:16:00.004+03:00</published><updated>2011-08-17T15:44:16.816+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='posix'/><category scheme='http://www.blogger.com/atom/ns#' term='manpages'/><category scheme='http://www.blogger.com/atom/ns#' term='kernel'/><title type='text'>Man Pages on Linux</title><content type='html'>Man pages are manual pages about programs, utilities and functions usually with their names. They can be seen by "man" command. Man pages are very useful and easier to access than the searching web or other documentation materials. In most Linux distributions they are located at /usr/share/man directory includes directories for each level with level number suffix.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;ls /usr/share/man&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you install your Linux system GNUX/Linux programs and utilities related manpages are installed by default. You can check this with your package manager; below is command for debian based distributions:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: #741b47;"&gt;aptitude search manpages&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Most probably you already have manpages package, if you don't have you can install and test it for basic "ls" command as below:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;aptitude install manpages&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;man ls&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are other man pages about C library, Posix standard libraries and kernel sources functions. You can install these man pages with your package manager except kernel man pages. You have to use kernel source codes to generate man pages for kernel functions. Lets check C and Posix man pages:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;aptitude install manpages-dev manpages-posix manpages-posix-dev&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can test installation for fopen() libc function and socket() posix function as below:&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;man fopen&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;man pthread_create&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Sometimes there can be a command or tool with name of library functions. For examples there is a standard C library function exit() and also there is a built-in exit command. You can also check open, login, time etc. To see all man pages about a keyword you can use -a option with man:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;man -a time&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For kernel man pages, you should have kernel source codes. If you do not have, check your kernel version with "uname -r" command and download from kernel.org site. Usually kernel sources located under /usr/src directory. Untar kernel source package into /usr/src. Then enter top directory and use make to create and install kernel man pages to your system.&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;sudo tar xjvf linux-2.6.32.tar.bz2 -C /usr/src/&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;cd /usr/src/linux-2.6.32&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;make help&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;sudo make mandocs&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;sudo make installmandocs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;At this point, kernel man pages should be created and installed to your system by make from kernel source codes. Kernel man pages level is 9 and mostly located on /usr/local/share/man/man9/ directory. Now time to test, for example you can check kernel side print function as below:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;man printk&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By the way, you can update your man pages index caches as command below:&lt;br /&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;sudo mandb -c&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now you are completely ready to develop on Linux :)&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2360160807570351211-9103678203401999016?l=istphilosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://istphilosoft.blogspot.com/feeds/9103678203401999016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/man-pages.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/9103678203401999016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/9103678203401999016'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/man-pages.html' title='Man Pages on Linux'/><author><name>philosoft</name><uri>http://www.blogger.com/profile/16144246053433259150</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2360160807570351211.post-643553234999614652</id><published>2011-08-03T13:55:00.003+03:00</published><updated>2011-08-03T15:16:08.010+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tar'/><category scheme='http://www.blogger.com/atom/ns#' term='scp'/><category scheme='http://www.blogger.com/atom/ns#' term='tcpdump'/><category scheme='http://www.blogger.com/atom/ns#' term='wireshark'/><category scheme='http://www.blogger.com/atom/ns#' term='links'/><title type='text'>2 practical scripts for embedded systems</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', Times, serif; font-size: 14px; line-height: 21px; "&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;b style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;1. Live Wireshark capture for a CPE from your PC&lt;/b&gt;&lt;/div&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 15px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; "&gt;&lt;/p&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;i style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;Prerequisites:&lt;/i&gt;&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;- tcpdump installed on the CPE&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;- CPE accepting SSH connections&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;- Wireshark and Putty installed on the PC (Windows)&lt;/div&gt;&lt;p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 15px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; "&gt;&lt;/p&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;You can use the following command to listen for the packets on the CPE interface and see the output on the Wireshark which is launched on your PC:&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: 14px; line-height: 21px; " &gt;C:\Program Files\PuTTY&amp;gt;plink.exe -pw &lt;cpe root="" password=""&gt; root@&lt;cpe ip=""&gt; export LD_LIBRARY_PATH=/usr/local/ssl/lib:/usr/sfw/lib ; &lt;on_cpe_path_to&gt;/tcpdump -s 1500 -l -w- 'port!22' | "c:\Program Files\Wireshark\wireshark.exe" -k -i-&lt;/on_cpe_path_to&gt;&lt;/cpe&gt;&lt;/cpe&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: 14px; line-height: 21px; "&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt; &lt;/div&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;b style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;2. Extracting folders from a CPE without following symbolic links&lt;/b&gt;&lt;/div&gt;&lt;p style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 15px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; "&gt;&lt;/p&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;i style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;Prerequisites:&lt;/i&gt;&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;- tar installed on the CPE and the Linux PC&lt;/div&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;- CPE accepting SSH connections&lt;/div&gt;&lt;/div&gt;&lt;p style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 15px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; "&gt;&lt;/p&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;We know that we can use scp -r to extract folders from another Linux device, but scp will follow symbolic links. Here is how you do it without following symbolic links (this example will get the folders under /etc and /usr):&lt;/div&gt;&lt;p style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 15px; margin-right: 0px; margin-bottom: 18px; margin-left: 0px; "&gt;&lt;/p&gt;&lt;div style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;span class="Apple-style-span" &gt;ssh root@&lt;cpe ip=""&gt; "cd /; tar cf - etc usr" | tar xvf -&lt;/cpe&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;Source:&lt;/div&gt;&lt;div style="font-family: Georgia, 'Times New Roman', Times, serif; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "&gt;&lt;a href="http://www.linuxquestions.org/questions/linux-general-1/recursive-scp-w-o-following-links-658857/"&gt;http://www.linuxquestions.org/questions/linux-general-1/recursive-scp-w-o-following-links-658857/&lt;/a&gt;&lt;/div&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2360160807570351211-643553234999614652?l=istphilosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/643553234999614652'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/643553234999614652'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/2-practical-scripts-for-embedded.html' title='2 practical scripts for embedded systems'/><author><name>Mehmet Arikkan</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-2360160807570351211.post-6810361949883222753</id><published>2011-08-02T21:44:00.008+03:00</published><updated>2011-08-03T14:36:21.736+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='beagle'/><category scheme='http://www.blogger.com/atom/ns#' term='cross-compile'/><category scheme='http://www.blogger.com/atom/ns#' term='android'/><title type='text'>Android From Scratch  I</title><content type='html'>&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Android is a software stack for mobile devices that includes an operating system, middleware and key applications. Android has a large community of developers writing applications ("apps") that extend the functionality of the devices. There are currently more than 250,000 apps available for Android. Developers write primarily in the Java language, controlling the device via Google-developed Java libraries.&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Android is linux based and open source. We can download sources and build images for supported boards. In this document, we will try to build kernel and rootfs for beagleboard. Beagleboard is manufactured by Texas Instruments and it is good for doing development. You can check beagleboard from here[1]. I have beagleboard C4 revision and all works below is done on it.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;There are many projects use beagleboard[2]. Some of them are aimed to run android on beagleboard such as 0xdroid, Beagledroid, Android on Beagle and Rowboat. The most popular projects which use android is Angstrom and Rowboat. Angstrom is an embedded linux distrubition for variety of embedded devices and off course it is ported for beagleboard too. Angstrom is built from Openembedded, you can check manual how to configure and build it from here[3]. Another project ,Rowboat, provides a stable Google Android base port for AM1808, OMAP35x, AM35x, AM37x, AM389x and DM37x platforms. Our board platfor is OMAP35x and we will use Rowboat to build images for beagleboard.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;There are a lot of documentation about compiling android sources for beagleboard however reading all of them takes too time and we tried to create a document to tell just necessary instructions. In document you will see links as references and if you want to go further, sure you can.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;We will use Gingerbread-2.3 version but you can see other version build instructions on reference links. Lets start!&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Android use git repository with repo tool. Then if you already do not have, you should install git and get repo tool at first as below:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sudo apt-get install git-core&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wget http://android.git.kernel.org/repo&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;chmod +x repo&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sudo mv repo /bin/&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;We will use just "init" and "sync" commands of repo tool, you can see other commands and options from here[4].&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Now we need sources. You can download from repository over internet or you may download all needed repository as tar package. We will show both.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;If you want to download tarball package just use these commands and your build environment gets ready:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mkdir ti-android-rowboat&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cd ti-android-rowboat&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;wget http://software-dl.ti.com/dsps/dsps_public_sw/sdo_tii/TI_Android_DevKit/TI_Android_GingerBread_2_3_DevKit_1_0/&lt;span class="Apple-tab-span" style="white-space: pre;"&gt; &lt;/span&gt;exports/TI_Android_GingerBread_2_3_Sources.tar.gz&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;tar xzvf TI_Android_GingerBread_2_3_Sources.tar.gz&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;repo sync --local-only&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Secondly, if you want to download from repository, follow these steps:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Create a new directory and init repository as below. Your name and mail address will be asked while initing repository, you can enter anyting.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mkdir ti-android-rowboat&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cd ti-android-rowboat&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;repo init -u git://gitorious.org/rowboat/manifest.git -m TI-Android-GingerBread-2.3-DevKit-1.0.xml&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;repo sync&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;By commands above, we configured our manifest file as TI-Android-GingerBread-2.3-DevKit-1.0.xml. Our build operations will be up to this file. You can think it as configuration and selected application file. By sync operation, it gets sources. It may take hours depend on your bandwith.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;At this point, we have sources, toolchain and ready to build but we should add toolchain binary path to our PATH environment to be reachable when needed. In my system I add as below, you should enter your local path where it is.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;export PATH=/store/android/ti/gingerbread/TI_Android_GingerBread_2_3_Sources/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin:$PATH&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if you want to make it permanently you can add command into ~/.bashrc or ~/.profile scripts which run every shell login.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Now time to build. Enter top directory and run commands to get kernel image and rootfs:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cd ti-android-rowboat/TI_Android_GingerBread_2_3_Sources&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;make TARGET_PRODUCT=beagleboard -j4 OMAPES=3.x&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Our target product is beagleboard. It is recommended to use more than one thread on multi core systems, specify -j number_of_threads for this. Set OMAPES variable to install proper version of SGX driver, our board is use version 3.x.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;After successful compilation, we should have kernel image in "kernel/arch/arm/boot/" directory. uImage will be used as kernel. In addition, we should have "out/target/product/beagleboard/root" and "out/target/product/beagleboard/system" directories which are our rootfs images sources. We should create a rootfs directory and copy root and system contents to this directory. Then we will create a tarball.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cd out/target/product/beagleboard&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mkdir android_rootfs&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cp -r root/* android_rootfs&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;cp -r system android_rootfs&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="color: #741b47;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;sudo ../../../../build/tools/mktarball.sh ../../../host/linux-x86/bin/fs_get_stats android_rootfs . rootfs rootfs.tar.bz2&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Now we should have kernel image and rootfs tarball. Next time we will explain how to write kernel and untar rootfs to mmc card partitions. Then we will use mmc card for running android on beagle board. Have a nice coding!&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;--------------------------&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;Links:&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="text-decoration: none;"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-size: x-small;"&gt;1. http://beagleboard.org/hardware&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="text-decoration: none;"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-size: x-small;"&gt;2. http://beagleboard.org/project&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span style="text-decoration: none;"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-size: x-small;"&gt;3. http://www.angstrom-distribution.org/building-angstrom&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="text-decoration: none;"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style="font-size: x-small;"&gt;4. http://source.android.com/source/using-repo.html&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2360160807570351211-6810361949883222753?l=istphilosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://istphilosoft.blogspot.com/feeds/6810361949883222753/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/android-from-stracth-i.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/6810361949883222753'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/6810361949883222753'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/android-from-stracth-i.html' title='Android From Scratch  I'/><author><name>philosoft</name><uri>http://www.blogger.com/profile/16144246053433259150</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2360160807570351211.post-7293905665976118813</id><published>2011-08-02T19:26:00.013+03:00</published><updated>2011-08-04T13:36:28.492+03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='protocol'/><category scheme='http://www.blogger.com/atom/ns#' term='networking'/><title type='text'>Protocol Encoding</title><content type='html'>&lt;h2&gt;&lt;span style="font-size: large;"&gt;Terminology&lt;/span&gt;&lt;/h2&gt;&lt;b&gt;Protocol:&lt;/b&gt; A protocol is a set of rules which have to be followed in the course of some activity. In this article, we use the term “protocol” as a set of formal rules that governs the exchange of information.&lt;br /&gt;&lt;b&gt;Encoding:&lt;/b&gt;&lt;br /&gt;&lt;b&gt;Decoding:&lt;/b&gt;&lt;br /&gt;&lt;b&gt;PDU:&lt;/b&gt; A PDU is an abstraction unit that hides the protocol specific fields.&lt;br /&gt;&lt;h2&gt;&lt;/h2&gt;&lt;h2&gt;&lt;span style="font-size: large;"&gt;Representing PDUs&lt;/span&gt;&lt;/h2&gt;In  an abstract manner, we can think PDUs of simple records composed of  some fields. It also gives us the opportunity for transforming the  communication problem to programming domain. We can retrieve the value  of a field or modify the fields of the PDU in a proper way in order to  achieve the goal.&lt;br /&gt;&lt;br /&gt;General objectives of representation[1] :&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;b&gt;Efficiency&lt;/b&gt;: The information in the PDU should be coded as compactly as possible.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Delimiting&lt;/b&gt;: It must be possible for the receiver to recognise the beginning and end of the PDU.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Ease of decoding&lt;/b&gt;: It should be easy for the receiver to find out exactly what information it has received.&lt;/li&gt;&lt;li&gt;&lt;b&gt;Data transparency&lt;/b&gt;: The representation should be such that arbitrary sequences of bits can be sent as data within the PDU.&lt;/li&gt;&lt;/ol&gt;&lt;h3&gt;Simple binary encoding:&lt;/h3&gt;It  just encodes the value without any indicators.This type of encoding is  not flexible because size and order of members of the PDU are fixed. The  receiver can retrieve the desired value in constant time.&lt;br /&gt;&lt;br /&gt;Li be the length of ith item then,&lt;br /&gt;&lt;br /&gt;&lt;a href="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image00.png"&gt;&lt;img alt="" class="aligncenter size-full wp-image-129" height="18" src="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image00.png" title="image00" width="224" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;SBE:Algorithms(get parameter, add parameter)&lt;br /&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;&lt;span class="comment" style="color: #969696;"&gt;/* Get value of Nth key&lt;/span&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt;Value length is assumed 1&lt;/span&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt; */&lt;/span&gt;&lt;br /&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;void&lt;/span&gt; get(buffer, N, &amp;amp;val)&lt;br /&gt;{&lt;br /&gt;    val = buffer[n];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;void&lt;/span&gt; add(buffer, N, val)&lt;br /&gt;{&lt;br /&gt;    buffer[N] = val;&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;h3&gt;Type-Length-Value(TLV) encoding&lt;/h3&gt;TLV  is more flexible than simple binary encoding because fields are laid in  an arbitrary order, we can find the encoded value using the type as a  key. Also it helps us to implementation to retrieve values using generic  parsers.&lt;br /&gt;&lt;br /&gt;Li be the length of ith item then,&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image01.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="15" src="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image01.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Size of same amount of data that is encoded using TLV is greater than the one encoded using simple binary encoding.&lt;br /&gt;&lt;br /&gt;Figure1.1 may help to understand the algorithms below.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image02.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="100" src="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image02.png" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;Figure1.1&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;span class="Apple-style-span" style="background-color: white; color: black; font-family: Monospaced; font-size: small; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"&gt;&lt;pre style="background-color: white; color: black; font-family: Monospaced;"&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;define&lt;/span&gt; TYPE_INDEX 0&lt;br /&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;define&lt;/span&gt; LEN_INDEX 1&lt;br /&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;#&lt;/span&gt;&lt;span class="preprocessor-keyword-directive" style="color: #009b00;"&gt;define&lt;/span&gt; VAL_INDEX 2&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt; get(buffer, type) {&lt;br /&gt;    val = 0;&lt;br /&gt;    i = 0;&lt;br /&gt;&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;while&lt;/span&gt; (1) {&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;if&lt;/span&gt; (buffer[i] == t)&lt;br /&gt;            val = parser[t](buffer + i + VAL_INDEX); &lt;span class="comment" style="color: #969696;"&gt;//call the matching parser&lt;/span&gt;&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;break&lt;/span&gt;;&lt;br /&gt;        len = buffer[i + LEN_INDEX];&lt;br /&gt;        i = i + len + 1; &lt;span class="comment" style="color: #969696;"&gt;//jump to next type&lt;/span&gt;&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;return&lt;/span&gt; val;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="comment" style="color: #969696;"&gt;/* add the value to the end of the buffer */&lt;/span&gt;&lt;br /&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;void&lt;/span&gt; add(buffer, type, val, val_len) {&lt;br /&gt;    len = length(buffer);&lt;br /&gt;    buffer[len] = type;&lt;br /&gt;    buffer[len + LEN_INDEX] = val_len;&lt;br /&gt;    buffer[len + VAL_INDEX] = val;&lt;br /&gt;    buffer[len + LEN_INDEX + VAL_INDEX + val_len + 1] = END;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="keyword-directive" style="color: #0000e6;"&gt;int&lt;/span&gt; length(buffer) {&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;while&lt;/span&gt; (1) {&lt;br /&gt;        &lt;span class="keyword-directive" style="color: #0000e6;"&gt;if&lt;/span&gt; (buffer[i] == END)&lt;br /&gt;            &lt;span class="keyword-directive" style="color: #0000e6;"&gt;break&lt;/span&gt;;&lt;br /&gt;        len = buffer[i + LEN_INDEX];&lt;br /&gt;        i = i + len + 1;&lt;br /&gt;    }&lt;br /&gt;    &lt;span class="keyword-directive" style="color: #0000e6;"&gt;return&lt;/span&gt; len;&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;These encodings both may be used for a protocol at  the same time. Fixed parts are encoded using simple binary encoding,  while optional parts are encoded using TLV.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;span style="font-size: large;"&gt;Case study: DHCP&lt;/span&gt;&lt;/h2&gt;Let's try to figure out how the theory is applied to the real-world cases. DHCP is an automatic configuration protocol used on IP networks. Below you can find a DHCP packet structure:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="260" src="http://knuth.cs.bilgi.edu.tr/%7Ehdogan/bahadir/wp-content/uploads/2011/07/image03.png" width="462" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As you see DHCP PDU includes two types of parts:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;fixed(i.e, op, htype, hlen, hops, xid, ..)&lt;/li&gt;&lt;li&gt;variable(options)&lt;/li&gt;&lt;/ul&gt;Fixed fields are encoded in simple binary encoding, so lengths and orders of the fields are fixed. Any variation of field length or field order causes failure in communication.&lt;br /&gt;&lt;br /&gt;DHCP options, variable part, are encoded in  TLV. So, it is not a problem how the fields are ordered. Because the node retrieving the message can parse the options correctly by the help of self describing format of TLV. Some options are listed:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;tr&gt; &lt;td style="color: #ea9999;"&gt;&lt;b&gt;Code&lt;/b&gt;&lt;/td&gt; &lt;td style="color: #ea9999;"&gt;&lt;b&gt;Description&lt;/b&gt;&lt;/td&gt; &lt;td style="color: #ea9999;"&gt;&lt;b&gt;Length&lt;/b&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;53&lt;/td&gt; &lt;td&gt;DHCP Message Type&lt;/td&gt; &lt;td&gt;1&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;58&lt;/td&gt; &lt;td&gt;Renewal Time&lt;/td&gt; &lt;td&gt;4&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; &lt;td&gt;59&lt;/td&gt; &lt;td&gt;Rebinding Time&lt;/td&gt; &lt;td&gt;4&lt;/td&gt; &lt;/tr&gt;&lt;/tbody&gt; &lt;/table&gt;&lt;br /&gt;We can retrieve the value of option 53 using get pseudo:&lt;br /&gt;&lt;br /&gt;val = get(options, 53)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;References:&lt;br /&gt;[1] Principles of Protocol Design-&lt;span class="Apple-style-span" style="color: #666666; font-family: myriad,arial,sans-serif; font-size: 11px; line-height: 15px;"&gt;&lt;b style="border-width: 0px; font-family: inherit; font-size: 11px; font-style: normal; font-weight: bold; line-height: 1.3em; margin: 0px; padding: 0px; text-align: left;"&gt;Sharp&lt;/b&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: #666666; font-family: myriad,arial,sans-serif; font-size: 11px; line-height: 15px;"&gt;, Robin&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2360160807570351211-7293905665976118813?l=istphilosoft.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://istphilosoft.blogspot.com/feeds/7293905665976118813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/protocol-encoding.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/7293905665976118813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2360160807570351211/posts/default/7293905665976118813'/><link rel='alternate' type='text/html' href='http://istphilosoft.blogspot.com/2011/08/protocol-encoding.html' title='Protocol Encoding'/><author><name>Bahadır Doğan</name><uri>http://www.blogger.com/profile/12688737400201446138</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
