<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Håkon Nessjøen &#187; C</title>
	<atom:link href="http://lunatic.no/category/cprogramming/feed/" rel="self" type="application/rss+xml" />
	<link>http://lunatic.no</link>
	<description>Just another life hacker</description>
	<lastBuildDate>Tue, 06 Dec 2011 22:39:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>DMX Light control system</title>
		<link>http://lunatic.no/2011/11/dmx-light-control-system/</link>
		<comments>http://lunatic.no/2011/11/dmx-light-control-system/#comments</comments>
		<pubDate>Fri, 18 Nov 2011 22:53:56 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[dmx]]></category>
		<category><![CDATA[hobby]]></category>
		<category><![CDATA[jackd]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=275</guid>
		<description><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2011/11/dmx-light-control-system/"></g:plusone></div>
Every year, I team up with raider.no to arrange a party in Hurdalen, or around the Oslo area. And one of the things that is important for us (especially me and William), is to create a cool opening show, using our own innovative technology. We don&#8217;t have a lot of money in the organization, so [...]]]></description>
			<content:encoded><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2011/11/dmx-light-control-system/"></g:plusone></div>
<p>Every year, I team up with <a href="http://raider.no/" target="_blank">raider.no</a> to arrange a party in Hurdalen, or around the Oslo area. And one of the things that is important for us (especially me and <a href="http://williamviker.net/" target="_blank">William</a>), is to create a cool opening show, using our own innovative technology. We don&#8217;t have a lot of money in the organization, so we tend to also develop stuff that already exists.</p>
<p>This year, we wanted to do the timing of the show entirely in our own system, as we weren&#8217;t satisfied with the Avolites Pearl systems own &#8220;show timing&#8221; system.</p>
<p>So we split up the task in two daemons and a GUI. The two daemons are written in C, and the GUI in Perl (using the Catalyst Framework).<br />
The first deamon is the &#8220;DMX daemon&#8221;, which handles existing DMX data from the Pearl mixer as the rest of the night will be run from this board. This is transferred via network over the ArtNet protocol. It also listens for our own udp DMX-commands, which includes simple operations like, fade (linear), blink, subtract, add, etc. These functions allows external scripts and programs to send simple commands to control the lights. For example &#8220;fade channel 1 from 0 to 255 in 2 seconds&#8221;. Which would then automatically execute, without the client having do anything more. You can also group together a bunch of actions in a &#8220;transaction&#8221;, and then have it execute as soon as you send the &#8220;end transaction&#8221; command. The resulting DMX data is sent to the Enttec DMX dongle connected to this computer. The system is so lightweight, that there was no noticeable delay from using ArtNet->DMXDaemon->EnttecDongle over network, than using the direct DMX output from the board. The nice thing is that, if we want, the show daemon can forcibly stop all data from the Pearl mixer, or even alter the data using add/subtract/max/min commands.</p>
<p>The next daemon is the show daemon, this takes complete scripted shows from the database (created by the GUI), and converts them to commands to be sent to the DMX daemon. This daemon uses (lib)jackd2 to fire events at the exact time according to the sound file playing in a external program like Ardour, which sends timecodes via jackd. The show daemon has functions to group together effects that will be executed at specific timestamps.</p>
<p>Here&#8217;s a link to a <a href='http://lunatic.no/2011/11/dmx-light-control-system/tekniskoversiktdistrictsep17apningsshow/' rel='attachment wp-att-276'>overview</a> of how we wired it all up for the show.</p>
<p>The whole system is kept open-source at <a href="https://github.com/RaiderEMB/timecode-dmx">github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2011/11/dmx-light-control-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Variable initialization in C</title>
		<link>http://lunatic.no/2011/11/variable-initialization-in-c/</link>
		<comments>http://lunatic.no/2011/11/variable-initialization-in-c/#comments</comments>
		<pubDate>Sun, 13 Nov 2011 04:46:10 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Tips & tricks]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=263</guid>
		<description><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2011/11/variable-initialization-in-c/"></g:plusone></div>
I&#8217;m feel that I am starting to get the hold of C programming. But every now and then, I get these &#8220;ahaaa&#8221; moments, that I am a bit embarrassed about. One of these &#8220;aha&#8221;&#8216;s I experienced today is how/when C handles initialization of variables where you don&#8217;t explicitly initialize them yourself. Consider this code: 1 [...]]]></description>
			<content:encoded><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2011/11/variable-initialization-in-c/"></g:plusone></div>
<p>I&#8217;m feel that I am starting to get the hold of C programming. But every now and then, I get these &#8220;ahaaa&#8221; moments, that I am a bit embarrassed about. One of these &#8220;aha&#8221;&#8216;s I experienced today is how/when C handles initialization of variables where you don&#8217;t explicitly initialize them yourself.</p>
<p>Consider this code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">int</span> var1<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span> <span style="color: #339933;">**</span>argv<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> argc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> var2<span style="color: #339933;">;</span>
  <span style="color: #993333;">int</span> var3<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Here i deliberately did not initialize any of the variables to make an example. The first two variables will automatically be initialized with 0 before your main() function is executed. The last variable lives in the stack and will not be initialized unless you explicitly do it yourself. So it will probably have a &#8216;random&#8217; value. Thats kind of handy to know about ;) I feel like this probably is one of the first things you usually learn about C, but I had totally missed this. Nice to know. Also if you use Valgrind to check your code, it can be very good at following uninitialized stack variables. It will actually follow uninitialized memory bit-wise.</p>
<p>First I thought the memory was initialized to 0 at compile-time, but after some reading, I learnt that the compiler records the amount of uninitialized memory for global and static variables, and stores the amount of data required in the BSS segment of the program. This way the executable will not grow in size in line with the amount of uninitialized data. For this reason some people call the BSS segment for the &#8220;Better Save Space&#8221; segment.</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2011/11/variable-initialization-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAC-address based Telnet server in Linux</title>
		<link>http://lunatic.no/2010/12/mac-address-based-telnet-server-in-linux/</link>
		<comments>http://lunatic.no/2010/12/mac-address-based-telnet-server-in-linux/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 00:40:48 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[mikrotik]]></category>
		<category><![CDATA[routeros]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=200</guid>
		<description><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/12/mac-address-based-telnet-server-in-linux/"></g:plusone></div>
My previous post was about RouterOS Mac-Telnet application for Linux users where I talked about the MAC-Telnet client I created for Linux users. Since then, I have both started porting it to OS X and to create a daemon version of MAC-Telnet, called &#8220;mactelnetd&#8221;. You can look at the different branches at github.com. To use [...]]]></description>
			<content:encoded><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/12/mac-address-based-telnet-server-in-linux/"></g:plusone></div>
<p>My previous post was about <a title="Permanent Link to RouterOS Mac-Telnet application for Linux users" rel="bookmark" href="/2010/10/routeros-mac-telnet-application-for-linux-users/">RouterOS Mac-Telnet application for Linux users</a> where I talked about the MAC-Telnet client I created for Linux users.</p>
<p>Since then, I have both started porting it to OS X and to create a daemon version of MAC-Telnet, called &#8220;mactelnetd&#8221;. You can look at the different branches at <a title="MAC-Telnet at github.com" href="http://github.com/haakonnessjoen/MAC-Telnet" target="_blank">github.com</a>.</p>
<p>To use mactelnetd, install MAC-Telnet from the github link, using either the latest .deb file from the download section (if you are on Ubuntu or Debian), or download the sources and compile it yourself. You can find instructions for this on my previous post. you first need to edit the /etc/mactelnetd.users file. This file consists of the users and their respective passwords for logging into the server. I wish we wouldn&#8217;t have to write the passwords in plain text, but the authentication method used in the mac-telnet protocol demands that we know the actual password, unlike ssh/regular telnet, where the password can be stored as a hash sum.</p>
<p>The format of /etc/mactelnetd.users is like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Users file for MAC-Telnetd</span>
<span style="color: #666666; font-style: italic;"># Use existing usernames from your system</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Format:</span>
<span style="color: #666666; font-style: italic;">#username:password</span>
haakon:mypass</pre></div></div>

<p>Here I have activated the user account haakon, with apssword &#8220;mypass&#8221;. It is important that the user names that you enter into this file is existing user names from your Linux machine. The mactelnetd daemon will check /etc/passwd for home directory, and what shell to spawn for the user, as any regular terminal server.</p>
<p>When you have created/modified this file to your wishes, you can start the server daemon:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> mactelnetd</pre></div></div>

<p>If there were no error messages, it spawned successfully and you can watch it&#8217;s log entries via syslog.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>syslog
Dec <span style="color: #000000;">26</span> 01:06:08 haakon-kontorpc mactelnetd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">10183</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: Bound to 0.0.0.0:<span style="color: #000000;">20561</span>
Dec <span style="color: #000000;">26</span> 01:<span style="color: #000000;">31</span>:<span style="color: #000000;">17</span> haakon-kontorpc mactelnetd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">10183</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">28780</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> New connection from <span style="color: #000000;">0</span>:c:<span style="color: #000000;">42</span>:3e:<span style="color: #000000;">20</span>:c2.
Dec <span style="color: #000000;">26</span> 01:<span style="color: #000000;">31</span>:<span style="color: #000000;">17</span> haakon-kontorpc mactelnetd<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">10391</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">28780</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> User haakon logged in.</pre></div></div>

<p>Here you see the results of me logging into my Linux Desktop machine from a MikroTik Router using the RouterOS command &#8220;tool mac-telnet 1c:6f:65:2c:98:b7&#8243;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>admin<span style="color: #000000; font-weight: bold;">@</span>Holmenveien<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> tool mac-telnet 1c:6f:<span style="color: #000000;">65</span>:2c:<span style="color: #000000;">98</span>:b7
Login: haakon
Password:
Trying 1C:6F:<span style="color: #000000;">65</span>:2C:<span style="color: #000000;">98</span>:B7...
Connected to 1C:6F:<span style="color: #000000;">65</span>:2C:<span style="color: #000000;">98</span>:B7
Linux haakon-kontorpc 2.6.35-<span style="color: #000000;">23</span>-generic-pae <span style="color: #666666; font-style: italic;">#41-Ubuntu SMP Wed Nov 24 10:35:46 UTC 2010 i686 GNU/Linux</span>
Ubuntu <span style="color: #000000;">10.10</span>
&nbsp;
Welcome to Ubuntu<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #000000; font-weight: bold;">*</span> Documentation:  https:<span style="color: #000000; font-weight: bold;">//</span>help.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
haakon<span style="color: #000000; font-weight: bold;">@</span>haakon-kontorpc:~$ <span style="color: #c20cb9; font-weight: bold;">w</span>
01:<span style="color: #000000;">32</span>:<span style="color: #000000;">52</span> up <span style="color: #000000;">24</span> days, <span style="color: #000000;">22</span>:<span style="color: #000000;">48</span>,  <span style="color: #000000;">2</span> <span style="color: #c20cb9; font-weight: bold;">users</span>,  load average: <span style="color: #000000;">0.53</span>, <span style="color: #000000;">0.61</span>, <span style="color: #000000;">0.57</span>
USER     TTY      FROM              LOGIN<span style="color: #000000; font-weight: bold;">@</span>   IDLE   JCPU   PCPU WHAT
haakon   tty7     :<span style="color: #000000;">0</span>               01Dec10 24days <span style="color: #000000;">26</span>:29m  3.17s gnome-session
haakon   pts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0</span>    <span style="color: #000000;">0</span>:c:<span style="color: #000000;">42</span>:3e:<span style="color: #000000;">20</span>:c2  01:<span style="color: #000000;">32</span>    0.00s  0.15s  0.00s <span style="color: #c20cb9; font-weight: bold;">w</span></pre></div></div>

<p>If you want to shut down the mactelnetd server, simply write &#8220;sudo killall mactelnetd&#8221; in your shell.</p>
<p><strong>FUN TIP:</strong> If you want &#8220;fancy&#8221; terminal promt like RouterOS has, with syntax coloring on your Linux machine (logging in via console, xterm, ssh or mactelnet), you can install the shell &#8220;<a title="Friendly Interactive SHell" href="http://en.wikipedia.org/wiki/Friendly_interactive_shell" target="_blank">fish</a>&#8220;, and then change your user settings to use it as the default shell by issuing:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> usermod <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fish myusername</pre></div></div>

<p><strong>NB:</strong> Be sure that the file /usr/bin/fish exists, and change &#8220;myusername&#8221; with your username, and remember to test logging into a second console, just to be sure you did this correctly, before logging out of your current terminal. To revert, set /bin/bash as your shell again, or what ever shell you previously used.</p>
<p>Here&#8217;s a direct link to the latest Ubuntu/Debian package at the time of writing:</p>
<p><a href="https://github.com/downloads/haakonnessjoen/MAC-Telnet/mactelnet_0.2-1ubuntu1_i386.deb">mactelnet_0.2-1ubuntu1_i386.deb</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/12/mac-address-based-telnet-server-in-linux/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RouterOS Mac-Telnet application for Linux users</title>
		<link>http://lunatic.no/2010/10/routeros-mac-telnet-application-for-linux-users/</link>
		<comments>http://lunatic.no/2010/10/routeros-mac-telnet-application-for-linux-users/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 10:28:53 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[mikrotik]]></category>
		<category><![CDATA[routeros]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=180</guid>
		<description><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/10/routeros-mac-telnet-application-for-linux-users/"></g:plusone></div>
Earlier, I wrote about a Wireshark plugin for dissecting Mac-Telnet packets. Now I have created an open source application for connecting to a RouterOS router via its MAC address from Linux without having to install Wine. At the time of writing the project is still in &#8220;alpha&#8221; stage. But it is fully functional. Though it [...]]]></description>
			<content:encoded><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/10/routeros-mac-telnet-application-for-linux-users/"></g:plusone></div>
<p>Earlier, I wrote about a <a href="http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/">Wireshark plugin</a> for dissecting Mac-Telnet packets. Now I have created an open source application for connecting to a RouterOS router via its MAC address from Linux without having to install Wine. At the time of writing the project is still in &#8220;alpha&#8221; stage. But it is fully functional. Though it will probably be rewritten soon. I feel that the second time you write the same application, it tends to be more robust and thought through.. The first time is more of a proof of concept, and I let myself do a lot of short-cuts, just to be able to see it working.</p>
<p>The source code can be found at <a href="http://github.com/haakonnessjoen/MAC-Telnet">github</a>. Just find the &#8220;download source&#8221; link at the top of the page.</p>
<p>To compile it, simply untar it, and compile it with &#8220;make&#8221; .<br />
Because it needs to alter the frame headers, it uses RAW sockets, which means that you will need root access to use this tool.</p>
<p>To find the MAC address of connected routers, try the included tool mndp. It might take up to 2 minutes to find all routers, since it is a passive tool that waits for the routers to broadcast their info on the network:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ./mndp</span>
Searching <span style="color: #000000; font-weight: bold;">for</span> MikroTik routers... Abort with CTRL+C.
  <span style="color: #000000;">0</span>:c:<span style="color: #000000;">42</span>:<span style="color: #000000;">43</span>:<span style="color: #000000;">58</span>:a5 HMG</pre></div></div>

<p>HMG is my name of the found router, set in the Identity section of the router.</p>
<p>Here are some mac-telnet usage information:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ./mactelnet --help</span>
Usage: .<span style="color: #000000; font-weight: bold;">/</span>mactelnet <span style="color: #000000; font-weight: bold;">&lt;</span>ifname<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>MAC<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;</span>username<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>password<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Parameters:
  ifname    Network interface that the RouterOS resides on. <span style="color: #7a0874; font-weight: bold;">&#40;</span>ex: eth0<span style="color: #7a0874; font-weight: bold;">&#41;</span>
  MAC       MAC-Address of the RouterOS device. Use mndp to discover them.
  username  Your username.
  password  Your password.</pre></div></div>

<p><strong>Tip:</strong> Log out using CTRL+D on your keyboard.</p>
<p>Usage example:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># sudo ./mactelnet eth0 0:c:42:43:58:a5 admin mysecretpass</span>
Connecting to <span style="color: #000000;">0</span>:c:<span style="color: #000000;">42</span>:<span style="color: #000000;">43</span>:<span style="color: #000000;">58</span>:a5...done
&nbsp;
&nbsp;
  MMM      MMM       KKK                          TTTTTTTTTTT      KKK
  MMMM    MMMM       KKK                          TTTTTTTTTTT      KKK
  MMM MMMM MMM  III  KKK  KKK  RRRRRR     OOOOOO      TTT     III  KKK  KKK
  MMM  MM  MMM  III  KKKKK     RRR  RRR  OOO  OOO     TTT     III  KKKKK
  MMM      MMM  III  KKK KKK   RRRRRR    OOO  OOO     TTT     III  KKK KKK
  MMM      MMM  III  KKK  KKK  RRR  RRR   OOOOOO      TTT     III  KKK  KKK
&nbsp;
  MikroTik RouterOS <span style="color: #000000;">4.0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>c<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">1999</span>-<span style="color: #000000;">2009</span>       http:<span style="color: #000000; font-weight: bold;">//</span>www.mikrotik.com<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>admin<span style="color: #000000; font-weight: bold;">@</span>HMG<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>[UPDATE]<br />
<a href="http://www.omniflux.com/">Omni Flux</a> sent me a patch that speeds up the MNDP discovery time by sending out a MNDP request before waiting for replies. Thanks!</p>
<p>He also informed me that his tests showed that you could send all the mac-telnet traffic to- and from- the broadcast address. This means that you would not need socket_raw (read: root privileges) capabillities to be able to send data to the router.</p>
<p>So the latest version of mactelnet, now also as a binary .deb package below, can be used without root privileges, unless you don&#8217;t want all data from your session to be broadcasted on your local network. You can optionally use the &#8220;old&#8221; method, where it uses the destination routers mac address as destination instead of broadcast.</p>
<p>Heres the latest &#8220;stable&#8221;: v0.1 version<br />
<a href="http://github.com/haakonnessjoen/MAC-Telnet/tarball/v0.1">Source tarball</a><br />
<a href="http://github.com/downloads/haakonnessjoen/MAC-Telnet/mactelnet_0.1-0ubuntu1_i386.deb">Ubuntu/Debian binary package</a></p>
<h2>Last commits on MAC-Telnet at GitHub</h2><ul><li>28.02.2012 - <a href="https://github.com/haakonnessjoen/MAC-Telnet/commit/2d1bb7ebafb3cfe9161854d1ac0b05133fa05139">Add comment about \r\n in i18n</a></li>
<li>28.02.2012 - <a href="https://github.com/haakonnessjoen/MAC-Telnet/commit/0918879970d8b399512a9a4553d7989f2434c9a7">Update po template</a></li>
<li>28.02.2012 - <a href="https://github.com/haakonnessjoen/MAC-Telnet/commit/86990fe50070268508caf171c825217c7da21ef5">Cleaned up i18n</a></li>
<li>28.02.2012 - <a href="https://github.com/haakonnessjoen/MAC-Telnet/commit/210b1b5574afb381b87d6d34860009a905ed6848">Added i18n support</a></li>
<li>11.02.2012 - <a href="https://github.com/haakonnessjoen/MAC-Telnet/commit/11ee3dc65c67d6a5c98347287cee50963029d412">Bugfix. Don't die on interfaces without address.</a></li>
</ul>]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/10/routeros-mac-telnet-application-for-linux-users/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Dissecting Mikrotiks Mac-Telnet packets</title>
		<link>http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/</link>
		<comments>http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 19:11:43 +0000</pubDate>
		<dc:creator>Håkon Nessjøen</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[routeros]]></category>

		<guid isPermaLink="false">http://lunatic.no/?p=112</guid>
		<description><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/"></g:plusone></div>
I was searching on the Internet if there were any MAC-Telnet clients for linux/posix, since using terminal.exe in wine is problematic sometimes, as wine gives it access to only one of the NICs in your computer. I didn&#8217;t find any clients, but I found this nice reverse engineering of the protocol, which interested me, because [...]]]></description>
			<content:encoded><![CDATA[<div style="display:inline;float:right;margin-left:1em"><g:plusone href="http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/"></g:plusone></div>
<div id="attachment_117" class="wp-caption alignleft" style="width: 310px"><a href="http://lunatic.no/wp-content/uploads/2010/06/Screenshot-mactelnet-test.png"><img class="size-medium wp-image-117" title="Screenshot of Mac-Telnet dissecter" src="http://lunatic.no/wp-content/uploads/2010/06/Screenshot-mactelnet-test-300x205.png" alt="Screenshot of Mac-Telnet dissecter" width="300" height="205" /></a><p class="wp-caption-text">Mac-Telnet traffic in Wireshark</p></div>
<p>I was searching on the Internet if there were any MAC-Telnet clients for linux/posix, since using terminal.exe in wine is problematic sometimes, as wine gives it access to only one of the NICs in your computer.</p>
<p>I didn&#8217;t find any clients, but I found this nice reverse engineering of the protocol, which interested me, because I&#8217;ve always wondered how it was made, just not enough to check myself. But this guy has done his homework and then some in reverse engineering of Mikrotiks protocol.</p>
<p>You can find his page here: <a href="http://www.omniflux.com/devel/" target="_blank">http://www.omniflux.com/devel/</a></p>
<p>This gave me an Idea to create a MAC-Telnet client myself, and I started some testing with perl to check if I was able to send the correct packets to my mikrotik router. At first you might think; thats easy! All packets via the mac-telnet protocol uses UDP packets, with both source- and destintation port: 20561.</p>
<p>But you can&#8217;t send these packets with your normal socket wrapper library, because you need to set the mac-addresses in the network frame to something other than the source/destination IPs corresponding ARP entry. To go into details: When you send Mac-Telnet packets as a client, you need to send your packets going from your ip to ip 255.255.255.255, but with the router you want to telnet as the destination mac address in the ethernet frame. (even though the ip is set to 255.255.255.255).</p>
<p>To test this in perl, I used Net::RawIP from CPAN, which worked just like I wanted to. The only problem is that you need to have root access to be able to do raw packets.</p>
<p>Anyways, I looked at the packet I sent with my test script, and the response from the RouterBoard with Wireshark. Even though I got it to work, I felt I was having problems reading the packets very easily: Reading omniflux&#8217;s protocol description, and then looking at the hex dump of the packet. So I decided to make a dissector plugin for Wireshark (ethereal), so I could debug the packets easier.</p>
<p>Here is the finished source code for the Wireshark plugin (GPLv2): <a href="http://lunatic.no/wp-content/uploads/2010/06/mactelnet.diff_.txt">mactelnet.diff</a></p>
<p>Just patch this in from the root of the wireshark sources.</p>
<p>[Update: It is now added in the wireshark svn trunk]</p>
]]></content:encoded>
			<wfw:commentRss>http://lunatic.no/2010/06/dissecting-mikrotiks-mac-telnet-packets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

