<?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>Binary Tides &#187; Linux</title>
	<atom:link href="http://www.binarytides.com/blog/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarytides.com/blog</link>
	<description></description>
	<lastBuildDate>Sat, 24 Jul 2010 05:31:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Open View MS Access mdb files in Ubuntu Linux</title>
		<link>http://www.binarytides.com/blog/open-view-ms-access-mdb-files-in-ubuntu-linux/</link>
		<comments>http://www.binarytides.com/blog/open-view-ms-access-mdb-files-in-ubuntu-linux/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 15:37:41 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=177</guid>
		<description><![CDATA[MDB Viewer is a tool which can be used to open and view mdb files on Linux.
On Ubuntu it can be installed from synaptic via the command :
sudo apt-get install mdbtools-gmdb
]]></description>
			<content:encoded><![CDATA[<p>MDB Viewer is a tool which can be used to open and view mdb files on Linux.<br />
On Ubuntu it can be installed from synaptic via the command :</p>
<p>sudo apt-get install mdbtools-gmdb</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=177&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/open-view-ms-access-mdb-files-in-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a deb file from source on Ubuntu</title>
		<link>http://www.binarytides.com/blog/create-a-deb-file-from-source-on-ubuntu/</link>
		<comments>http://www.binarytides.com/blog/create-a-deb-file-from-source-on-ubuntu/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 09:40:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=64</guid>
		<description><![CDATA[To create a .deb package file on Ubuntu you need a utility called checkinstall.sudo apt-get install checkinstall
1. Extract the source of the application in a folder.2. Run : ./configure3. Run : make4. Now run : sudo checkinstall

checkinstall will ask for some information most of which you can skip except the version of the package being [...]]]></description>
			<content:encoded><![CDATA[<p>To create a .deb package file on Ubuntu you need a utility called checkinstall.<br />sudo apt-get install checkinstall</p>
<p>1. Extract the source of the application in a folder.<br />2. Run : ./configure<br />3. Run : make<br />4. Now run : sudo checkinstall</p>
<p><span id="more-64"></span></p>
<p>checkinstall will ask for some information most of which you can skip except the version of the package being created.</p>
<p>Once finished a .deb file would be created which can be used to install the package by simple double clicking. Packages installed from deb files will get listed in Synaptic Package Manager and can also be uninstalled very easily.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=64&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/create-a-deb-file-from-source-on-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Screen Resolution 1440 x 900 in Ubuntu</title>
		<link>http://www.binarytides.com/blog/screen-resolution-1440-x-900-in-ubuntu/</link>
		<comments>http://www.binarytides.com/blog/screen-resolution-1440-x-900-in-ubuntu/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 15:45:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=62</guid>
		<description><![CDATA[Ubuntu 9.04 did not detect the native resolution of my new LCD monitor which was 1440 x 900.
Fix :
1. Get the modeline for the required resolution + refresh rate using the gtf command.

desktop:~$ gtf 1440 900 75

&#60;span id=&#34;more-62&#34;&#62;&#60;/span&#62;

  # 1440x900 @ 75.00 Hz (GTF) hsync: 70.50 kHz; pclk: 136.49 MHz
  Modeline &#38;quot;1440x900_75.00&#38;quot;  [...]]]></description>
			<content:encoded><![CDATA[<p>Ubuntu 9.04 did not detect the native resolution of my new LCD monitor which was 1440 x 900.</p>
<p><strong>Fix :</strong></p>
<p>1. Get the modeline for the required resolution + refresh rate using the gtf command.</p>
<pre class="brush: cpp;">
desktop:~$ gtf 1440 900 75

&lt;span id=&quot;more-62&quot;&gt;&lt;/span&gt;

  # 1440x900 @ 75.00 Hz (GTF) hsync: 70.50 kHz; pclk: 136.49 MHz
  Modeline &amp;quot;1440x900_75.00&amp;quot;  136.49  1440 1536 1688 1936  900 901 904940  -HSync +Vsync
</pre>
<p>The modeline is to be added to the xorg.conf file at /etc/X11/xorg.conf<br />
Take a backup of the file before editing it.</p>
<p>On a fresh Ubuntu installation the file may look small like this :</p>
<pre class="brush: cpp;">
#Some comments on top
Section &quot;Monitor&quot;
 Identifier &quot;Configured Monitor&quot;
EndSection

Section &quot;Screen&quot;
 Identifier &quot;Default Screen&quot;
 Monitor  &quot;Configured Monitor&quot;
 Device  &quot;Configured Video Device&quot;
EndSection

Section &quot;Device&quot;
 Identifier &quot;Configured Video Device&quot;
EndSection

Section &quot;ServerFlags&quot;
 Option &quot;DontZap&quot; &quot;True&quot;
EndSection
</pre>
<p>Simply add the modeline to the monitor section like this :</p>
<pre class="brush: cpp;">
Section &quot;Monitor&quot;
 Identifier &quot;Configured Monitor&quot;
 Modeline &quot;1440x900_75.00&quot;  136.49  1440 1536 1688 1936  900 901 904 940  -HSync +Vsync
 Option          &quot;PreferredMode&quot; &quot;1440x900_75.00&quot;
EndSection

Section &quot;Screen&quot;
 Identifier &quot;Default Screen&quot;
 Monitor  &quot;Configured Monitor&quot;
 Device  &quot;Configured Video Device&quot;
EndSection

Section &quot;Device&quot;
 Identifier &quot;Configured Video Device&quot;
EndSection

Section &quot;ServerFlags&quot;
 Option &quot;DontZap&quot; &quot;True&quot;
EndSection
</pre>
<p>The option &#8220;PreferredMode&#8221; &#8220;1440&#215;900_75.00&#8243; is used so that it becomes the default resolution on gnome, KDE desktops and GDM and KDM i.e. the login screen. If this option is not used then there may be issues such that resolution after reboot or relogin reverts to a default like 1280 x 1200 as discussed here <a href="https://bugs.launchpad.net/kdebase/+bug/268434">Bug</a>.</p>
<p>Another fix could to be reconfigure X like : sudo dpkg-reconfigure xserver-xorg.</p>
<p>References :<br />
1. <a href="https://wiki.ubuntu.com/X/Config/Resolution">Ubuntu Resolution Configuration</a><br />
2. <a href="http://ubuntuforums.org/showthread.php?t=280683&amp;page=3">Forum</a></p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=62&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/screen-resolution-1440-x-900-in-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top Games on Ubuntu Linux</title>
		<link>http://www.binarytides.com/blog/top-games-on-ubuntu-linux/</link>
		<comments>http://www.binarytides.com/blog/top-games-on-ubuntu-linux/#comments</comments>
		<pubDate>Sat, 02 May 2009 17:34:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=58</guid>
		<description><![CDATA[So here is a list of games which can be played on Ubuntu.
On Ubuntu 8.10
1. TORCS &#8211; The Open Racing Car Simulator &#8211; Racing game

Install from Synaptic

2. Planet Penguin Racer &#8211; Racing Game
Install from Synaptic

3. Extreme Tux Racer &#8211; Racing Game
Install from Synaptic

4. Frozen Bubble &#8211; Puzzle Game
Install from Synaptic

5. Supertuxkart &#8211; Racing Game
Install from [...]]]></description>
			<content:encoded><![CDATA[<p>So here is a list of games which can be played on Ubuntu.</p>
<p>On Ubuntu 8.10</p>
<p>1. <a style="font-weight: bold;" href="http://torcs.sourceforge.net/">TORCS</a> &#8211; The Open Racing Car Simulator &#8211; Racing game</p>
<p><span id="more-58"></span></p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhPhcSEysI/AAAAAAAAADQ/le6YtLSGO8o/s1600-h/linux-game-torcs.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352615593076116162" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhPhcSEysI/AAAAAAAAADQ/le6YtLSGO8o/s320/linux-game-torcs.png" border="0" alt="" width="320" height="240" /></a></p>
<p>2. <span style="font-weight: bold;">Planet Penguin Racer</span> &#8211; Racing Game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://3.bp.blogspot.com/_y5Z8wyEG7ZA/SkhNX0FluCI/AAAAAAAAAC4/ylCOE8usRCk/s1600-h/ppracer.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352613228644251682" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_y5Z8wyEG7ZA/SkhNX0FluCI/AAAAAAAAAC4/ylCOE8usRCk/s320/ppracer.png" border="0" alt="" width="320" height="240" /></a></p>
<p>3. <span style="font-weight: bold;">Extreme Tux Racer</span> &#8211; Racing Game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhQFj1EQDI/AAAAAAAAADY/9rkn3hWTutQ/s1600-h/extreme_tux_racer.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352616213577220146" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhQFj1EQDI/AAAAAAAAADY/9rkn3hWTutQ/s320/extreme_tux_racer.jpg" border="0" alt="" width="320" height="240" /></a></p>
<p>4. <span style="font-weight: bold;">Frozen Bubble</span> &#8211; Puzzle Game</p>
<p>Install from Synaptic</p>
<p><img class="aligncenter size-medium wp-image-109" title="frozenbubble" src="http://www.binarytides.com/blog/wp-content/uploads/2009/05/frozenbubble-300x234.jpg" alt="frozenbubble" width="300" height="234" /></p>
<p>5. <span style="font-weight: bold;">Supertuxkart</span> &#8211; Racing Game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhM8gt_xHI/AAAAAAAAACw/RzMVlnzt_vI/s1600-h/supertuxcart.png" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352612759588553842" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhM8gt_xHI/AAAAAAAAACw/RzMVlnzt_vI/s320/supertuxcart.png" border="0" alt="" width="320" height="240" /></a></p>
<p>6. <span style="font-weight: bold;">Alien Arena</span> &#8211; 3D first person shooting game</p>
<p>Install from Synaptic<a href="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhOMKSaz0I/AAAAAAAAADA/rqmtX6eFjgI/s1600-h/Alien_arena_2007_6_04_01.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"></a></p>
<p style="text-align: center;"><a href="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhOMKSaz0I/AAAAAAAAADA/rqmtX6eFjgI/s1600-h/Alien_arena_2007_6_04_01.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352614127956840258" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhOMKSaz0I/AAAAAAAAADA/rqmtX6eFjgI/s320/Alien_arena_2007_6_04_01.jpg" border="0" alt="" width="320" height="240" /></a></p>
<p>7. <span style="font-weight: bold;">Open Arena</span> &#8211; 3D first person shooting game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhRdnxseeI/AAAAAAAAADo/3xhpNafUNa4/s1600-h/OpenArena.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352617726465309154" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 256px;" src="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhRdnxseeI/AAAAAAAAADo/3xhpNafUNa4/s320/OpenArena.jpg" border="0" alt="" width="320" height="256" /></a></p>
<p>8. <span style="font-weight: bold;">Tremulous</span> &#8211; 3D first person shooting game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://2.bp.blogspot.com/_y5Z8wyEG7ZA/SkhU3rWZZvI/AAAAAAAAADw/OC7N2MPwZPg/s1600-h/tremulous.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352621472636036850" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 256px;" src="http://2.bp.blogspot.com/_y5Z8wyEG7ZA/SkhU3rWZZvI/AAAAAAAAADw/OC7N2MPwZPg/s320/tremulous.jpg" border="0" alt="" width="320" height="256" /></a></p>
<p>9. <span style="font-weight: bold;">NeverBall</span> &#8211; 3D floor tilting game</p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://3.bp.blogspot.com/_y5Z8wyEG7ZA/SkhPDFTYIrI/AAAAAAAAADI/OcuktuRoGtQ/s1600-h/neverball.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352615071511487154" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://3.bp.blogspot.com/_y5Z8wyEG7ZA/SkhPDFTYIrI/AAAAAAAAADI/OcuktuRoGtQ/s320/neverball.jpg" border="0" alt="" width="320" height="240" /></a></p>
<p>10. <a style="font-weight: bold;" href="http://maniadrive.raydium.org/">ManiaDrive</a> &#8211; Car Driving Game</p>
<p>Download deb for Ubuntu from www.getdeb.net</p>
<p style="text-align: center;"><a href="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhQiXtwOkI/AAAAAAAAADg/19McWc2B_nc/s1600-h/maniadrive.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352616708541528642" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 256px;" src="http://4.bp.blogspot.com/_y5Z8wyEG7ZA/SkhQiXtwOkI/AAAAAAAAADg/19McWc2B_nc/s320/maniadrive.jpg" border="0" alt="" width="320" height="256" /></a></p>
<p>11. <span style="font-weight: bold;">FreeCiv</span></p>
<p>12. <span style="font-weight: bold;">Nexuiz</span></p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhWCKde-zI/AAAAAAAAAD4/0QE8G46Ko6I/s1600-h/Nexuiz.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5352622752297581362" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 240px;" src="http://1.bp.blogspot.com/_y5Z8wyEG7ZA/SkhWCKde-zI/AAAAAAAAAD4/0QE8G46Ko6I/s320/Nexuiz.jpg" border="0" alt="" width="320" height="240" /></a></p>
<p>13. <span style="font-weight: bold;">Bat</span><span style="font-weight: bold;">tle for Wesn</span><span style="font-weight: bold;">oth</span></p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><img class="size-medium wp-image-100 aligncenter" title="battle_for_wesnoth" src="http://www.binarytides.com/blog/wp-content/uploads/2009/05/battle_for_wesnoth-300x225.jpg" alt="battle_for_wesnoth" width="300" height="225" /></p>
<p>14. <span style="font-weight: bold;">Secret Maryo Chronicles</span></p>
<p>Install from Synaptic</p>
<p style="text-align: center;"><a href="http://2.bp.blogspot.com/_y5Z8wyEG7ZA/SkTsMRXGcaI/AAAAAAAAACo/RkhFrka3Sh8/s1600-h/smc.jpg" onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}"><img id="BLOGGER_PHOTO_ID_5351661952785871266" class="aligncenter" style="border: 0pt none; margin-top: 0pt; margin-bottom: 10px; cursor: pointer; width: 320px; height: 241px;" src="http://2.bp.blogspot.com/_y5Z8wyEG7ZA/SkTsMRXGcaI/AAAAAAAAACo/RkhFrka3Sh8/s320/smc.jpg" border="0" alt="" width="320" height="241" /></a></p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=58&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/top-games-on-ubuntu-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TCP Connect Port Scanner with Linux Sockets (BSD)</title>
		<link>http://www.binarytides.com/blog/tcp-connect-port-scanner-with-linux-sockets-bsd/</link>
		<comments>http://www.binarytides.com/blog/tcp-connect-port-scanner-with-linux-sockets-bsd/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 17:24:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=51</guid>
		<description><![CDATA[TCP Connect Port Scanner works by trying to establish a connection with every port that is being scanned. If a connectio is established then the port is open otherwise closed.
The steps are simple :

1. Create a socket2. Run a Loop to connect with each port on the remote system ; if connection established then port [...]]]></description>
			<content:encoded><![CDATA[<p>TCP Connect Port Scanner works by trying to establish a connection with every port that is being scanned. If a connectio is established then the port is open otherwise closed.</p>
<p>The steps are simple :</p>
<p><span id="more-51"></span></p>
<p>1. Create a socket<br />2. Run a Loop to connect with each port on the remote system ; if connection established then port open otherwise closed.</p>
<p><b>Code</b> :</p>
<pre class="brush: cpp;">
#include&lt;stdio.h&gt;
#include&lt;sys/socket.h&gt;
#include&lt;netinet/in.h&gt;
#include&lt;errno.h&gt;
#include&lt;netdb.h&gt;
#include&lt;string.h&gt;

int main(int argc , char **argv)
{
 struct hostent *host;
 int err, i , net ,start , end;
 char hostname[100];
 struct sockaddr_in sa;
 //Get the hostname to scan
 printf(&quot;Enter hostname or IP : &quot;);
 gets(hostname);
 //Get start port number
 printf(&quot;\nEnter start port number : &quot;);
 scanf(&quot;%d&quot; , &amp;start);
 //Get end port number
 printf(&quot;\nEnter end port number : &quot;);
 scanf(&quot;%d&quot; , &amp;end);

 //Initialise the sockaddr_in structure
 strncpy((char*)&amp;sa , &quot;&quot; , sizeof sa);
 sa.sin_family = AF_INET;

 if(isdigit(hostname[0]))
 {
  printf(&quot;Doing inet_addr...&quot;);
  sa.sin_addr.s_addr = inet_addr(hostname);
  printf(&quot;Done\n&quot;);
 }
 else if((host = gethostbyname(hostname))!=0)
 {
  printf(&quot;Doing gethostbyname...&quot;);
  strncpy((char*)&amp;sa.sin_addr , (char*)host-&gt;h_addr , sizeof sa.sin_addr);
  printf(&quot;Done\n&quot;);
 }
 else
 {
  herror(hostname);
  exit(2);
 }
 //Start the port scan loop
 printf(&quot;Starting the portscan loop : \n&quot;);
 for(i=start ; i&lt;=end ; i++)
 {
  //Fill in the port number
  sa.sin_port = htons(i);
  //Create a socket of type internet
  net = socket(AF_INET , SOCK_STREAM , 0);
  //Check whether socket created fine or not
  if(net &lt; 0)
  {
   perror(&quot;\nSocket&quot;);
   exit(1);
  }
  //Connect using that socket and sockaddr structure
  err = connect(net , (struct sockaddr*)&amp;sa , sizeof sa);

  if(err&lt;0)
  {
   printf(&quot;%s %-5d %s\r&quot; , hostname , i, strerror(errno));
   fflush(stdout);
  }
  else
  {
   printf(&quot;%s %-5d accepted. \n&quot;,  hostname , i);
   //Now shutdown the read and write operations on this socket
   if(shutdown(net , SHUT_RDWR) &lt; 0)
   {
    //Print error with error message mapped from err_no
    perror(&quot;\nShutdown&quot;);
    exit(1);
   }
  }
  close(net);
 }
 printf(&quot;\r&quot;);
 fflush(stdout);
 return(0);
}
</pre>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=51&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/tcp-connect-port-scanner-with-linux-sockets-bsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C Packet Sniffer Code with Libpcap and Linux Sockets (BSD)</title>
		<link>http://www.binarytides.com/blog/c-packet-sniffer-code-with-libpcap-and-linux-sockets-bsd/</link>
		<comments>http://www.binarytides.com/blog/c-packet-sniffer-code-with-libpcap-and-linux-sockets-bsd/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 13:51:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=49</guid>
		<description><![CDATA[Libpcap is a packe capture library which can be used to sniff packets or network traffic over a network interface. Pcap Documentation gives a description of the methods and data structures available in the libpcap library.

To install libpcap on your linux distro you can either download the source from the website and compile it and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tcpdump.org/">Libpcap</a> is a packe capture library which can be used to sniff packets or network traffic over a network interface. <a href="http://www.tcpdump.org/pcap3_man.html">Pcap Documentation</a> gives a description of the methods and data structures available in the libpcap library.</p>
<p><span id="more-49"></span></p>
<p>To install libpcap on your linux distro you can either download the source from the <a href="http://www.tcpdump.org/">website</a> and compile it and install. Or if you are on a distro like ubuntu then it can be installed from synaptic package manager. In the list of packages in Synaptic Package Manager look for 2 packages named as libpcap0.8 and libpcap0.8-dev. Install both of them.</p>
<p>To start with the C program the simple steps would be :</p>
<p>1. Find all available devices &#8211; find_alldevs()</p>
<p>find_alldevs() is the function which can be used to get a list of all available network devices or interfaces present on the machine or which can be opened by pcap_open_live() for sniffing purpose.</p>
<p>The prototype is as :</p>
<p>int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf)</p>
<p>where alldevsp is a pointer to an array of of pcap_if_t structures and errbuf is a character pointer and will contain any error message that occured during the function call.</p>
<p>2. Select a device for sniffing data &#8211; pcap_open_live()</p>
<p>pcap_open_live() is the function to get a packet capture descriptor or a handle to a device which has been opened up for sniffing. The protoype is as :</p>
<p>pcap_t *pcap_open_live(const char *device, int snaplen,int promisc, int to_ms, char *errbuf)</p>
<p>device &#8211; is the name of the device as obtained from the call to pcap_findalldevs.<br />
snaplen &#8211; is the maximum amount of data to be captured. 65536 should be sufficient length.<br />
promisc &#8211; 0 or 1 to indicate whether to open the device in promiscuous mode.<br />
to_ms &#8211; the timeout in milliseconds , 0 for no timeout<br />
errbuf &#8211; buffer to contain any error message</p>
<p>It returns a device handler in the form of the structure pcap_t which can be used by pcap_loop() to capture data from.</p>
<p>3. Start sniffing the device &#8211; pcap_loop()<br />
4. Process the sniffed packet &#8211; user defined callback method</p>
<p><strong>Code</strong> :</p>
<pre class="brush: cpp;">

 /*
 Packet sniffer using libpcap library
*/
#include&lt;pcap.h&gt;
#include&lt;stdio.h&gt;
#include&lt;net/ethernet.h&gt;
#include&lt;netinet/ip_icmp.h&gt; //Provides declarations for icmp header
#include&lt;netinet/udp.h&gt; //Provides declarations for udp header
#include&lt;netinet/tcp.h&gt; //Provides declarations for tcp header
#include&lt;netinet/ip.h&gt; //Provides declarations for ip header

void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet);
void process_ip_packet(unsigned char* , int);
void print_ip_header(unsigned char* , int);
void print_tcp_header(unsigned char* buffer , int size);
void print_udp_header(unsigned char* , int);

FILE *logfile;
struct sockaddr_in source,dest;

int main()
{
 pcap_if_t alldevsp[100] , *device;
 pcap_t *handle; //Handle of the device that shall be sniffed

 char errbuf[100] , *devname , **devs;
 int count = 1 , n;
 //First get the list of available devices
 printf(&quot;Finding available devices ... &quot;);
 if(pcap_findalldevs(&amp;alldevsp, errbuf))
 {
  printf(&quot;Error finding devices : %s&quot; , errbuf);
  exit(1);
 }
 printf(&quot;Done&quot;);
 //Print the available devices
 printf(&quot;\nAvailable Devices are :\n&quot;);
 device = alldevsp;
 while(device != NULL)
 {
  *(devs + count) = device-&gt;name;
  printf(&quot;%d. %s - %s\n&quot;, count++ , device-&gt;name , device-&gt;description);
  device = device-&gt;next;

 }
 //Ask user which device to sniff
 printf(&quot;Enter the number of the device you want to sniff : &quot;);
 scanf(&quot;%d&quot; , &amp;n);
 devname = *(devs + count - 1);
 //Open the device for sniffing
 printf(&quot;Opening device for sniffing ... &quot;);
 handle = pcap_open_live(&quot;eth0&quot; , 65536 , 1 , 0 , errbuf);
 if (handle == NULL) {
  fprintf(stderr, &quot;Couldn't open device eth0 : %s\n&quot; , errbuf);
  exit(1);
 }
 printf(&quot;Done\n&quot;);

 logfile=fopen(&quot;log.txt&quot;,&quot;w&quot;);
 if(logfile==NULL) printf(&quot;Unable to create file.&quot;);

 //Put the device in sniff loop
 pcap_loop(handle , -1 , process_packet , NULL);
 return 0;
}

void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
{
 int size = header-&gt;len;
 struct ether_header *ethh;
 ethh = (struct ether_header *)packet;
 //Print the ethernet header in the log file

 if(ntohs(ethh-&gt;ether_type) == ETHERTYPE_IP)
 {

  process_ip_packet(packet + sizeof *ethh , size - sizeof ethh);
  printf(&quot;%d&quot; , sizeof *ethh);
  fflush(stdout);
 }
 return 0;
}

void process_ip_packet(unsigned char* buffer, int size)
{
 //Get the IP Header part of this packet
 struct iphdr *iph = (struct iphdr*)buffer;
 switch (iph-&gt;protocol) //Check the Protocol and do accordingly...
 {
  case 1:  //ICMP Protocol
   //PrintIcmpPacket(Buffer,Size);
   break;
  case 2:  //IGMP Protocol
   break;
  case 6:  //TCP Protocol
   print_tcp_packet(buffer , size);
   break;
  case 17: //UDP Protocol
   print_udp_packet(buffer , size);
   break;
  default: //Some Other Protocol like ARP etc.
   break;
 }
}

void print_ip_header(unsigned char* Buffer, int Size)
{
 unsigned short iphdrlen;

 struct iphdr *iph = (struct iphdr *)Buffer;
 iphdrlen =iph-&gt;ihl*4;

 memset(&amp;source, 0, sizeof(source));
 source.sin_addr.s_addr = iph-&gt;saddr;

 memset(&amp;dest, 0, sizeof(dest));
 dest.sin_addr.s_addr = iph-&gt;daddr;

 fprintf(logfile,&quot;\n&quot;);
 fprintf(logfile,&quot;IP Header\n&quot;);
 fprintf(logfile,&quot;   |-IP Version        : %d\n&quot;,(unsigned int)iph-&gt;version);
 fprintf(logfile,&quot;   |-IP Header Length  : %d DWORDS or %d Bytes\n&quot;,(unsigned int)iph-&gt;ihl,((unsigned int)(iph-&gt;ihl))*4);
 fprintf(logfile,&quot;   |-Type Of Service   : %d\n&quot;,(unsigned int)iph-&gt;tos);
 fprintf(logfile,&quot;   |-IP Total Length   : %d  Bytes(Size of Packet)\n&quot;,ntohs(iph-&gt;tot_len));
 fprintf(logfile,&quot;   |-Identification    : %d\n&quot;,ntohs(iph-&gt;id));
 //fprintf(logfile,&quot;   |-Reserved ZERO Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_reserved_zero);
 //fprintf(logfile,&quot;   |-Dont Fragment Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_dont_fragment);
 //fprintf(logfile,&quot;   |-More Fragment Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_more_fragment);
 fprintf(logfile,&quot;   |-TTL      : %d\n&quot;,(unsigned int)iph-&gt;ttl);
 fprintf(logfile,&quot;   |-Protocol : %d\n&quot;,(unsigned int)iph-&gt;protocol);
 fprintf(logfile,&quot;   |-Checksum : %d\n&quot;,ntohs(iph-&gt;check));
 fprintf(logfile,&quot;   |-Source IP        : %s\n&quot;,inet_ntoa(source.sin_addr));
 fprintf(logfile,&quot;   |-Destination IP   : %s\n&quot;,inet_ntoa(dest.sin_addr));
}

void print_tcp_packet(unsigned char* Buffer, int Size)
{
 unsigned short iphdrlen;

 struct iphdr *iph = (struct iphdr *)Buffer;
 iphdrlen = iph-&gt;ihl*4;

 struct tcphdr *tcph=(struct tcphdr*)(Buffer + iphdrlen);

 fprintf(logfile,&quot;\n\n***********************TCP Packet*************************\n&quot;); 

 print_ip_header(Buffer,Size);

 fprintf(logfile,&quot;\n&quot;);
 fprintf(logfile,&quot;TCP Header\n&quot;);
 fprintf(logfile,&quot;   |-Source Port      : %u\n&quot;,ntohs(tcph-&gt;source));
 fprintf(logfile,&quot;   |-Destination Port : %u\n&quot;,ntohs(tcph-&gt;dest));
 fprintf(logfile,&quot;   |-Sequence Number    : %u\n&quot;,ntohl(tcph-&gt;seq));
 fprintf(logfile,&quot;   |-Acknowledge Number : %u\n&quot;,ntohl(tcph-&gt;ack_seq));
 fprintf(logfile,&quot;   |-Header Length      : %d DWORDS or %d BYTES\n&quot; ,(unsigned int)tcph-&gt;doff,(unsigned int)tcph-&gt;doff*4);
 //fprintf(logfile,&quot;   |-CWR Flag : %d\n&quot;,(unsigned int)tcph-&gt;cwr);
 //fprintf(logfile,&quot;   |-ECN Flag : %d\n&quot;,(unsigned int)tcph-&gt;ece);
 fprintf(logfile,&quot;   |-Urgent Flag          : %d\n&quot;,(unsigned int)tcph-&gt;urg);
 fprintf(logfile,&quot;   |-Acknowledgement Flag : %d\n&quot;,(unsigned int)tcph-&gt;ack);
 fprintf(logfile,&quot;   |-Push Flag            : %d\n&quot;,(unsigned int)tcph-&gt;psh);
 fprintf(logfile,&quot;   |-Reset Flag           : %d\n&quot;,(unsigned int)tcph-&gt;rst);
 fprintf(logfile,&quot;   |-Synchronise Flag     : %d\n&quot;,(unsigned int)tcph-&gt;syn);
 fprintf(logfile,&quot;   |-Finish Flag          : %d\n&quot;,(unsigned int)tcph-&gt;fin);
 fprintf(logfile,&quot;   |-Window         : %d\n&quot;,ntohs(tcph-&gt;window));
 fprintf(logfile,&quot;   |-Checksum       : %d\n&quot;,ntohs(tcph-&gt;check));
 fprintf(logfile,&quot;   |-Urgent Pointer : %d\n&quot;,tcph-&gt;urg_ptr);
 fprintf(logfile,&quot;\n&quot;);
 fprintf(logfile,&quot;                        DATA Dump                         &quot;);
 fprintf(logfile,&quot;\n&quot;);

 fprintf(logfile,&quot;IP Header\n&quot;);
 PrintData(Buffer,iphdrlen);

 fprintf(logfile,&quot;TCP Header\n&quot;);
 PrintData(Buffer+iphdrlen,tcph-&gt;doff*4);

 fprintf(logfile,&quot;Data Payload\n&quot;);
 PrintData(Buffer + iphdrlen + tcph-&gt;doff*4 , (Size - tcph-&gt;doff*4-iph-&gt;ihl*4) );

 fprintf(logfile,&quot;\n###########################################################&quot;);
}

void print_udp_packet(unsigned char *Buffer , int Size)
{

 unsigned short iphdrlen;

 struct iphdr *iph = (struct iphdr *)Buffer;
 iphdrlen = iph-&gt;ihl*4;

 struct udphdr *udph = (struct udphdr*)(Buffer + iphdrlen);

 fprintf(logfile,&quot;\n\n***********************UDP Packet*************************\n&quot;);

 print_ip_header(Buffer,Size);   

 fprintf(logfile,&quot;\nUDP Header\n&quot;);
 fprintf(logfile,&quot;   |-Source Port      : %d\n&quot; , ntohs(udph-&gt;source));
 fprintf(logfile,&quot;   |-Destination Port : %d\n&quot; , ntohs(udph-&gt;dest));
 fprintf(logfile,&quot;   |-UDP Length       : %d\n&quot; , ntohs(udph-&gt;len));
 fprintf(logfile,&quot;   |-UDP Checksum     : %d\n&quot; , ntohs(udph-&gt;check));

 fprintf(logfile,&quot;\n&quot;);
 fprintf(logfile,&quot;IP Header\n&quot;);
 PrintData(Buffer , iphdrlen);

 fprintf(logfile,&quot;UDP Header\n&quot;);
 PrintData(Buffer+iphdrlen , sizeof udph);

 fprintf(logfile,&quot;Data Payload\n&quot;);
 PrintData(Buffer + iphdrlen + sizeof udph ,( Size - sizeof udph - iph-&gt;ihl * 4 ));

 fprintf(logfile,&quot;\n###########################################################&quot;);
}

void print_icmp_packet(unsigned char* Buffer , int Size)
{
 unsigned short iphdrlen;

 struct iphdr *iph = (struct iphdr *)Buffer;
 iphdrlen = iph-&gt;ihl*4;

 struct icmphdr *icmph = (struct icmphdr *)(Buffer + iphdrlen);

 fprintf(logfile,&quot;\n\n***********************ICMP Packet*************************\n&quot;); 

 print_ip_header(Buffer , Size);

 fprintf(logfile,&quot;\n&quot;);

 fprintf(logfile,&quot;ICMP Header\n&quot;);
 fprintf(logfile,&quot;   |-Type : %d&quot;,(unsigned int)(icmph-&gt;type));

 if((unsigned int)(icmph-&gt;type) == 11)
  fprintf(logfile,&quot;  (TTL Expired)\n&quot;);
 else if((unsigned int)(icmph-&gt;type) == ICMP_ECHOREPLY)
  fprintf(logfile,&quot;  (ICMP Echo Reply)\n&quot;);
 fprintf(logfile,&quot;   |-Code : %d\n&quot;,(unsigned int)(icmph-&gt;code));
 fprintf(logfile,&quot;   |-Checksum : %d\n&quot;,ntohs(icmph-&gt;checksum));
 //fprintf(logfile,&quot;   |-ID       : %d\n&quot;,ntohs(icmph-&gt;id));
 //fprintf(logfile,&quot;   |-Sequence : %d\n&quot;,ntohs(icmph-&gt;sequence));
 fprintf(logfile,&quot;\n&quot;);

 fprintf(logfile,&quot;IP Header\n&quot;);
 PrintData(Buffer,iphdrlen);

 fprintf(logfile,&quot;UDP Header\n&quot;);
 PrintData(Buffer + iphdrlen , sizeof icmph);

 fprintf(logfile,&quot;Data Payload\n&quot;);
 PrintData(Buffer + iphdrlen + sizeof icmph , (Size - sizeof icmph - iph-&gt;ihl * 4));

 fprintf(logfile,&quot;\n###########################################################&quot;);
}

void PrintData (unsigned char* data , int Size)
{
 int i,j;
 for(i=0 ; i &lt; Size ; i++)
 {
  if( i!=0 &amp;&amp; i%16==0)   //if one line of hex printing is complete...
  {
   fprintf(logfile,&quot;         &quot;);
   for(j=i-16 ; j&lt;i ; j++)
   {
    if(data[j]&gt;=32 &amp;&amp; data[j]&lt;=128)
     fprintf(logfile,&quot;%c&quot;,(unsigned char)data[j]); //if its a number or alphabet

    else fprintf(logfile,&quot;.&quot;); //otherwise print a dot
   }
   fprintf(logfile,&quot;\n&quot;);
  } 

  if(i%16==0) fprintf(logfile,&quot;   &quot;);
  fprintf(logfile,&quot; %02X&quot;,(unsigned int)data[i]);

  if( i==Size-1)  //print the last spaces
  {
   for(j=0;j&lt;15-i%16;j++) fprintf(logfile,&quot;   &quot;); //extra spaces

   fprintf(logfile,&quot;         &quot;);

   for(j=i-i%16 ; j&lt;=i ; j++)
   {
    if(data[j]&gt;=32 &amp;&amp; data[j]&lt;=128) fprintf(logfile,&quot;%c&quot;,(unsigned char)data[j]);
    else fprintf(logfile,&quot;.&quot;);
   }
   fprintf(logfile,&quot;\n&quot;);
  }
 }
}   
</pre>
<p>Compile : gcc sniffer.c -lpcap -o sniffer<br />
Run : sudo ./sniffer</p>
<p>The program requires superuser or root privileges to be able to sniff the packets.<br />
Wireshark(previously ethereal) and tcpdump are examples of applications which use the libpcap library on linux to capture packet data.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=49&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/c-packet-sniffer-code-with-libpcap-and-linux-sockets-bsd/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Packet Sniffer Code in C using Linux Sockets (BSD)</title>
		<link>http://www.binarytides.com/blog/packet-sniffer-code-in-c-using-linux-sockets-bsd/</link>
		<comments>http://www.binarytides.com/blog/packet-sniffer-code-in-c-using-linux-sockets-bsd/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 08:50:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=48</guid>
		<description><![CDATA[To code a sniffer in C (Linux) the steps would be :
1. Create a Raw Socket.
2. Put it in a recvfrom loop.
A raw socket when put in recvfrom receives all incoming packets. The following code shows an example of such a sniffer. Note that it sniffs only incoming packets. For sniffing all traffic on a [...]]]></description>
			<content:encoded><![CDATA[<p>To code a sniffer in C (Linux) the steps would be :</p>
<p>1. Create a Raw Socket.<br />
2. Put it in a recvfrom loop.</p>
<p>A raw socket when put in recvfrom receives all incoming packets. The following code shows an example of such a sniffer. Note that it sniffs only incoming packets. For sniffing all traffic on a network a packet capture library like libpcap can be used.</p>
<p><span id="more-48"></span></p>
<p><strong>Code </strong> : sniffer.c</p>
<pre class="brush: cpp;">
#include&lt;netinet/in.h&gt;
#include&lt;errno.h&gt;
#include&lt;netdb.h&gt;
#include&lt;stdio.h&gt;	//For standard things
#include&lt;netinet/ip_icmp.h&gt;	//Provides declarations for icmp header
#include&lt;netinet/udp.h&gt;	//Provides declarations for udp header
#include&lt;netinet/tcp.h&gt;	//Provides declarations for tcp header
#include&lt;netinet/ip.h&gt;	//Provides declarations for ip header
#include&lt;sys/socket.h&gt;
#include&lt;arpa/inet.h&gt;
#include&lt;sys/ioctl.h&gt;
#include&lt;sys/time.h&gt;
#include&lt;sys/types.h&gt;
#include&lt;unistd.h&gt;

void ProcessPacket(unsigned char* , int);
void print_ip_header(unsigned char* , int);
void print_tcp_header(unsigned char* buffer , int size);
void print_udp_header(unsigned char* , int);

int sock_raw;
FILE *logfile;
int tcp=0,udp=0,icmp=0,others=0,igmp=0,total=0,i,j;
struct sockaddr_in source,dest;

int main()
{
	int saddr_size , data_size;
	struct sockaddr_in saddr;
	struct in_addr in;

	unsigned char *buffer = (unsigned char *)malloc(65536); //Its Big!

	logfile=fopen(&quot;log.txt&quot;,&quot;w&quot;);
	if(logfile==NULL) printf(&quot;Unable to create file.&quot;);
	printf(&quot;Starting...\n&quot;);
	//Create a raw socket that shall sniff
	sock_raw = socket(AF_INET , SOCK_RAW , IPPROTO_TCP);
	if(sock_raw &lt; 0)
	{
		printf(&quot;Socket Error\n&quot;);
		return 1;
	}
	while(1)
	{
		saddr_size = sizeof saddr;
		//Receive a packet
		data_size = recvfrom(sock_raw , buffer , 65536 , 0 , &amp;saddr , &amp;saddr_size);
		if(data_size &lt;0 )
		{
			printf(&quot;Recvfrom error , failed to get packets\n&quot;);
			return 1;
		}
		//Now process the packet
		ProcessPacket(buffer , data_size);
	}
	close(sock_raw);
	printf(&quot;Finished&quot;);
	return 0;
}

void ProcessPacket(unsigned char* buffer, int size)
{
	//Get the IP Header part of this packet
	struct iphdr *iph = (struct iphdr*)buffer;
	++total;
	switch (iph-&gt;protocol) //Check the Protocol and do accordingly...
	{
		case 1:  //ICMP Protocol
			++icmp;
			//PrintIcmpPacket(Buffer,Size);
			break;

		case 2:  //IGMP Protocol
			++igmp;
			break;

		case 6:  //TCP Protocol
			++tcp;
			print_tcp_packet(buffer , size);
			break;

		case 17: //UDP Protocol
			++udp;
			print_udp_packet(buffer , size);
			break;

		default: //Some Other Protocol like ARP etc.
			++others;
			break;
	}
	printf(&quot;TCP : %d   UDP : %d   ICMP : %d   IGMP : %d   Others : %d   Total : %d\r&quot;,tcp,udp,icmp,igmp,others,total);
}

void print_ip_header(unsigned char* Buffer, int Size)
{
	unsigned short iphdrlen;

	struct iphdr *iph = (struct iphdr *)Buffer;
	iphdrlen =iph-&gt;ihl*4;

	memset(&amp;source, 0, sizeof(source));
	source.sin_addr.s_addr = iph-&gt;saddr;

	memset(&amp;dest, 0, sizeof(dest));
	dest.sin_addr.s_addr = iph-&gt;daddr;

	fprintf(logfile,&quot;\n&quot;);
	fprintf(logfile,&quot;IP Header\n&quot;);
	fprintf(logfile,&quot;   |-IP Version        : %d\n&quot;,(unsigned int)iph-&gt;version);
	fprintf(logfile,&quot;   |-IP Header Length  : %d DWORDS or %d Bytes\n&quot;,(unsigned int)iph-&gt;ihl,((unsigned int)(iph-&gt;ihl))*4);
	fprintf(logfile,&quot;   |-Type Of Service   : %d\n&quot;,(unsigned int)iph-&gt;tos);
	fprintf(logfile,&quot;   |-IP Total Length   : %d  Bytes(Size of Packet)\n&quot;,ntohs(iph-&gt;tot_len));
	fprintf(logfile,&quot;   |-Identification    : %d\n&quot;,ntohs(iph-&gt;id));
	//fprintf(logfile,&quot;   |-Reserved ZERO Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_reserved_zero);
	//fprintf(logfile,&quot;   |-Dont Fragment Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_dont_fragment);
	//fprintf(logfile,&quot;   |-More Fragment Field   : %d\n&quot;,(unsigned int)iphdr-&gt;ip_more_fragment);
	fprintf(logfile,&quot;   |-TTL      : %d\n&quot;,(unsigned int)iph-&gt;ttl);
	fprintf(logfile,&quot;   |-Protocol : %d\n&quot;,(unsigned int)iph-&gt;protocol);
	fprintf(logfile,&quot;   |-Checksum : %d\n&quot;,ntohs(iph-&gt;check));
	fprintf(logfile,&quot;   |-Source IP        : %s\n&quot;,inet_ntoa(source.sin_addr));
	fprintf(logfile,&quot;   |-Destination IP   : %s\n&quot;,inet_ntoa(dest.sin_addr));
}

void print_tcp_packet(unsigned char* Buffer, int Size)
{
	unsigned short iphdrlen;

	struct iphdr *iph = (struct iphdr *)Buffer;
	iphdrlen = iph-&gt;ihl*4;

	struct tcphdr *tcph=(struct tcphdr*)(Buffer + iphdrlen);

	fprintf(logfile,&quot;\n\n***********************TCP Packet*************************\n&quot;);	

	print_ip_header(Buffer,Size);

	fprintf(logfile,&quot;\n&quot;);
	fprintf(logfile,&quot;TCP Header\n&quot;);
	fprintf(logfile,&quot;   |-Source Port      : %u\n&quot;,ntohs(tcph-&gt;source));
	fprintf(logfile,&quot;   |-Destination Port : %u\n&quot;,ntohs(tcph-&gt;dest));
	fprintf(logfile,&quot;   |-Sequence Number    : %u\n&quot;,ntohl(tcph-&gt;seq));
	fprintf(logfile,&quot;   |-Acknowledge Number : %u\n&quot;,ntohl(tcph-&gt;ack_seq));
	fprintf(logfile,&quot;   |-Header Length      : %d DWORDS or %d BYTES\n&quot; ,(unsigned int)tcph-&gt;doff,(unsigned int)tcph-&gt;doff*4);
	//fprintf(logfile,&quot;   |-CWR Flag : %d\n&quot;,(unsigned int)tcph-&gt;cwr);
	//fprintf(logfile,&quot;   |-ECN Flag : %d\n&quot;,(unsigned int)tcph-&gt;ece);
	fprintf(logfile,&quot;   |-Urgent Flag          : %d\n&quot;,(unsigned int)tcph-&gt;urg);
	fprintf(logfile,&quot;   |-Acknowledgement Flag : %d\n&quot;,(unsigned int)tcph-&gt;ack);
	fprintf(logfile,&quot;   |-Push Flag            : %d\n&quot;,(unsigned int)tcph-&gt;psh);
	fprintf(logfile,&quot;   |-Reset Flag           : %d\n&quot;,(unsigned int)tcph-&gt;rst);
	fprintf(logfile,&quot;   |-Synchronise Flag     : %d\n&quot;,(unsigned int)tcph-&gt;syn);
	fprintf(logfile,&quot;   |-Finish Flag          : %d\n&quot;,(unsigned int)tcph-&gt;fin);
	fprintf(logfile,&quot;   |-Window         : %d\n&quot;,ntohs(tcph-&gt;window));
	fprintf(logfile,&quot;   |-Checksum       : %d\n&quot;,ntohs(tcph-&gt;check));
	fprintf(logfile,&quot;   |-Urgent Pointer : %d\n&quot;,tcph-&gt;urg_ptr);
	fprintf(logfile,&quot;\n&quot;);
	fprintf(logfile,&quot;                        DATA Dump                         &quot;);
	fprintf(logfile,&quot;\n&quot;);

	fprintf(logfile,&quot;IP Header\n&quot;);
	PrintData(Buffer,iphdrlen);

	fprintf(logfile,&quot;TCP Header\n&quot;);
	PrintData(Buffer+iphdrlen,tcph-&gt;doff*4);

	fprintf(logfile,&quot;Data Payload\n&quot;);
	PrintData(Buffer + iphdrlen + tcph-&gt;doff*4 , (Size - tcph-&gt;doff*4-iph-&gt;ihl*4) );

	fprintf(logfile,&quot;\n###########################################################&quot;);
}

void print_udp_packet(unsigned char *Buffer , int Size)
{

	unsigned short iphdrlen;

	struct iphdr *iph = (struct iphdr *)Buffer;
	iphdrlen = iph-&gt;ihl*4;

	struct udphdr *udph = (struct udphdr*)(Buffer + iphdrlen);

	fprintf(logfile,&quot;\n\n***********************UDP Packet*************************\n&quot;);

	print_ip_header(Buffer,Size);			

	fprintf(logfile,&quot;\nUDP Header\n&quot;);
	fprintf(logfile,&quot;   |-Source Port      : %d\n&quot; , ntohs(udph-&gt;source));
	fprintf(logfile,&quot;   |-Destination Port : %d\n&quot; , ntohs(udph-&gt;dest));
	fprintf(logfile,&quot;   |-UDP Length       : %d\n&quot; , ntohs(udph-&gt;len));
	fprintf(logfile,&quot;   |-UDP Checksum     : %d\n&quot; , ntohs(udph-&gt;check));

	fprintf(logfile,&quot;\n&quot;);
	fprintf(logfile,&quot;IP Header\n&quot;);
	PrintData(Buffer , iphdrlen);

	fprintf(logfile,&quot;UDP Header\n&quot;);
	PrintData(Buffer+iphdrlen , sizeof udph);

	fprintf(logfile,&quot;Data Payload\n&quot;);
	PrintData(Buffer + iphdrlen + sizeof udph ,( Size - sizeof udph - iph-&gt;ihl * 4 ));

	fprintf(logfile,&quot;\n###########################################################&quot;);
}

void print_icmp_packet(unsigned char* Buffer , int Size)
{
	unsigned short iphdrlen;

	struct iphdr *iph = (struct iphdr *)Buffer;
	iphdrlen = iph-&gt;ihl*4;

	struct icmphdr *icmph = (struct icmphdr *)(Buffer + iphdrlen);

	fprintf(logfile,&quot;\n\n***********************ICMP Packet*************************\n&quot;);	

	print_ip_header(Buffer , Size);

	fprintf(logfile,&quot;\n&quot;);

	fprintf(logfile,&quot;ICMP Header\n&quot;);
	fprintf(logfile,&quot;   |-Type : %d&quot;,(unsigned int)(icmph-&gt;type));

	if((unsigned int)(icmph-&gt;type) == 11)
		fprintf(logfile,&quot;  (TTL Expired)\n&quot;);
	else if((unsigned int)(icmph-&gt;type) == ICMP_ECHOREPLY)
		fprintf(logfile,&quot;  (ICMP Echo Reply)\n&quot;);
	fprintf(logfile,&quot;   |-Code : %d\n&quot;,(unsigned int)(icmph-&gt;code));
	fprintf(logfile,&quot;   |-Checksum : %d\n&quot;,ntohs(icmph-&gt;checksum));
	//fprintf(logfile,&quot;   |-ID       : %d\n&quot;,ntohs(icmph-&gt;id));
	//fprintf(logfile,&quot;   |-Sequence : %d\n&quot;,ntohs(icmph-&gt;sequence));
	fprintf(logfile,&quot;\n&quot;);

	fprintf(logfile,&quot;IP Header\n&quot;);
	PrintData(Buffer,iphdrlen);

	fprintf(logfile,&quot;UDP Header\n&quot;);
	PrintData(Buffer + iphdrlen , sizeof icmph);

	fprintf(logfile,&quot;Data Payload\n&quot;);
	PrintData(Buffer + iphdrlen + sizeof icmph , (Size - sizeof icmph - iph-&gt;ihl * 4));

	fprintf(logfile,&quot;\n###########################################################&quot;);
}

void PrintData (unsigned char* data , int Size)
{

	for(i=0 ; i &lt; Size ; i++)
	{
		if( i!=0 &amp;&amp; i%16==0)   //if one line of hex printing is complete...
		{
			fprintf(logfile,&quot;         &quot;);
			for(j=i-16 ; j&lt;i ; j++)
			{
				if(data[j]&gt;=32 &amp;&amp; data[j]&lt;=128)
					fprintf(logfile,&quot;%c&quot;,(unsigned char)data[j]); //if its a number or alphabet

				else fprintf(logfile,&quot;.&quot;); //otherwise print a dot
			}
			fprintf(logfile,&quot;\n&quot;);
		} 

		if(i%16==0) fprintf(logfile,&quot;   &quot;);
			fprintf(logfile,&quot; %02X&quot;,(unsigned int)data[i]);

		if( i==Size-1)  //print the last spaces
		{
			for(j=0;j&lt;15-i%16;j++) fprintf(logfile,&quot;   &quot;); //extra spaces

			fprintf(logfile,&quot;         &quot;);

			for(j=i-i%16 ; j&lt;=i ; j++)
			{
				if(data[j]&gt;=32 &amp;&amp; data[j]&lt;=128) fprintf(logfile,&quot;%c&quot;,(unsigned char)data[j]);
				else fprintf(logfile,&quot;.&quot;);
			}
			fprintf(logfile,&quot;\n&quot;);
		}
	}
}
</pre>
<p>Compile : gcc sniffer.c</p>
<p>The program must be run as root user or superuser privileges. e.g. sudo ./a.out in ubuntu<br />
The program creates raw sockets which require root access.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=48&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/packet-sniffer-code-in-c-using-linux-sockets-bsd/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Konqueror Dolphin not accessing Windows FTP Server</title>
		<link>http://www.binarytides.com/blog/konqueror-dolphin-not-accessing-windows-ftp-server/</link>
		<comments>http://www.binarytides.com/blog/konqueror-dolphin-not-accessing-windows-ftp-server/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 17:21:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=45</guid>
		<description><![CDATA[Hmmm, so it looks like that konqueror or dolphin wont access a windows ftp server properly whereas its absolutely fine and fast with linux ftp servers. One reason for this could be the NTLM authentication that windows ftp servers use.

So using gftp or filezilla or fireftp  in this case is a better option.
]]></description>
			<content:encoded><![CDATA[<p>Hmmm, so it looks like that konqueror or dolphin wont access a windows ftp server properly whereas its absolutely fine and fast with linux ftp servers. One reason for this could be the NTLM authentication that windows ftp servers use.</p>
<p><span id="more-45"></span></p>
<p>So using gftp or filezilla or fireftp  in this case is a better option.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=45&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/konqueror-dolphin-not-accessing-windows-ftp-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run PHP scripts automatically at intervals &#8211; use Cron Jobs</title>
		<link>http://www.binarytides.com/blog/run-php-scripts-automatically-at-intervals-use-cron-jobs/</link>
		<comments>http://www.binarytides.com/blog/run-php-scripts-automatically-at-intervals-use-cron-jobs/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 12:21:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[Cron]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=41</guid>
		<description><![CDATA[Automation may be needed in to order to run certain scripts at regular intervals for tasks like scraping , extracting or crawling data from web or do some regular tasks like sending emails or whatever.

To automate a script is simple. The webhost must provide cron facility. Cron is a utility which can be used to [...]]]></description>
			<content:encoded><![CDATA[<p>Automation may be needed in to order to run certain scripts at regular intervals for tasks like scraping , extracting or crawling data from web or do some regular tasks like sending emails or whatever.</p>
<p><span id="more-41"></span></p>
<p>To automate a script is simple. The webhost must provide cron facility. Cron is a utility which can be used to execute a set of commands at a given schedule of time.</p>
<p>For e.g. if a php script called regular.php is to be executed regularly every day or every month or on certain weekdays then cron can be configured to execute the script at defined schedules and hence automation is achieved. Since web hosts are alive and online most of the times the automation process is more useful when used on a web server rather than a home pc.</p>
<p>Cron can be configured from Cpanel and via ssh terminal as well.</p>
<p>To configure cron from ssh terminal simply login to your webspace using ssh.</p>
<p>The command crontab -l will show what schedules have already been made or what tasks are to execute according to current cron settings.</p>
<p>Cron settings consist of lines like this</p>
<p><strong>* * * * * /command/to/execute</strong></p>
<p>The 5 stars indicate the time to execute and the /command/to/execute is the path to the script or command which should be executed at that point of time.</p>
<p>If you put the regular.php script in the www folder on your webhost then the path could be :<br />
<strong> </strong></p>
<p><strong>/home/username/www/regular.php</strong></p>
<p>So the command to execute it would be</p>
<p><strong>php /home/username/www/regular.php</strong></p>
<p>The above command needs a time schedule to run.</p>
<p>The 5 stars indicate the following</p>
<p>Minute Hour Day Month Day    &#8212; in that order</p>
<p>Minute &#8211; 0-59<br />
Hour &#8211; 0-23<br />
Day &#8211; 1-31<br />
Month &#8211; 1-12<br />
Weekday 0-6  (o= Sunday)<br />
* means any</p>
<p>So to execute a script everyday<br />
<strong> 0 0 * * *</strong> &#8211; means At 00:00 anyday anymonth anyweekday</p>
<p>So the cron line would be<br />
<strong> 0 0 * * * php /home/username/www/regular.php</strong></p>
<p>All such cron schedule lines can be written in a txt file and this cron file can be given to crontab to set the schedules using the following command :</p>
<pre class="brush: cpp;">
crontab crontasks.txt
</pre>
<p>Another line that can be added on the top of the crontasks.txt file is<br />
<strong> MAILTO=user@site.com</strong></p>
<p>and this is the email address to which the execution results shall be mailed.</p>
<p>So the crontasks.txt file can look like this :</p>
<p>MAILTO=user@site.com<br />
0 0 * * * php /home/username/www/regular.php</p>
<p>should be saved and the command :</p>
<pre class="brush: cpp;">
$crontab crontasks.txt
</pre>
<p>would set it.</p>
<p>Before setting a new crontask set you may want to backup the previous set of cron tasks :</p>
<pre class="brush: cpp;">
$crontab -l &gt; oldcrontasks.txt
</pre>
<p>List current cron jobs :</p>
<pre class="brush: cpp;">
$crontab -l
</pre>
<p>Remove all cron jobs :</p>
<pre class="brush: cpp;">
crontab -r
</pre>
<p>So using crontab any php script or any other script or command can be executed automatically on server side.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=41&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/run-php-scripts-automatically-at-intervals-use-cron-jobs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>File &#8211; Image Previews in Konqueror KDE</title>
		<link>http://www.binarytides.com/blog/file-image-previews-in-konqueror-kde/</link>
		<comments>http://www.binarytides.com/blog/file-image-previews-in-konqueror-kde/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 11:30:00 +0000</pubDate>
		<dc:creator></dc:creator>
				<category><![CDATA[KDE]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.binarytides.com/blog/?p=40</guid>
		<description><![CDATA[If Konqueror is not showing the image thumbnails in the icons or previews then check :
1. Control Center > KDE Components > File Manager > Previews &#38; Meta-Data for the Maximum File Size in the slider. If it is too low then increase it to say 5 MB.

2. Open Konqueror. In the menu View > [...]]]></description>
			<content:encoded><![CDATA[<p>If Konqueror is not showing the image thumbnails in the icons or previews then check :</p>
<p>1. Control Center > KDE Components > File Manager > Previews &amp; Meta-Data for the Maximum File Size in the slider. If it is too low then increase it to say 5 MB.</p>
<p><span id="more-40"></span></p>
<p>2. Open Konqueror. In the menu View > Preview check whether previews are enabled or not. If disabled then enable them. Various file types can be selectively enabled or disabled for preview.</p>
<img src="http://www.binarytides.com/blog/?ak_action=api_record_view&id=40&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.binarytides.com/blog/file-image-previews-in-konqueror-kde/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
