<?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-4680898882379290660</id><updated>2011-12-29T18:25:44.765+09:00</updated><category term='linux'/><category term='volunteer'/><category term='sendai'/><category term='/proc'/><category term='java'/><category term='camera'/><category term='wifi'/><category term='php'/><category term='radiation'/><category term='storage'/><category term='xbee'/><category term='iot'/><category term='fuzzy computing'/><category term='tamias'/><category term='network interface'/><category term='interface'/><category term='gsoc2010'/><category term='SIOCGIFCONF'/><category term='socket'/><category term='iphone'/><category term='motd'/><category term='rtnetlink'/><category term='welcome'/><category term='ioctl'/><category term='python'/><category term='netlink'/><category term='setsockopt'/><category term='debian'/><category term='accelerometer'/><category term='japan'/><category term='touchscreen'/><category term='standards'/><category term='network'/><category term='read.air'/><category term='funscience'/><category term='floating-point'/><category term='shellscript'/><category term='reader'/><category term='pachube'/><category term='ipv6'/><category term='les amis du Tohoku'/><title type='text'>Jean's tech blog</title><subtitle type='html'>I really try hard to put interesting technical stuff into there. &lt;br&gt;Now here's a quote : "Servers have gained freedom. Clients have gained nothing. Welcome to the cloud -- Eben Moglen"</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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>17</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-2273102546788708543</id><published>2011-12-27T10:17:00.000+09:00</published><updated>2011-12-27T10:17:30.969+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='tamias'/><category scheme='http://www.blogger.com/atom/ns#' term='storage'/><title type='text'>Looking back on 2011</title><content type='html'>Dear readers,&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-itAVw8odqXw/TvkbcTdmZcI/AAAAAAAAAJQ/ZlCmBH_hsiU/s1600/tamias.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img border="0" height="184" src="http://1.bp.blogspot.com/-itAVw8odqXw/TvkbcTdmZcI/AAAAAAAAAJQ/ZlCmBH_hsiU/s200/tamias.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;So the year 2011 is coming to an end and I have eventually failed my secret goal of having more articles than last year. The main reason being that I did not &amp;nbsp;post much in the last three months. And the explanation is just a single word : &lt;b&gt;Tamias&lt;/b&gt;. Tamias is a pet name, a kind of chipmunk (although some folks complained that our logo looks like a mutated rat or something, hi Ed!). It could have been the name of a pet-project, but it really is the pet-name of a project we have here, at the office.&lt;br /&gt;&lt;br /&gt;I can't really explain it all in one post, so let's say a few very basic things to keep it short and interesting.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Tamias is based on &lt;a href="https://tahoe-lafs.org/" target="_blank"&gt;Tahoe-LAFS&lt;/a&gt;, which makes it awesome from the start&lt;/li&gt;&lt;li&gt;Tamias allows users sharing a mutual interest to gather together and create their own cloudish storage system by providing storage space to the distributed storage "cloud". Sorry for the buzz word, you can really replace cloud by network, p2p network, overlay network, whatever.&lt;/li&gt;&lt;li&gt;Users from a same network exchange identity information between each others (essentially public keys) and can share files privately and securely. Privately means that someone learning the access information (what is called a capability here, think of it as a self-certifying URL) from someone else can not use it. Securely means that file blocks are stored with encryption and thus not readable by the storage node (this is granted by Tahoe-LAFS).&lt;/li&gt;&lt;li&gt;The first beta version of Tamias was released on December 25th &lt;a href="https://tamias.iijlab.net/?p=43" target="_blank"&gt;here&lt;/a&gt;.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;This version works, but it is not very user-friendly, so we only expect the most computer savvy users to try it out and report errors, problems, bugs and so on. In the future, we will provide a (much much much) better UI of course, and new features like user self-introduction, user search, sharing delegation, networks federation, etc...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The Tamias website is at &lt;a href="https://tamias.iijlab.net/" target="_blank"&gt;https://tamias.iijlab.net&lt;/a&gt; and has a few &lt;a href="https://tamias.iijlab.net/?page_id=50" target="_blank"&gt;tutorials&lt;/a&gt; about compiling the software or setting up a node. As it is based on Tahoe-LAFS, it includes Tahoe-LAFS and builds upon it. However, you can not use your existing Tahoe-LAFS grid without modifications, because we added a couple of features on the storage server side, that were needed for privacy extensions.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Short post for a long story, but here's a scoop for you all : the next release will be much better and is planned for next spring...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Happy year-end holidays to you all !&lt;/div&gt;&lt;div&gt;Jean&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-2273102546788708543?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/2273102546788708543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=2273102546788708543' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/2273102546788708543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/2273102546788708543'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/12/looking-back-on-2011.html' title='Looking back on 2011'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/-itAVw8odqXw/TvkbcTdmZcI/AAAAAAAAAJQ/ZlCmBH_hsiU/s72-c/tamias.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-5381947974593725683</id><published>2011-09-21T10:22:00.000+09:00</published><updated>2011-09-21T10:32:58.547+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='accelerometer'/><category scheme='http://www.blogger.com/atom/ns#' term='xbee'/><category scheme='http://www.blogger.com/atom/ns#' term='funscience'/><title type='text'>Realtime visualization for Xbee+Accelerometer data</title><content type='html'>Here is the long awaited follow-up to the Xbee experiments that my little brother outsourced to me.&lt;br /&gt;&lt;br /&gt;Before I get to the description of the software itself, if you want to try this out, be sure to follow the guidelines in the &lt;a href="http://iijean.blogspot.com/2011/08/accelerometer-xbee-geekish-fun.html"&gt;previous post on the same topic&lt;/a&gt;. You are then ready to proceed.&lt;br /&gt;&lt;br /&gt;And here is what you get with this software :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Realtime visualization of all three axis&lt;/li&gt;&lt;li&gt;Can be adapted to many different accelerometers by tuning some global variables&lt;/li&gt;&lt;li&gt;Recording of samples to file, with timestamps and X, Y and Z values&lt;/li&gt;&lt;li&gt;Automatically generated plots for each axis and a combined 3-axis plot&lt;/li&gt;&lt;li&gt;Exported files named according to experiment date and time (for easier sorting)&lt;/li&gt;&lt;li&gt;All the above, in pure opensource python goodness&lt;/li&gt;&lt;li&gt;English and French localization&lt;/li&gt;&lt;li&gt;Theoretically works from within a LiveCD&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-j8_8C-6x0Bw/Tnk6_MxbfcI/AAAAAAAAAIw/IVzVvRTsJkQ/s1600/python_appli_screenshot.png" imageanchor="1" style="clear:left; float:left;margin-right:1em; margin-bottom:1em"&gt;&lt;img border="0" height="99" width="200" src="http://3.bp.blogspot.com/-j8_8C-6x0Bw/Tnk6_MxbfcI/AAAAAAAAAIw/IVzVvRTsJkQ/s200/python_appli_screenshot.png" /&gt;&lt;/a&gt;&lt;/div&gt;Now let me briefly describe what the software does. As you can see in the screenshot on the side, the user interface is quite easy to understand. The three rectangle-shaped black boxes are showing whatever comes from the Xbee chip hooked up to the USB port, in realtime.&lt;br /&gt;&lt;br /&gt;There are also three clickable buttons. The leftmost button labelled 'start' triggers the beginning of the recording. You will usually push this just before your experiment. The middle button named 'stop' obviously halts the recording. It also takes care of dumping all the samples into a CSV and generating the four plots : a combined plot with all 3 axis and three separate plots, one per axis. Of course the last button closes the USB port and quits the program. Beware that it does not check if you have a running experiment and will hence lose some data unless you push the stop button first.&lt;br /&gt;&lt;br /&gt;Enough talking now, here is the &lt;a href="http://www.iijlab.net/~jean/xviz.zip"&gt;python archive&lt;/a&gt;, all you have to do is extract the contents somewhere and run the software by launching the xviz.py script file.&lt;br /&gt;&lt;br /&gt;I also uploaded this to the github social coding site, feel free to fork this, submit patches or whatever !&lt;br /&gt;&lt;br /&gt;&lt;a href="https://github.com/jean-/xviz"&gt;https://github.com/jean-/xviz&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-5381947974593725683?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/5381947974593725683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=5381947974593725683' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/5381947974593725683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/5381947974593725683'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/09/realtime-visualization-for.html' title='Realtime visualization for Xbee+Accelerometer data'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-j8_8C-6x0Bw/Tnk6_MxbfcI/AAAAAAAAAIw/IVzVvRTsJkQ/s72-c/python_appli_screenshot.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-8572950607931943173</id><published>2011-09-15T14:18:00.000+09:00</published><updated>2011-09-21T07:46:04.742+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='volunteer'/><category scheme='http://www.blogger.com/atom/ns#' term='les amis du Tohoku'/><category scheme='http://www.blogger.com/atom/ns#' term='sendai'/><title type='text'>Wanted: Volunteers to give a hand on next holiday</title><content type='html'>Dear readers,&lt;br /&gt;&lt;br /&gt;Here is a quick call for volunteering.&lt;br /&gt;&lt;br /&gt;An association I am working voluntarily is organizing a trip to Sendai area to deliver home appliances and furniture we have been gathering from the people who left Japan.&lt;br /&gt;&lt;br /&gt;As we do not have enough hands for the whole work, we are actively recruiting people who would like to help. Here is the full text :&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Silver Week is coming, the "friends" are hiring&lt;br /&gt;----------------------------------------------&lt;br /&gt;by Les Amis du Tohoku on Monday, September 12, 2011 at 11:20pm&lt;br /&gt;&lt;br /&gt;EDIT: the day has changed from 23rd to 22nd in order to avoid congestion on the Tohoku expressway on a national holiday, moreover reduced to a single lane because of (long overdue) construction work.&lt;br /&gt;&lt;br /&gt;Dear friends, through our Facebook page you have beenable to follow us and our activities, picking up furniture and home appliances around Tokyo.You have been hearing our calls for donation but were not moving and had neither furniture nor home appliances to donate.&lt;br /&gt;&lt;br /&gt;Now is your chance to make a difference, to show that youreally love Japan, and that you are a friend of the disaster-hit Tohoku area.&lt;br /&gt;&lt;br /&gt;Come &lt;b&gt;join us&lt;/b&gt;, come help us for the preparations to the next journey, or even the journey itself, on &lt;b&gt;September 22nd 2011&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;We are looking for the following kind of volunteers :&lt;br /&gt;- On the day of departure, people to &lt;b&gt;help clean the goods&lt;/b&gt;&lt;br /&gt;- On the day of departure, people to &lt;b&gt;help load the truck&amp;nbsp;&lt;/b&gt;&lt;br /&gt;- From the day of departure to following evening, people to &lt;b&gt;drive the truck&lt;/b&gt; (standard driving license required*)&lt;br /&gt;- From the day of departure to following evening, people to &lt;b&gt;join us with their own car&lt;/b&gt; and come help to unload.&lt;br /&gt;&lt;br /&gt;Don't hesitate to contact us if you would like to find out about this trip, to volunteer,or for any other reason.by mail: jean.lorchat@gmail.com&lt;br /&gt;&lt;br /&gt;[*]: for any inquiries about driving license, please contact us as well&lt;br /&gt;&lt;br /&gt;----------------------------------------------&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&amp;nbsp;And here is the original post. &lt;a href="https://www.facebook.com/notes/les-amis-du-tohoku/silver-week-is-coming-the-friends-are-hiring/287161067964520"&gt;les amis du Tohoku : silver week is coming&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-8572950607931943173?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/8572950607931943173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=8572950607931943173' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/8572950607931943173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/8572950607931943173'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/09/wanted-volunteers-to-give-hand-on-next.html' title='Wanted: Volunteers to give a hand on next holiday'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-6413009231758483045</id><published>2011-08-12T11:01:00.013+09:00</published><updated>2011-08-12T11:54:27.730+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='iot'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='pachube'/><title type='text'>Adding Pachube readings to any PHP website</title><content type='html'>&lt;div&gt;Whew, finally got to clean up almost all the frenchisms from the code...&lt;/div&gt;&lt;br /&gt;As promised earlier, here is a PHP code snippet to fetch data from the Pachube web service using their API. If this is the first time you are using a web service, there is something you need to know first : web services don't run for free. So even if you are paying for some service, it does not mean you can abuse it by querying for some information every second.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As any API-backed service, Pachube will require you to sign-up in order to get your API-key that can be used in your scripts. This key is identifying you and must thus not be handed around. For those who do not have an account, obviously go ahead and create one. You might want to start with a 'Basic' plan which is free, until you find that you are reaching the limits of the system and want to switch to something more beefy.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When you're done registering, you need to create an API key for use by the PHP script. One way to go is to use the master API key in your script but this is not such a great idea. Instead, create a "secure sharing key" so that if someone gets to see your code, he won't be able to do much to your existing feeds and so on. You can find these options on the right-hand side menu of the Pachube website, after you have logged-in. It is called "My API keys" and resides withing the "My account" section. Now that you have created some key with at least the 'GET' permission, write it down, we'll use it later.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://3.bp.blogspot.com/-GOlA2bvcGEU/TkSU3l-umOI/AAAAAAAAAII/z_MKyGK0Hc8/s400/pachube_site-af.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5639796316183632098" style="float: right; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 10px; cursor: pointer; width: 302px; height: 163px; " /&gt;&lt;div&gt;Now the other thing to take into account is, you only have a limited number of queries available over time. Depending on the web service provider, the type of account (free vs premium for example) and other likely parameters, you can find out this number. In the case of the Pachube Basic account, the limit is 5 requests per minute. I wanted to update some Geiger counter reading every 5 minutes, so this is plenty enough, great ! Here is how it looks on our PTA web site, pretty cool huh ?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;How we are going to deal with this in the code is by caching the web server response. The example I am showing here is very crude, but at least it works and respects the web service netiquette by not flooding the server with superfluous requests.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Another final word about web services : JSON. This stands for JavaScript Object Notation. It used to be a very convenient way for service to return data, because you would just get a bit JS code that once evaluated would have populated your namespace with the data you had requested. Obviously, evaluating data returned by a service that can potentially host data created by malicious users is never a good idea. Well, we are doing PHP anyway so we don't care, plus PHP provides json parsing functions. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now let's have a look at the code :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #abcdef"&gt;&lt;br /&gt;&lt;pre&gt;$json = file_get_contents('json.txt');&lt;br /&gt;&lt;br /&gt;$flux = json_decode($json);&lt;br /&gt;&lt;br /&gt;$right_now = new DateTime();&lt;br /&gt;$seconds_now = $right_now-&amp;gt;format('U');&lt;br /&gt;$json_cache_date = new DateTime($flux-&amp;gt;datastreams[0]-&amp;gt;at);&lt;br /&gt;$seconds_then = $json_cache_date-&amp;gt;format('U');&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;What we have here is pretty simple. We open the cached json data (once again, crude example, this should probably be stored in a better place like your website database, and named in a more multi-feeds friendly way) and extract the information about when this data was returned. This is specific to Pachube's data format, other web services&lt;br /&gt;might store this information in another place/way. We also generate information about current time, for comparison. Both times are expressed in epoch unit, which is a number of secondes elapsed since a specific event (guess which :P).&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #abcdef"&gt;&lt;br /&gt;&lt;pre&gt;if ( (($seconds_now - $seconds_then) &amp;gt; 300) || (property_exists($flux, 'errors')) )&lt;br /&gt;{ /* fetch and cache JSON data from feed every 5 minutes */&lt;br /&gt;$request = curl_init();&lt;br /&gt;curl_setopt($request, CURLOPT_URL, "http://api.pachube.com/v2/feeds/26485.json");&lt;br /&gt;curl_setopt($request, CURLOPT_HTTPHEADER, array("X-PachubeApiKey: your_own_key") );&lt;br /&gt;curl_setopt($request, CURLOPT_RETURNTRANSFER, TRUE);&lt;br /&gt;curl_setopt($request, CURLOPT_BINARYTRANSFER, TRUE);&lt;br /&gt;$json = curl_exec($request);&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Now we have some check about whether the data should be fetched again or not. The interval I chose is 5 minutes because it does not really make sense to get the radiation reading in realtime except for some specific events from March. If the data is stale, we build the web service request using the curl library. Note the line that adds a header with your API key. This is where you should put the information you wrote down earlier. Don't forget the space between the double-colon and the start of your key. When the request is built, we throw it at the Pachube API server and get ready to handle the result.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #abcdef"&gt;&lt;br /&gt;&lt;pre&gt;if (($json !== FALSE) &amp;amp;&amp;amp; (curl_getinfo($request, CURLINFO_HTTP_CODE) &amp;lt; 400)) &lt;br /&gt;{   &lt;br /&gt;$flux = json_decode($json);&lt;br /&gt;if ($flux !== FALSE)     &lt;br /&gt;  file_put_contents('json.txt', $json); &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Several things can happen here. The server can return an error, it sometimes happen at night for some reasons I could not find out because I was sleeping... Or the fetching can fail if you have network connectivity problems, etc... So we check that we got an answer from the API server &lt;span style="font-weight:bold;"&gt;and&lt;/span&gt; that this answer was a real json object. In which case we cache it  and decode it.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #abcdef"&gt;&lt;br /&gt;&lt;pre&gt;if ($flux !== FALSE)&lt;br /&gt;{&lt;br /&gt;$date = new DateTime($flux-&amp;gt;datastreams[0]-&amp;gt;at);&lt;br /&gt;$date-&amp;gt;setTimeZone(new DateTimeZone("Asia/Tokyo"));&lt;br /&gt;echo 'On : ' . $date-&amp;gt;format('Y-m-d') .' at '. $date-&amp;gt;format('H:i:s');&lt;br /&gt;echo '&amp;lt;br&amp;gt;';&lt;br /&gt;echo 'value was: ' . $flux-&amp;gt;datastreams[0]-&amp;gt;current_value;&lt;br /&gt;echo ' ' . $flux-&amp;gt;datastreams[0]-&amp;gt;unit-&amp;gt;label;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Whether we got the information from the cache or from the API web server, there are cases where the data has errors, in which case you do not want to show it. But if we got the requested information, all that's left to do is parse it and push it to the user in a human readable way. Et voila !&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-6413009231758483045?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/6413009231758483045/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=6413009231758483045' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6413009231758483045'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6413009231758483045'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/08/adding-pachube-readings-to-any-php.html' title='Adding Pachube readings to any PHP website'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-GOlA2bvcGEU/TkSU3l-umOI/AAAAAAAAAII/z_MKyGK0Hc8/s72-c/pachube_site-af.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-4145090081868290975</id><published>2011-08-12T09:18:00.007+09:00</published><updated>2011-08-12T10:24:50.684+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='accelerometer'/><category scheme='http://www.blogger.com/atom/ns#' term='xbee'/><category scheme='http://www.blogger.com/atom/ns#' term='funscience'/><title type='text'>Accelerometer + Xbee = geekish fun</title><content type='html'>&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span"  &gt;Hi there, I hope you are all having a nice holiday season. &lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" &gt;As for me, I am keeping quite busy despite the loneliness and am desperately trying to do my job, some volunteer help for the Tohoku area, turning the website for our PTA upside-down, transforming a two storeys (stories?) open room type house in a 3+LDK, and helping out my lil brother on his science assignment. &lt;/span&gt;And there's today's story. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://4.bp.blogspot.com/-Buh4Ptzry6k/TkR3VA4Vz4I/AAAAAAAAAHw/nxzFY_S_Tcs/s320/Water_rocket_nasa.gif" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 241px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5639763836271972226" /&gt;&lt;div&gt;So introduce my brother, who has been playing with water rockets since he was in high school. Now for his first year at university he managed to get himself a science assignment dealing with those&lt;/div&gt;&lt;br /&gt;&lt;div&gt; very things. I won't explain the principle at hand here because I already have lots of things to say, so look up wikipedia (I suggest reading the discussion page there too, it is abysmal in epic proportions) or check out this NASA picture.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now you can imagine that you can do lots of fun stuff with your own rocket, especially when you learn that the record height achieved is around 600 meters... Well, a 2L soda bottle won't go that high, but it is still a very interesting way to conduct extreme experiments around embedded/autonomous systems.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When I was around the parents' home back in France, he tells me about his latest experiments&lt;/div&gt;&lt;div&gt; and how they thought they wanted to get telemetry readings for the system. That sounded cool, and I was thinking about my co-worker here who does all those neat things with arduinos, xbees, sensors and so on...&lt;/div&gt;&lt;div&gt;&lt;img src="http://1.bp.blogspot.com/-_xrW-Z37nqg/TkR5O0YvguI/AAAAAAAAAH4/agw8ItEdcZ4/s320/digi_XBee-PRO%25E2%2584%25A2_ZNet_2_.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5639765928862253794" style="float: right; margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 10px; cursor: pointer; width: 320px; height: 320px; " /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Actually, my brother and his friends' main skills are neither geekygadgetry nor computer science, so the final picture is not as complex as I imagined, but still beyond their reach. Based on a survey around his friends and professors, he gathered that Xbees are cool and can work in an autonomous way without any microcontroller, which is good when you don't have a clue. They are small chips (see pic on the right) that do 802.15.4, present a serial emulation to the user, feature 5 analog inputs and an associated ADC, and have a decent (depending on your own definition of decent) sampling frequency.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Well, to be honest he actually told me about this all on the phone before I came back, so that I could do a small shopping trip around akiba and bring an accelerometer. There it is : &lt;a href="http://akizukidenshi.com/catalog/g/gI-01425/"&gt;KXM52-1050&lt;/a&gt;, straight from Akizukidenki, behind the now defunct Yamagiwa/Livina (just saw they were doing some construction work there, something happening soon I guess). So this little chip eats 3.3V which is all great because most of the boards that can host the Xbee provide a 3.3v regulator to feed the sensors. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now here's his plan : one Xbee on the rocket, with some form of power supply, hosted on a regulated board, where to hook the accelerometer sensor as well. On the receiving side, another Xbee (using just one doesn't make sense, does it ?) on a USB board plugged directly into a computer, and voila. It sounded so &lt;b&gt;EASY.&lt;/b&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;Now that I look back on the whole process, it was. But for some reasons, the Xbee manufacturers went through great pain to write a very detailed yet completely useless documentation. All the information needed is inside, but after reading the whole 68 pages, I felt like I did not know what to do. Also there has been several versions of the chip, things changed, and there is no clear history of what went and what didn't. One important thing I learned at my expense is that the ADC &lt;b&gt;used to do the conversion on the fixed 0~1.2V range only&lt;/b&gt;. But, in the latest document there is no mention about the voltage range. There is a two-line section about ADC that states that "Xbee supports ADC and here is how to enable it". Period. After lots of digging I found out that the "Pin signals" table stated that &lt;b&gt;Pin14 is for "Voltage reference for A/D input"&lt;/b&gt;. If the 68 pages were a haystack, this line would be the needle. &lt;/div&gt;&lt;br /&gt;&lt;div&gt;And then, the plan worked ! That is, until I saw the "software" that some friend gave to him in order to do the Xbee monitoring. If you can call a VB 20-liner a software, that is. Which is way I made another one for him that does .csv export and much more. More on it in another article but meanwhile, enjoy the output. Guess which line's the Z ?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;a href="http://2.bp.blogspot.com/-UtY2qumVcdk/TkSAjg4JbAI/AAAAAAAAAIA/6IISVZFkJy4/s1600/accelerometer-plot-2011_8_12-10_21_34.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img src="http://2.bp.blogspot.com/-UtY2qumVcdk/TkSAjg4JbAI/AAAAAAAAAIA/6IISVZFkJy4/s400/accelerometer-plot-2011_8_12-10_21_34.png" border="0" alt="" id="BLOGGER_PHOTO_ID_5639773980983913474" style="cursor: pointer; width: 400px; height: 300px; " /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PS: I know I am getting behind schedule with the follow-up to the pachube article. It is still in the pipeline...&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-4145090081868290975?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/4145090081868290975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=4145090081868290975' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4145090081868290975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4145090081868290975'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/08/accelerometer-xbee-geekish-fun.html' title='Accelerometer + Xbee = geekish fun'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-Buh4Ptzry6k/TkR3VA4Vz4I/AAAAAAAAAHw/nxzFY_S_Tcs/s72-c/Water_rocket_nasa.gif' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-7117194434596154341</id><published>2011-06-07T07:45:00.006+09:00</published><updated>2011-08-12T11:58:18.981+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='iot'/><category scheme='http://www.blogger.com/atom/ns#' term='radiation'/><category scheme='http://www.blogger.com/atom/ns#' term='japan'/><title type='text'>The internet of things is good for your health</title><content type='html'>&lt;br /&gt;&lt;a href="http://www.pachube.com/images/ui/logo.png?1306931235"&gt;&lt;/a&gt;At some point, the "Internet of Things" (IoT) was a quite  popular topic. I guess they lost the buzz war against the clouds but  yeah, it's a fight you'll never win... However, the whispering shadows  of sensor mania and IoT can still be heard if you listen closely. And,  IoT can actually be good for your health !&lt;br /&gt;&lt;br /&gt;&lt;img src="http://4.bp.blogspot.com/-occ2GvX6nuI/TkSWhywWDWI/AAAAAAAAAIQ/DPVLWIsKOd4/s320/pachubelogo.png" style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 238px; height: 80px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5639798140679097698" /&gt;&lt;br /&gt;As a concept, IoT is  as loosely defined as "cloud", but what did you expect from a buzz war  contender anyway ? For this article we will focus on an instance of a  very specific IoT concept and platform, called pachube. In just one  sentence, Pachube is a web service that  provides centralized hosting for sensor data. As most web services it  is rate limited, and offers different limits based on the premium you  pay. There is also a free service.&lt;br /&gt;&lt;br /&gt;On the other hand, I guess  that by now most of the people reading this have learned about the twin  disaster that hit Japan, followed by both an unlikely nuclear meltdown  and unfortunate radioactive leaks in the air, soil and water. In this  context, people suddenly realized about Geiger counters and they quickly  sold out. A few brave people put theirs on the web, through various  means (digitizer software, webcams, etc...).&lt;br /&gt;&lt;br /&gt;Now this is the kind  of Thing that can go into the Internet of Things. So a few of the  people that had digital probes or probes with digitizer software set up a  pachube account to host measurement data. Then someone stepped forward  to put together a user interface for all those values and plot  near-realtime measurements on a map. Here it is :  http://japan.failedrobot.com&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Next I will show you how to get some values from pachube to put on display in your own webpage, so stay tuned...&lt;br /&gt;&lt;br /&gt;&lt;a href="http://202.232.15.100/geigermap.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 617px; height: 313px;" src="http://202.232.15.100/geigermap.png" alt="" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-7117194434596154341?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/7117194434596154341/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=7117194434596154341' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/7117194434596154341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/7117194434596154341'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/06/internet-of-things-is-good-for-your.html' title='The internet of things is good for your health'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/-occ2GvX6nuI/TkSWhywWDWI/AAAAAAAAAIQ/DPVLWIsKOd4/s72-c/pachubelogo.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-6657728206596164276</id><published>2011-04-18T10:19:00.015+09:00</published><updated>2011-04-18T11:46:15.473+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='fuzzy computing'/><category scheme='http://www.blogger.com/atom/ns#' term='touchscreen'/><title type='text'>User interfaces gone fuzzy, a case against new interaction devices</title><content type='html'>So this is a rant about all the trendy new interaction devices. In fact, not so much against the devices themselves, but the way people keep trying to use them to emulate old things.&lt;br /&gt;&lt;br /&gt;Our knowledge, our science, our tools have been built in an incremental way. Of course, who would invent a spanner when nuts and bolts don't exist ? And even though sometimes, someone has a great idea that is very far-fetched, it also often meets with doubts and perplexity. This is how we just avoided getting computers 100 years early, which might have bumped human technology on a very different path.&lt;br /&gt;&lt;br /&gt;And so this is how after getting computers and monitors, people feeling the urge to interact with those beasts soon made out the keyboard, and then the mouse. For a very long time keyboard and mouse have reigned supreme over the world of user interfaces.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-Wwq6I_KXXhg/TaubN8ByxbI/AAAAAAAAAD8/PNalunDn4hE/s1600/HypertextEditingSystemConsoleBrownUniv1969.jpg"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 247px;" src="http://3.bp.blogspot.com/-Wwq6I_KXXhg/TaubN8ByxbI/AAAAAAAAAD8/PNalunDn4hE/s320/HypertextEditingSystemConsoleBrownUniv1969.jpg" border="0" alt="Hypertext Editing System. Original photo by Greg Lloyd" title="Hypertext Editing System. Original photo by Greg Lloyd" id="BLOGGER_PHOTO_ID_5596737625692226994" /&gt;&lt;span style="clear: left; float:left; text-decoration: none; color: #333333; font-size: 10px; width: 320px;"&gt;Hypertext Editing System.&lt;br&gt;Original photo by Greg Lloyd&lt;br&gt;source: wikipedia&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/a&gt; Of course there had been attempts at alternative ways, but these interfaces never took off and were doomed to stay a niche market. Probably a few schoolboys and girls from the 80s in France remember the Thomson light pen&lt;a href="http://en.wikipedia.org/wiki/Light_pen"&gt;&lt;/a&gt; ? And there have been graphical tablets for decades now, and people using 3DVR stations have those gloves, and videogames have their own things filled with buttons.&lt;br /&gt;&lt;br /&gt;But we all know the latest trend that seems to take off for real, is touch screens. This is not the dawn of touch interfaces, it has been pioneered for long by the graphics industry. Despite a few attempts at PDAs and smartphones (P900 anyone ?) that were expensive toys, the widespread use of touch devices has more likely begun with the nintendoDS and then the iPhone.&lt;br /&gt;&lt;br /&gt;So what's wrong with touch devices ? I would say feedback. When you learnt to use a keyboard for so long, feedback is what makes you know you mistyped even before seeing it. This does not happen with touchscreen emulated keyboards. Now worse, the software thinks it is smart enough to guess what you intended to type, even in some situations where you did *NOT* make a mistake.&lt;br /&gt;&lt;br /&gt;This is all because we want to use touchscreens the way we used keyboards. But touchscreens will never be keyboards, they are screens ! Kids like to look at pictures and slide them to see the next one. This is intuitive and cool. Probably the kids born around now will never have to use a real keyboard and won't miss it. But for me, as much as the mouse supplements the keyboard but can't substitute to it, so much can be said about the touchscreen. How many people use mouse emulation with the numpad ?&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-UO2Pcn7Gwgs/TauiuVvAupI/AAAAAAAAAEE/svXSDZ8EQnU/s1600/deduplication.png"&gt;&lt;img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;width: 320px; height: 280px;" src="http://3.bp.blogspot.com/-UO2Pcn7Gwgs/TauiuVvAupI/AAAAAAAAAEE/svXSDZ8EQnU/s320/deduplication.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5596745878929980050" /&gt;&lt;span style="clear:right; float:right; text-decoration: none; color: #333333; font-size: 10px; width: 320px"&gt;Don't type technical words !&lt;br&gt;&lt;br&gt;&lt;/span&gt;&lt;/a&gt; This all-touch trend, I call it "fuzzy interface". And by the way, I find it much more straining to type on the touchscreen because you have to check continuously that no error has been made, either by you OR the software. Here is an anecdote to close this case, redacted from a Google Summer of Code mailing list for mentors :&lt;br /&gt;&lt;br /&gt;. Random person says ''company XYZ can help assess candidate students abilities blablabla....''&lt;br /&gt;. Person in charge from Google answers ''actually I am hot interested in other companies reviewing our students..."&lt;br /&gt;... 8hrs later, same Google person : ''Not, not hot. Touch screen keyboard :-)"&lt;br /&gt;&lt;br /&gt;Happy touching !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-6657728206596164276?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/6657728206596164276/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=6657728206596164276' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6657728206596164276'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6657728206596164276'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/04/user-interfaces-gone-fuzzy-case-against.html' title='User interfaces gone fuzzy, a case against new interaction devices'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-Wwq6I_KXXhg/TaubN8ByxbI/AAAAAAAAAD8/PNalunDn4hE/s72-c/HypertextEditingSystemConsoleBrownUniv1969.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-6743339748619469433</id><published>2011-01-06T15:29:00.004+09:00</published><updated>2011-01-07T10:52:37.727+09:00</updated><title type='text'>Best wishes for 2011</title><content type='html'>Hi dear readers, and welcome to the year 2011 (of the cute bunny) that should hopefully be more peaceful than year 2010 (of the tiger).&lt;br /&gt;&lt;br /&gt;As some people might know, my hobbies include (a lot of) cooking so it is with a recipe that I am going to kick off the new year. All ingredients can be bought here in Japan, so you can probably cook this one almost everywhere in the world.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;First, the ingredients :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;. 2 pie sheets&lt;br /&gt;. 100g sugar&lt;br /&gt;. 100g almond powder&lt;br /&gt;. 50g butter&lt;br /&gt;. 2 eggs&lt;br /&gt;. Rum or any other flavor (e.g. vanilla essence)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Preparation :&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;. Place butter, sugar, almond powder and eggs in a bowl (in that order)&lt;br /&gt;. Mix slowly (especially if using an electric appliance)&lt;br /&gt;. When the dry ingredients start getting wet, add flavor and mix faster (to obtain an emulsion)&lt;br /&gt;. This emulsion is the almond cream&lt;br /&gt;&lt;br /&gt;. Cut two round shapes from the pie sheets, one being bigger than the other&lt;br /&gt;. The small diameter disk is the bottom of the pie, the large one will be the lid&lt;br /&gt;. Wet the outer part of the small disk (so that the lid will stick when you lay it on top)&lt;br /&gt;. Spread the almond cream in the center&lt;br /&gt;. Insert a bean or anything hard that can withstand oven temperature&lt;br /&gt;. Lay the larger disk on top and weld it on the small disk around the cream so that it doesn't leak (you can use a round cake mold for example to do that)&lt;br /&gt;. "Flute" the edges, by pushing with your finger and chipping with the point of a knife, repeat this all around the disk&lt;br /&gt;. Drill a small hole a the center so that vapor can leave the pie without making the whole thing burst&lt;br /&gt;. Beat another egg and spread it on the pie, then do some fancy drawings with the point of your knife&lt;br /&gt;. Let it dry then spread the beaten egg again&lt;br /&gt;. Bake at 200C for 10 mins, then at 170C for 20 mins&lt;br /&gt;&lt;br /&gt;You're done, enjoy.&lt;br /&gt;&lt;br /&gt;Small cultural note : this pie is called "La galette des rois" and is connected to the christian celebration of "Epiphany", somewhat related to the persons who visited baby Jesus to bring him presents. &lt;br /&gt;&lt;br /&gt;In our family, this pie is just linked to January 6th and a good way to stuff our stomach !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-6743339748619469433?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/6743339748619469433/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=6743339748619469433' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6743339748619469433'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6743339748619469433'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2011/01/best-wishes-for-2011.html' title='Best wishes for 2011'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-963582931026474046</id><published>2010-08-31T15:59:00.001+09:00</published><updated>2011-01-06T15:10:39.108+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='reader'/><category scheme='http://www.blogger.com/atom/ns#' term='camera'/><category scheme='http://www.blogger.com/atom/ns#' term='read.air'/><category scheme='http://www.blogger.com/atom/ns#' term='wifi'/><category scheme='http://www.blogger.com/atom/ns#' term='iphone'/><title type='text'>read.air : How to sort a "Vacances" worth of pictures on-the-go ?</title><content type='html'>This is the story of a pet project I called read.air. &lt;br /&gt;&lt;br /&gt;So the holidays are nearing the end, and I am so happy that I am back to Tokyo for the hot days. When I say I am going to take 3 weeks off, people here dub it "vacances" (read: bakansu) because apparently French people are customary to long holidays, so much so that the name has been borrowed.&lt;br /&gt;&lt;br /&gt;More alarmingly, my wife has been gone for 2 months with a borrowed SLR digital camera (thanks to the generous sponsor by the way). So this means that instead of having thousand of pictures piling up in the iphone camera roll, they are now piling up on SD cards. She took around 4 or 5 of these 4Gb cards and since she is experimenting with the camera a lot, there are many many blurry, over/under-exposed, or just failed pictures.&lt;br /&gt;&lt;br /&gt;As convenient as the back panel LCD might be, it is not as efficient as handling them from a much more powerful touch device, however I hate it. Also, the designers of the iphone did a perfect job at crippling it as far as interoperation is concerned. So how do you read a SD card with an iphone ? You don't. &lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;When I surveyed the electronic products market for such a thing, I found out that there were one or two products that could read an SD card and plug on the iphone connector on the bottom, but they relied on proprietary apps and also there was no review or preview video to be found. I am not going to buy without a try, and it was nowhere to be found in shops, online retail only, send money first. No way.&lt;br /&gt;&lt;br /&gt;So another product I found out was the AirStash and I have to admit I had been thinking about something like this for months but never got "unlazy" enough to actually build it. In fact, I got the idea nagging at the back of my mind everyday when I was looking at the unused FONera router on my desk at the office. The Airstash price tag at 100$ was the carrot I needed because I knew that I did not want to pay this price, and also that my wife would make me buy one if "read.air" was not ready before she left...&lt;br /&gt;&lt;br /&gt;Now one thing I didn't need in this AirStash was the harddisk. I just wanted a SD card-reader over WiFi that would be accessed by Web interface. This means no proprietary app, just plain old Safari.&lt;br /&gt;&lt;br /&gt;So in the end, if you have a FON router (it is now an old model, also they used to be almost free at some point) all you need to do is buy a USB card reader, 4 regular batteries (I'm using eneloops from sanyo) and some wires and plugs. Overall much below 100$. Mission accomplished, yay !&lt;br /&gt;&lt;br /&gt;Next time I will tell you about some custom software I wrote for read.air, which is based on OpenWRT.&lt;br /&gt;&lt;br /&gt;NOTE: I will add a pic of the thingie whenever I find one or she comes back, whichever happens first.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-963582931026474046?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/963582931026474046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=963582931026474046' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/963582931026474046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/963582931026474046'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/08/readair-how-to-sort-vacances-worth-of.html' title='read.air : How to sort a &quot;Vacances&quot; worth of pictures on-the-go ?'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-6065172715440427895</id><published>2010-07-02T15:28:00.003+09:00</published><updated>2011-01-06T15:19:44.217+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='standards'/><category scheme='http://www.blogger.com/atom/ns#' term='gsoc2010'/><category scheme='http://www.blogger.com/atom/ns#' term='floating-point'/><title type='text'>Floating point (of no return)</title><content type='html'>As the song goes "No return, from the other side of Heaven". And indeed, welcome to Floating Point Hell !&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_ElrrxmlK4Oc/TC2E0HL2xZI/AAAAAAAAACQ/0e2iFPMvLBo/s1600/gsoc2010.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img src="http://2.bp.blogspot.com/_ElrrxmlK4Oc/TC2E0HL2xZI/AAAAAAAAACQ/0e2iFPMvLBo/s200/gsoc2010.png" border="0" height="178" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;I recently got involved in GSoC (Google Summer of Code, ask Google web search for the homepage) helping a student make Wideband audio codec become a reality in &lt;a href="http://www.sip-communicator.org/"&gt;Sip Communicator&lt;/a&gt;. Which is a Java application.&lt;br /&gt;&lt;br /&gt;And as expected from such a mathematical object, one needs to do all kind of clever calculations to compress a high rate audio source to a low rate bitstream. Of course, nowadays we receive a lot of support from the FPU making this all a piece of cake, with respect to calculation speed.&lt;br /&gt;&lt;br /&gt;So, what's the big deal ? Let's see, as usual, it all begins with a standard. And a good one at that, the IEEE 754 standard. The problem with this standard is how it defines several bit format for floating point numbers, and how people decided, or not, to implement them.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;And of course, as for most of the hardware things, there is a software counterpart that can start ruining things all the same. Well, the opposite is true and you can ruin good software with horrible hardware, but we are getting side tracked.&lt;br /&gt;&lt;br /&gt;So, the wideband codec I am thinking about is &lt;a href="http://www.celt-codec.org/"&gt;CELT&lt;/a&gt; and I must say that it is pretty interesting, and much more geeky than the streamlined SILK codec (the one behind skype, also available to developers, kind of).&lt;br /&gt;&lt;br /&gt;And a part of CELT implements mdct for some reason, and includes a test program. You don't see test-units for C code so often, the last I can think of where in NS (the network simulator) and I can't say it left me with any good keepsake.&lt;br /&gt;&lt;br /&gt;So I try to run them, and guess what ? Results can differ. A lot. But not from one run to another, rather from one 'configuration' to another. For example, I get different results depending on the operating system. Or the compiler flags. An imac gives results that differ from a dell server (although they have the same FPU), which can themselves differ depending on the compiler flags I am using.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_ElrrxmlK4Oc/TC2HMFg7ugI/AAAAAAAAACY/bYxCof5hph8/s1600/sc_logo47x70.gif" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"&gt;&lt;img src="http://3.bp.blogspot.com/_ElrrxmlK4Oc/TC2HMFg7ugI/AAAAAAAAACY/bYxCof5hph8/s320/sc_logo47x70.gif" border="0" /&gt;&lt;/a&gt;&lt;/div&gt;In the end, the reason I realized this is because this student tries to adapt libcelt (the CELT codec in a library form) to Sip Communicator, and gets very bad results when running the test. Not that bad, but much worse than the C counterpart. On the same hardware+OS obviously, or it wouldn't be fun.&lt;br /&gt;&lt;br /&gt;The final word ? Floating point calculation seems to have been historically complicated (see references below) in the Java VM and it resulted in the current situation with FP-Strict and so on.&lt;br /&gt;&lt;br /&gt;Technical explanation : actually, on x86 machines, the FPU supports the extended double-precision format that specifies at least 80 bits numbers. This being available, all calculations are done using the highest precision by the hardware, then rounded before being handled back to the software.&lt;br /&gt;&lt;br /&gt;The thing is, this setting can be disabled, and probably has been, in some of the configurations that produce different results. Including within the JVM, although it sounds like it could be configurable according to the Java Language Specification (i.e. how Java should be, not always how it is practically).&lt;br /&gt;&lt;br /&gt;Well, I had already had a glimpse of the FP woes that plague Java when doing the ilbc codec implementation, where I realized that C and Java implementations gave different results for the same sample data. I solved the problem by deciding that 'to my ear' the difference is inaudible.&lt;br /&gt;&lt;br /&gt;This is probably the way to go, geez.&lt;br /&gt;&lt;br /&gt;Further reading material, if you want to have some floating fun :&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Ye olde &lt;a href="http://www.cs.berkeley.edu/%7Ewkahan/JAVAhurt.pdf"&gt;How Java Floating Point Hurts Everyone Everywhere&lt;/a&gt; by William Kahan, that might not make the test-of-time award, but sounds so nostalgic. Remember the Sun vs Microsoft Java war...&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.network-theory.co.uk/docs/gccintro/gccintro_70.html"&gt;The floating point chapter&lt;/a&gt; of the 'Introduction to GCC' book&lt;/li&gt;&lt;li&gt;A good &lt;a href="http://hal.archives-ouvertes.fr/docs/00/28/14/29/PDF/floating-point-article.pdf"&gt;technical article&lt;/a&gt; on Floating Point computations, aimed at what can (will?) go wrong&lt;/li&gt;&lt;li&gt;This webpage on the Sun/Java website with the simple title of "&lt;a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html"&gt;What Every Computer Scientist Should Know About Floating-Point Arithmetic&lt;/a&gt;" and apparently triggered by a W. Kahan lecture&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-6065172715440427895?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/6065172715440427895/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=6065172715440427895' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6065172715440427895'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6065172715440427895'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/07/floating-point-of-no-return.html' title='Floating point (of no return)'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_ElrrxmlK4Oc/TC2E0HL2xZI/AAAAAAAAACQ/0e2iFPMvLBo/s72-c/gsoc2010.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-4813472350736319611</id><published>2010-05-06T16:07:00.001+09:00</published><updated>2011-01-06T15:20:20.273+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='debian'/><category scheme='http://www.blogger.com/atom/ns#' term='socket'/><category scheme='http://www.blogger.com/atom/ns#' term='ipv6'/><category scheme='http://www.blogger.com/atom/ns#' term='setsockopt'/><title type='text'>Debian, IPv6 and ... Java ?</title><content type='html'>Today is the first time for me to talk about Debian. It has been my favorite Linux flavor for quite some time now. I would say at least ten years, when compiling stuff became less fun and more painful, or my spare time ran out. I don't know exactly.&lt;br /&gt;&lt;br /&gt;But whatever the cause, I ditched compiling everything in favor of the flexibility (and frustrating nature at times) of a packaging system. At that time, RPM did not prove better than Slackware's plain .tar.gz packaging and although dselect could be stubborn at times, it soon got better with apt-get and friends.&lt;br /&gt;&lt;br /&gt;Let's add IPv6 to this landscape.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;I discovered the details of this tentative IPv4 replacement protocol at around the same time I got acquainted with Debian. I will not try to cover the details of why IPv6 is better (or not) and why it takes so long to deploy (or not) but just make sure that you know the following important thing : IPv6 is &lt;b&gt;not&lt;/b&gt; designed to be a drop-in replacement for IPv4, but is made so that it closely resembles.&lt;br /&gt;&lt;br /&gt;And this is probably a very important point in today's mess. Being close enough, it might make people think that it takes a one-liner to update everything. Or just a new board/firmware for the router.&lt;br /&gt;&lt;br /&gt;Let's focus on applications on Linux.&lt;br /&gt;&lt;br /&gt;IPv6 API uses sockets, much like IPv4, and even uses the same calls for the basic socket creation, binding, listening and so on. Of course, the upper protocols are not modified, which means that UDP, TCP and friends still work.&lt;br /&gt;&lt;br /&gt;When binding a socket with the AF_INET6 family, it is specified that the socket can be bound to both IPv4 and IPv6 address spaces. Really ? Yes, probably as a means to make it easier for people to port applications, the system will start listening on both families and you only have to create one socket.&lt;br /&gt;&lt;br /&gt;This is made possible by adding a specific format for the IPv4 address which is called IPv6-mapped-IPv4 address. Basically it means that the 32 bits of the IPv4 address are mingled with a special meaning IPv6 prefix. Then you just check on those bits and figure if the incoming connection is IPv4 or IPv6, if you ever care. Which you should.&lt;br /&gt;&lt;br /&gt;So how do we enable (or disable) this behavior ? That is the very reason of this post : the default behavior is undetermined. In fact, the default behavior depends on a sysctl value. So imagine you are a software developer, you made a software assuming that dual-stacked sockets were the default. Now imagine that the Linux distribution you (or your user) runs has a different setting. Or even better, changes the setting at some point. This is what happened for Debian.&lt;br /&gt;&lt;br /&gt;This is exactly what happened. The variable is called net.ipv6.bindv6only and used to be 0, i.e. a AF_INET6 socket is bound to both v4 and v6. When it changed, it took people a little bit of unpleasant time to find out why the Java VM provided by Sun decided to stop working and report a network connection error. The thing is, the vm listens on some port on localhost and while using IPv4 as a default mean of connection, the socket was probably created with AF_INET6 family to help support both IPv4 and IPv6 (just guessing).&lt;br /&gt;&lt;br /&gt;To sum it all up, &lt;b&gt;man&lt;/b&gt; is your friend in the coding world : &lt;i&gt;man ipv6&lt;/i&gt; should provide you with all the necessary information. Now if you want to stick to the old style, you have two solutions.&lt;br /&gt;&lt;br /&gt;The first solution is to update the sysctl config file in /etc/sysctl.d folder. You will find the file under the name bindv6only.conf&lt;br /&gt;&lt;br /&gt;But this is an ugly workaround. As we all learned when writing our first C code program dealing with int arrays, there should be no hard-coded value for anything (at that time, I believe the teacher was referring to the define directive that decided how large the array was).&lt;br /&gt;&lt;br /&gt;To fix it properly, we need to stop expecting other people's system to work like ours. Since the default behavior is undefined because of a sysctl value, we can force the behavior we want with a simple setsockopt call. Indeed !&lt;br /&gt;&lt;br /&gt;This brings us to the morale of this story :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; int arg = 1;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; setsockopt(fd6, IPPROTO_IPV6, IPV6_V6ONLY, &amp;amp;arg, sizeof(arg));&lt;/div&gt;&lt;br /&gt;which makes sure that the socket listens only on IPv6. Which prevents you from receiving a bind error in case another program listens on the same port in the IPv4 address space, and at the same time allows to receive IPv4 and IPv6 traffic on two separate sockets if you so wish.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-4813472350736319611?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/4813472350736319611/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=4813472350736319611' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4813472350736319611'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4813472350736319611'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/05/debian-ipv6-and-java.html' title='Debian, IPv6 and ... Java ?'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-3858214627131185750</id><published>2010-03-15T16:05:00.003+09:00</published><updated>2011-01-06T15:20:42.450+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network interface'/><category scheme='http://www.blogger.com/atom/ns#' term='netlink'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='rtnetlink'/><title type='text'>Howto get a list of network interfaces in Linux, part 3</title><content type='html'>Here we are, this is the ultimate post from these series. Thanks both previous posts, we are now able to get a list of interfaces using any language from shell script to whatever language which can speak &lt;i&gt;''sockets''&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;However, as we could realize earlier, the ioctl-based method does not work exactly the way we want, because it does only report IP enabled devices. So if you want to deal with network interfaces before they start running, you are stuck with the /proc method. There must be another way. Remember that &lt;i&gt;man netdevice&lt;/i&gt; we did last week. They mentioned netlink... What are those ?&lt;br /&gt;&lt;br /&gt;Netlink sockets are sockets from the AF_NETLINK family. Being sockets, they are used to communicate between two addresses. The fun part is, netlink communications are local. And they usually (in the most simple scenario) link a user process with the kernel, especially the networking stack of the kernel.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;Oh great, so we could query the kernel directly, to find out the contents of the global list of interfaces ? Indeed, we will. And since this tutorial is the most tricky of all three, let's have a detailed look at the source code. You can always grab the full source by following the link at the bottom of this post.&lt;br /&gt;&lt;br /&gt;First we will open a socket :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;int fd; &lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;(...)&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);&lt;/div&gt;&lt;br /&gt;We already discussed about the socket family, the type should be set to SOCK_RAW (the only one that makes sense here anyway) and the protocol is NETLINK_ROUTE. Why _ROUTE ? There are a few netlink protocols, each dealing with a specific part of the networking stack. NETLINK_XFRM deals with the transform layer used by security and mobility stacks, for example. And the protocol we chose deals with both routes and links.&lt;br /&gt;&lt;br /&gt;Now we have to bind that socket. Netlink addresses are based on process ID, so let's do that :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;struct sockaddr_nl local; &lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;(...) &lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(&amp;amp;local, 0, sizeof(local));&lt;br /&gt;local.nl_family = AF_NETLINK;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;local.nl_pid = pid; /* can be obtained using getpid*/&lt;br /&gt;local.nl_groups = 0;&lt;br /&gt;&lt;br /&gt;if (bind(fd, (struct sockaddr *) &amp;amp;local, sizeof(local)) &amp;lt; 0)&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;... error handling ...&lt;/div&gt;&lt;br /&gt;If an error occurs it might mean that you are not running the program as super-user or with sufficient rights, or that netlink support is missing in the kernel. And if the &lt;i&gt;bind&lt;/i&gt; system call is successful, we can now start sending requests. The request we will be sending, is the one that makes the kernel answer by sending a list of all the interfaces, whatever their state.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;typedef struct nl_req_s nl_req_t; &lt;br /&gt;&lt;br /&gt;struct nl_req_s {&lt;br /&gt;&amp;nbsp; struct nlmsghdr hdr;&lt;br /&gt;&amp;nbsp; struct rtgenmsg gen;&lt;br /&gt;};&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;(...) &lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;struct sockaddr_nl kernel;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;struct msghdr rtnl_msg;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;struct iovec io;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;nl_req_t req;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;(...)&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(&amp;amp;rtnl_msg, 0, sizeof(rtnl_msg));&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;memset(&amp;amp;kernel, 0, sizeof(kernel));&lt;br /&gt;memset(&amp;amp;req, 0, sizeof(req));&lt;br /&gt;(...) &lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;kernel.nl_family = AF_NETLINK; /* fill-in kernel address (destination) */&lt;br /&gt;&lt;br /&gt;req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtgenmsg));&lt;br /&gt;req.hdr.nlmsg_type = RTM_GETLINK;&lt;br /&gt;req.hdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP; &lt;br /&gt;req.hdr.nlmsg_seq = 1;&lt;br /&gt;req.hdr.nlmsg_pid = pid;&lt;br /&gt;req.gen.rtgen_family = AF_PACKET; /*&amp;nbsp; no preferred AF, we will get *all* interfaces */&lt;br /&gt;&lt;br /&gt;io.iov_base = &amp;amp;req;&lt;br /&gt;io.iov_len = req.hdr.nlmsg_len;&lt;br /&gt;rtnl_msg.msg_iov = &amp;amp;io;&lt;br /&gt;rtnl_msg.msg_iovlen = 1;&lt;br /&gt;rtnl_msg.msg_name = &amp;amp;kernel;&lt;br /&gt;rtnl_msg.msg_namelen = sizeof(kernel);&lt;br /&gt;&lt;br /&gt;sendmsg(fd, (struct msghdr *) &amp;amp;rtnl_msg, 0);&lt;/div&gt;&lt;br /&gt;Okay, so this is the longest piece of code we will be quoting here. First we need to define a structure that can hold our specific message, since netlink can encapsulate so many things, we need to give some structure for this encapsulation. This the the &lt;i&gt;nl_req_t&lt;/i&gt; type we just defined.&lt;br /&gt;&lt;br /&gt;Then we prepare the destination address for our message. As expected, it is the ''kernel'' address which is specified by all zeroes except the family that is set to AF_NETLINK.&lt;br /&gt;&lt;br /&gt;Now we prepare our request. It has a header, and a single message. The header follows the &lt;i&gt;struct nlmsghdr&lt;/i&gt; format. In this structure, we will fill information about :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;the message type : RTM_GETLINK, obviously used to get information about links.&lt;/li&gt;&lt;li&gt;the message length. For this, we use the NLMSG_LENGTH macro that makes some alignment calculation and also accounts for the header length. We thus have to pass the size of the payload only, and the result will be the aligned size of the whole netlink message. Our payload is a &lt;i&gt;struct rtgenmsg&lt;/i&gt; structure, that is used to specify which address family we are interested in.&lt;/li&gt;&lt;li&gt;the message flags : NLM_F_REQUEST because we are sending a request (i.e. requiring an answer) and NLM_F_DUMP.&lt;/li&gt;&lt;li&gt;the message sequence number : not very important here because we will only send one message. Note that this number must be monotonically increasing.&lt;/li&gt;&lt;li&gt;the message pid : this is our the pid of the sending process, which as we said earlier, is related to the netlink address.&lt;/li&gt;&lt;/ul&gt;We also fill the &lt;i&gt;rtgen_family&lt;/i&gt; field of our payload structure to make sure that we receive information about &lt;b&gt;ALL&lt;/b&gt; interfaces, not only IP-related ones. Then we prepare the regular sendmsg stuff using &lt;i&gt;struct msghdr&lt;/i&gt; and &lt;i&gt;struct iovec&lt;/i&gt; friends.&lt;br /&gt;&lt;br /&gt;The message is then complete, and is sent through a &lt;i&gt;sendmsg&lt;/i&gt; call. And now, let's get ready for the answer.&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;int end = 0;&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;char reply[IFLIST_REPLY_BUFFER]; /* a large buffer */&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;(...)&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; while (!end)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int len;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct nlmsghdr *msg_ptr;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* pointer to current part */&lt;/div&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct msghdr rtnl_reply;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* generic msghdr structure */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; struct iovec io_reply;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(&amp;amp;io_reply, 0, sizeof(io_reply));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memset(&amp;amp;rtnl_reply, 0, sizeof(rtnl_reply));&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; io.iov_base = reply;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; io.iov_len = IFLIST_REPLY_BUFFER;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtnl_reply.msg_iov = &amp;amp;io;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtnl_reply.msg_iovlen = 1;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtnl_reply.msg_name = &amp;amp;kernel;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rtnl_reply.msg_namelen = sizeof(kernel);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; len = recvmsg(fd, &amp;amp;rtnl_reply, 0); /* read lots of data */&lt;/div&gt;&lt;br /&gt;This is the first part of the loop that contains most of the initialization logic. It is relying on a &lt;i&gt;end&lt;/i&gt; flag that will be updated upon receiving the message that defines an end of answer. Then &lt;i&gt;recvmsg&lt;/i&gt; structures are prepared to read a very large message. This netlink message itself can have several message in it's payload, this is why we are going to need a nested loop :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; if (len)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; for (msg_ptr = (struct nlmsghdr *) reply; NLMSG_OK(msg_ptr, len); msg_ptr = NLMSG_NEXT(msg_ptr, len))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch(msg_ptr-&amp;gt;nlmsg_type)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case 3:&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; /* this is the NLMSG_DONE end msg */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; end++;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; case 16:&amp;nbsp;&amp;nbsp;&amp;nbsp; /* this is the RTM_NEWLINK msg */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; rtnl_print_link(msg_ptr);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; default:&amp;nbsp;&amp;nbsp;&amp;nbsp; /* for education only,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; should not happen here */&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; printf("message type %d, length %d\n", msg_ptr-&amp;gt;nlmsg_type, msg_ptr-&amp;gt;nlmsg_len);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/div&gt;&lt;br /&gt;Here we use a few of those NLMSG macros, to walk the big netlink message. Basically, NLMSG_OK checks that the message specified by the parameter pointer is indeed a valid netlink message, while NLMSG_NEXT steps over a single iteration, moving from the parameter pointer current message to the next message in the netlink payload, while the global length is specified to avoid buffer overrun. Upon receiving NLMSG_DONE message, we just update our end of loop condition. And we use a separated function to print out new link information. Here it is :&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;void&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;rtnl_print_link(struct nlmsghdr *h)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; struct ifinfomsg *iface;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; struct rtattr *attribute;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; int len;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; iface = NLMSG_DATA(h);&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; len = h-&amp;gt;nlmsg_len - NLMSG_LENGTH(sizeof(*iface));&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; for (attribute = IFLA_RTA(iface); RTA_OK(attribute, len); attribute = RTA_NEXT(attribute, len))&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; switch(attribute-&amp;gt;rta_type)&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; {&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; case IFLA_IFNAME:&lt;/span&gt; &lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; printf("Interface %d : %s\n", iface-&amp;gt;ifi_index, (char *) RTA_DATA(attribute));&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; default:&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; break;&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color: #cfe2f3; font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Very simple function made of mostly a big loop. Here we can find some new macros that look a lot like the NLMSG ones. They have an equivalent behavior but are handling different data. NLMSG_ macros are handling the netlink message and allows to parse all parts of a multi-part query or request. Then, each part itself is made of several attributes (think of route information here, routes have lots of attributes, and so do links). So RTA_ stands for route attribute, and the effect of the RTA macros is identical to NLMSG ones. This allows us to loop over &lt;b&gt;ALL&lt;/b&gt; attributes of a link.&lt;br /&gt;&lt;br /&gt;Also, in order to catch the first of those RTAs, we need to know where they start. This depends on the kind of message we received, but as far as this function is concerned, the message type is known to be RTM_NEWLINK. So IFLA_RTA allows us to get a pointer to the first attribute in the RTM_NEWLINK message.&lt;br /&gt;&lt;br /&gt;For the sake of this exemple, we will only consider the interface name, but there is much more information (MTU, hardware address, link type, flags, state, etc...). You can check out &lt;i&gt;&lt;linux if_link.h=""&gt;&lt;/linux&gt;&lt;/i&gt; for more information, like the list of possible attributes.&lt;br /&gt;&lt;br /&gt;And now, let's run our example :&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: #cfe2f3;"&gt;Interface 1 : lo&lt;br /&gt;Interface 2 : eth1&lt;br /&gt;Interface 3 : wlan1&lt;br /&gt;Interface 4 : pan0&lt;/div&gt;&lt;br /&gt;Where we can see that they are all returned, including the down ones. Victory ! By the way, the number we are printing here is the interface index, that is very useful for subsequent actions, you'd better store it next to the interface name.&lt;br /&gt;&lt;br /&gt;I hope this was an interesting (long) read. Again, feel free to use this code provided you give proper credits.&lt;br /&gt;&lt;br /&gt;PS: for the lazy people who want to try it right away, here is a link to the &lt;a href="http://www.iijlab.net/%7Ejean/iflist.c"&gt;full source&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-3858214627131185750?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/3858214627131185750/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=3858214627131185750' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/3858214627131185750'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/3858214627131185750'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/03/howto-get-list-of-network-interfaces-in.html' title='Howto get a list of network interfaces in Linux, part 3'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-7886850130288570770</id><published>2010-02-19T14:38:00.002+09:00</published><updated>2011-01-06T15:21:28.564+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='interface'/><category scheme='http://www.blogger.com/atom/ns#' term='SIOCGIFCONF'/><category scheme='http://www.blogger.com/atom/ns#' term='ioctl'/><title type='text'>Howto get a list of network interfaces in Linux, part 2</title><content type='html'>Welcome back, networkers !&lt;br /&gt;&lt;br /&gt;Now, we are able to loop over all network interfaces within a shell script. How about we do it in C ? Let's make a first attempt using syscalls, shall we ? The alert reader already guessed that like all major things, there will be three parts (talking about major things, Google suggests me that there are three little pigs, stooges, musketeers. But Rs beat them all with 3 billion hits, what an ignorant fool I was, to not even know about RRR).&lt;br /&gt;&lt;br /&gt;So, whenever it comes to system and kernel stuff, system calls are your friends, and thus we naturally turn to&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt; ioctl &lt;/span&gt;and friends, in order to find out more about the network interfaces. A quick "&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;man ioctl&lt;/span&gt;"&amp;nbsp; reveals that there is a manual page that knows them all ioctls. So, let's summon it right away by doing "&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;man ioctl_list&lt;/span&gt;".&amp;nbsp; Now that you have it in front of your eyes in it's full glory, you will just trust me and use &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;SIOCGIFCONF&lt;/span&gt; to know about network interfaces. Because that manual page was rather obscure, wasn't it ?&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;So basically that's how it works : you prepare an &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ifconf&lt;/span&gt; structure to issue the ioctl itself, and add within another pointer to a few &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;ifreq&lt;/span&gt; structures that will hold the answer to your request. It's that simple. Got it ? Let's proceed to the source code then : &lt;br /&gt;&lt;div style="background-color: #d0d0ff;"&gt;&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;#include &amp;lt;stdlib.h&amp;gt;#include &amp;lt;string.h&amp;gt;#include &amp;lt;unistd.h&amp;gt;#include &amp;lt;sys/socket.h&amp;gt;#include &amp;lt;sys/types.h&amp;gt;#include &amp;lt;sys/ioctl.h&amp;gt;#include &amp;lt;linux/if.h&amp;gt;intmain(int argc, char **argv){&amp;nbsp; int devices, n, i;&amp;nbsp; struct ifconf config;&amp;nbsp; struct ifreq ifreq[128];&amp;nbsp; int ret;&amp;nbsp; /* Initialize the structure to 0s */&amp;nbsp; memset(&amp;amp;config, 0, sizeof(struct ifconf));&amp;nbsp; /* Open a socket to issue the ioctl */&amp;nbsp; devices = socket(AF_INET, SOCK_STREAM, 0);&amp;nbsp; if (devices &amp;lt; 0)&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("cannot open socket");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; /* fill-in the config request structure, including a buffer to hold the answer */&amp;nbsp; config.ifc_buf = (char *) ifreq;&amp;nbsp; config.ifc_len = 128 * sizeof(struct ifreq);&amp;nbsp; /* issue the system call */&amp;nbsp; ret = ioctl(devices, SIOCGIFCONF, (char *) &amp;amp;config);&amp;nbsp; if (ret &amp;lt; 0)&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; perror("ioctl failed\n");&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; close(devices);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 2;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; /* and parse the results, the length of the answer hints at the number of interfaces */&amp;nbsp; n = config.ifc_len / (sizeof(struct ifreq));&amp;nbsp; for (i = 0; i &amp;lt; n; i++) &amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; printf("Interface : %s\n", ifreq[i].ifr_name);&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp; close(devices);}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;And now let's try it : &lt;br /&gt;&lt;div style="background-color: #d0d0ff;"&gt;&lt;pre&gt;$ ./iflist Interface : loInterface : eth1&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Assuming I ran it on the same hardware, there seems to be some inconsistency. Because there are missing interfaces, and these are the ones that had no traffic in the stats. Which leads us to believe that SIOCGIFCONF does not return information about non running interfaces.&lt;br /&gt;&lt;br /&gt;By digging a little bit further, we will realise, doing "&lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;man netdevice&lt;/span&gt;", that SIOCGIFCONF belongs to IP layer and thus only returns information about up interfaces that have an IP address. So, let's discuss next week about another solution using netlink sockets. To be continued...&lt;br /&gt;&lt;br /&gt;PS: of course you can use that code if you need, although it is not that great. Well it depends on what you need ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-7886850130288570770?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/7886850130288570770/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=7886850130288570770' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/7886850130288570770'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/7886850130288570770'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/02/howto-get-list-of-network-interfaces-in_19.html' title='Howto get a list of network interfaces in Linux, part 2'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-4927148444107434994</id><published>2010-02-19T12:15:00.005+09:00</published><updated>2011-01-06T15:21:46.964+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='network'/><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><category scheme='http://www.blogger.com/atom/ns#' term='/proc'/><category scheme='http://www.blogger.com/atom/ns#' term='shellscript'/><category scheme='http://www.blogger.com/atom/ns#' term='interface'/><title type='text'>Howto get a list of network interfaces in Linux, part 1</title><content type='html'>Hi folks,&lt;br /&gt;&lt;br /&gt;Today we are going to become a little bit more technical. Some of you might wonder how to get a list of the network interfaces. For our first part, we are going to consider the shell script case.&lt;br /&gt;&lt;br /&gt;Little disclaimer first, I am not an expert at shell-scripts at all, my abilities are limited to understanding the random scripts I encounter during my daily use of Linux on my computers, and writing the occasional script that saves some time when having to automate some boring tasks (converting a few gigs of&amp;nbsp; videos is boring).&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;So, where shall we begin ? This is all quite easy : the kernel has a list of devices that is updated whenever a new device is added (through hotplugging, module loading, virtual device creation, and so on) or removed. As for many important kernel hosted pieces of information, this list can be accessed through the &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;/proc&lt;/span&gt; filesystem. If you are curious and want to know more about all this, you can check &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;net/core/dev.c&lt;/span&gt; from your current kernel, it should be there. Look for &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;dev_base_head&lt;/span&gt; and &lt;span style="font-family: &amp;quot;Courier New&amp;quot;,Courier,monospace;"&gt;dev_seq_printf_stats&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Let's have a look at that proc entry :&lt;br /&gt;&lt;div style="background-color: #e0e0ff;"&gt;&lt;pre&gt;Inter-|&amp;nbsp;&amp;nbsp; Receive&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp; Transmit&amp;nbsp;face |bytes&amp;nbsp;&amp;nbsp;&amp;nbsp; packets errs drop fifo frame compressed multicast|bytes&amp;nbsp;&amp;nbsp;&amp;nbsp; packets errs drop fifo colls carrier compressed&amp;nbsp;&amp;nbsp;&amp;nbsp; lo:&amp;nbsp;&amp;nbsp;&amp;nbsp; 1384&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1384&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; eth1:14664583&amp;nbsp;&amp;nbsp; 22189&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 660&amp;nbsp; 3069813&amp;nbsp;&amp;nbsp; 15105&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;wlan1:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp; pan0:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Great, It's all there in a neat and easy to parse format. Let's trash the first line, keep only the leftmost part of all the other ones, and trim the leading whitespace.&lt;br /&gt;&lt;br /&gt;As I told you earlier, I am not claiming to be a shell-script expert, but that script does work ! Here it is, using bash.&lt;br /&gt;&lt;div style="background-color: #e0e0ff;"&gt;&lt;pre&gt;#!/bin/bashfor i in `cat /proc/net/dev | grep ':' | cut -d ':' -f 1`do&amp;nbsp; ifname=`echo $i | tr -d ' '`&amp;nbsp; echo "Interface : $i"done&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;And of course, we get the expected results, at least on my debian box. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;i&gt;Results for a random debian GNU/Linux box :&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="background-color: #e0e0ff;"&gt;&lt;pre&gt;bash$ ./iflist.sh Interface : loInterface : eth1Interface : wlan1Interface : pan&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;That code snippet is given to you for free, just leave a comment if you love or hate it. Next time we will look at a little longer piece of C code to obtain the same kind of information, without resorting to opening the /proc file, of course.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-4927148444107434994?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/4927148444107434994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=4927148444107434994' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4927148444107434994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/4927148444107434994'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/02/howto-get-list-of-network-interfaces-in.html' title='Howto get a list of network interfaces in Linux, part 1'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4680898882379290660.post-6587470906512667137</id><published>2010-01-19T14:13:00.002+09:00</published><updated>2011-01-06T15:22:13.369+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='standards'/><category scheme='http://www.blogger.com/atom/ns#' term='iphone'/><title type='text'>Standards : How do you like them Apple ? (continued)</title><content type='html'>So, we are back to our iphone standards woes. If, like my wife, you shoot between 100 and 500 pictures a months, it will still take 20 to 100 months to fill up the camera roll. But that's still a lot to scroll through, so I am making a few Album folders within iTunes, and grouping the pictures by month. Which means that I remove the old pictures from the camera roll. Which also means that when the "10000 glitch" appeared, the camera roll was looking empty for some time until the update. Had to plug the phone to the comp to be sure everything was still there.&lt;br /&gt;&lt;br /&gt;So here's the big question : how could we reach 10'000 pictures in the camera roll so quickly ? The answer is, broken software. As I am suspecting more and more after seeing this "10000 glitch", the software quality is much below the anticipated quality from a company as notorious as Apple. I have never owned a Mac, out of hatred. But I have always heard good feedback and was looking forward to that phone from a software point of view.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;And I am so disappointed. This phone reminds me those cheap scripted games that are pretty much like a movie. You can not access the contents of the phone. There are no folders, no documents. It is thus &lt;b&gt;impossible to upload a file&lt;/b&gt;. Even more ridiculous, for a very long time it was impossible to cut and paste text. Even my Toshiba (!) phone could do it... By the way, I know most of this is possible with add-on software, but not always free, and never well integrated. I even read some enthusiast saying that : "If the iphone doesn't support it, it means we don't need it". The same person probably acclaimed the release that featured the never seen before cut and paste capability. Which reminds me how safari lacks a "search" function...&lt;br /&gt;&lt;br /&gt;So, back to software quality. Even though there are no folders, Safari at least gives you the ability to save images to the camera roll. And so does the iphone OS by allowing you to make screenshots, pressing both the square button and the power button simultaneously. Which has a high probability to screw up your camera roll ! Yes, this is the culprit. I found out that every now and then, when saving pictures from the web or making a screenshot, the software smartly creates a new 1XXAPPLE folder inside the DCIM root folder. So instead of 10'000 pictures, all we needed to get to the infamous 110APPLE folder was a dozen of screenshots or saved files...&lt;br /&gt;&lt;br /&gt;Now the story wouldn't be complete without some more ranting from my side. So here it goes : when I realized that this picture stuff was happening i filed a bug in the iphone developer section of apple developer connection (the Apple developer resource center, like MSDN for the windozers, if I'm not mistaken). Of course I never had any reply, but that update I mentioned was fixing part of the problem : Apple decided to work around the issue and allow the camera roll to display files with out-of-specifications names (i.e. 4 letters 5 digits).&lt;br /&gt;&lt;br /&gt;Unfortunately, it looks like something in the 3.x update completely screwed up the battery life for some phones in some circumstances. Not my case, but it still resulted in a last update, the latest and greatest 3.1.2 iPhone OS. And what a mess it is : it features a very nice bug where the phone is not detected as a storage device anymore (neither by PCs nor Macs). Remeber the thin obfuscation layer I was mentioning in the previous post ? It looks like it is broken, oh my ! After a few days posting on the apple forums, I met someone who found the cause for this issue : it only happens if there are PNG files in the camera roll. Well, not any PNGs, it needs to be very specific ones, but at least I was not the only person with the issue.&lt;br /&gt;&lt;br /&gt;And to my knowledge, the problem is still not fixed today. So what do you do when you want to extract the pictures from your glitched phone ? It depends on budget and policy :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;strict policy : you wait for Apple to sort it out&lt;/li&gt;&lt;li&gt;loose policy, no budget : you use a free application to send all the pictures (e.g. Pixelpipe, or any of those wifi sharing apps)&lt;/li&gt;&lt;li&gt;loose policy, low budget : you buy a &amp;lt;30$ software to extract the pictures from the 1XXAPPLE folders (e.g. Touchcopy)&lt;/li&gt;&lt;li&gt;high budget : you buy a real digital camera and repeat after me : I phone with my phone, iphone will just phone.&lt;/li&gt;&lt;/ul&gt;Okay enough joking. If you can manage to copy those PNG files to your computer and erase them from the iphone using a third-party app, the phone will appear again as a storage device, after you unplug (from the computer) and reboot it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-6587470906512667137?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/6587470906512667137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=6587470906512667137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6587470906512667137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/6587470906512667137'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/01/standards-how-do-you-like-them-apple_19.html' title='Standards : How do you like them Apple ? (continued)'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-1946358441740028200</id><published>2010-01-13T14:58:00.002+09:00</published><updated>2011-01-06T15:22:33.148+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='standards'/><category scheme='http://www.blogger.com/atom/ns#' term='iphone'/><title type='text'>Standards : How do you like them Apple ?</title><content type='html'>Okay I have been trying hard to find some funny way to introduce this post, don't worry if you don't think it is (funny).&lt;br /&gt;&lt;br /&gt;Actually, there are two reasons why I wanted that funny start, the first one being because it has been a long time since I posted anything -or since I posted at all- and the second one because, I am still not sure if I should post it. I have been wrestling with myself over this, but I believe that accumulated frustration finally triggered the whole thing, so let's go. I will try to explain here how I am getting more and more disappointed by an overrated phone...&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;It all began when I bought an iPhone for my wife. Very good idea by the way, because being very busy all day along, she could not use her computer anymore and this was a kind of pocket substitute. She had tried a few other tiny gadget notebooks like the Zaurus, various VAIOs, but apparently she was much more pleased with this one. She mainly uses it for : browsing the web, reading RSS flows, writing emails and taking pictures.&lt;br /&gt;&lt;br /&gt;And these last two were iPhone killers. At the time we got it (I believe 2.0 upgrade, the one with Google Streetvie) there was still no cut and paste (ha ha !) and it was not possible to send more than 1 picture by e-mail, with butchered resolution. This led me to design a small web-based mailing application allowing a bit of formatting, and image inlining which is much better than attaching everything at the bottom. If anyone is interested, I can talk about that another day. So e-mail problem was solved.&lt;br /&gt;&lt;br /&gt;What about pictures then ? There is a camera on the iPhone so it should be okay. Should be. This is where we will discover the meaning of the title. But first, let's digress a bit and discuss &lt;b&gt;Standards&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;I never loved anything as much as standards when it comes to computers. Either hardware or software, standards are good for us. If a manufacturer, software developer fails, you don't have to worry if they were operating within a standard : data can be losslessly converted, parts can be replaced, etc...&lt;br /&gt;&lt;br /&gt;Now back to the camera. Under a little obfuscation layer that we will discuss again later, the iPhone has folders to organize the pictures it takes. And of course, people over there at Apple didn't want to re-invent the wheel, so they just went for the famous ABCD1234.JPG naming scheme. If you have ever looked at the data produced by digital cameras on their memory cards, you know what I mean. And guess what ? This naming has been standardized. Yes ! By the Japan Electronic Industry Development Association, and it can be found &lt;a href="http://www.exif.org/dcf.PDF"&gt;here&lt;/a&gt;. Read it if you want, the important part is, the name should be made of 8 chars including 4 free chars and 4 digits.&lt;br /&gt;&lt;br /&gt;Okay, so just plug your iPhone into your computer and check out the storage device that is created. You can see the pictures there, sorted neatly in a few 100APPLE and such folders. Let's see how Apple people decided to name the files. The folders look like 100APPLE, 101APPLE, 102APPLE and so on. In each folder, there are files called IMG_numb.JPG, where numb is unique and incremented after each shot. And now is the interesting part : this unique number was also decided, by the designers of the iPhone and out of the specification scope, to be unique among directories. The quick and very dirty way is to decide that 100APPLE has pictures from 0001 to 0999, then 101APPLE has pictures from 1000 to 1999, and this sounds so much like "640Ko should be enough for all" that I am surprised they could do the exact same mistake !&lt;br /&gt;&lt;br /&gt;What happens when someone has more than 9999 pictures ? I will tell you, a new folder is created, called 110APPLE and it contains files named IMG_10001,JPG and so on. I would laugh if it didn't deprive me from sleeping for a few days. So here we have a clear violation of the DCF standard, right ? For people like Apple this is no big deal because they make the picture taking, picture viewing, picture synchronizing (iTunes, iPhoto, whatever) applications, so they just have to be aware of this standard "enhancement". But they are not. Which is why during a few weeks (before an update that silently fixed the camera roll without telling) it was impossible for me to see any pictures taken after the 9999th in the Camera Roll application within the iPhone. Good job guys...&lt;br /&gt;&lt;br /&gt;Hmmm this is getting longer than expected so i will cut here and resume the story in the next post soon... Because let me reassure you, we never shot ten thousand pictures with the iphone, yet we reached the 10'000 bar...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-1946358441740028200?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/1946358441740028200/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=1946358441740028200' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/1946358441740028200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/1946358441740028200'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2010/01/standards-how-do-you-like-them-apple.html' title='Standards : How do you like them Apple ?'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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-4680898882379290660.post-456572146598411470</id><published>2008-07-08T07:40:00.000+09:00</published><updated>2010-01-13T15:02:22.173+09:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='motd'/><category scheme='http://www.blogger.com/atom/ns#' term='welcome'/><title type='text'>Welcome / ようこそ / Bienvenue !</title><content type='html'>&lt;span style="font-family: arial;"&gt;Welcome to the 'Hayai Jean' blog. On this site, I will try to present all kind of technical stuff that I find interesting.&lt;br /&gt;&lt;br /&gt;「ハヤイ　ジャン」へようこそ！このウェブサイトで色々な面白い情報を見せたいです。　&lt;br /&gt;&lt;br /&gt;Bienvenue sur le blog Hayai Jean. J'essaierai d'y présenter des informations techniques que je trouverai intéressantes.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;早い　ジャン　d^.^V&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: arial;"&gt;EDIT: This blog was renamed "Jean's tech blog" after a major lack of content &lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4680898882379290660-456572146598411470?l=iijean.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://iijean.blogspot.com/feeds/456572146598411470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4680898882379290660&amp;postID=456572146598411470' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/456572146598411470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4680898882379290660/posts/default/456572146598411470'/><link rel='alternate' type='text/html' href='http://iijean.blogspot.com/2008/07/welcome-bienvenue.html' title='Welcome / ようこそ / Bienvenue !'/><author><name>Jean</name><uri>http://www.blogger.com/profile/06319501918352242606</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>
