<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Coredump</title>
	
	<link>http://www.coredump.gr</link>
	<description>Tips on Security, Programming, and Administration</description>
	<lastBuildDate>Tue, 15 Mar 2011 17:18:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/coredumpgr" /><feedburner:info uri="coredumpgr" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>coredumpgr</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>C Program to Calculate Network and Broadcast IP Addresses</title>
		<link>http://feedproxy.google.com/~r/coredumpgr/~3/_U_KDfW27k8/</link>
		<comments>http://www.coredump.gr/programming/c-program-to-calculate-network-and-broadcast-ip-addresses/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 04:21:56 +0000</pubDate>
		<dc:creator>Haris</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[broadcast]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[IP calculator]]></category>
		<category><![CDATA[netmask]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[subnet]]></category>

		<guid isPermaLink="false">http://www.coredump.gr/?p=95</guid>
		<description><![CDATA[While working on a custom packet injector for Linux, I had to calculate the network and broadcast IP addresses given an IP address and a netmask. After searching on Google I found that the calculations are some very simple bitwise operations. To get the network address perform a bitwise AND on the IP address and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.coredump.gr/wp-content/uploads/2011/02/calc.png" alt="" title="calc" width="75" height="78" class="alignleft size-full wp-image-105" />While working on a custom packet injector for Linux, I had to calculate the network and broadcast IP addresses given an IP address and a netmask. After searching on Google I found that the calculations are some very simple bitwise operations.</p>
<p>To get the network address perform a bitwise AND on the IP address and the netmask:<br />
<code>network = ip &#038; netmask</code></p>
<p>To get the broadcast address perform a bitwise OR on the network address and the complement of the netmask:<br />
<code>broadcast = network | ~netmask</code></p>
<p>Here a simple C program you can use to calculate the network and broadcast addresses on your own:</p>
<pre class="brush: cpp; title: ; notranslate">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;arpa/inet.h&gt;

int main(int argc, char **argv)
{
    struct in_addr ip;
    struct in_addr netmask;
    struct in_addr network;
    struct in_addr broadcast;

    if (argc != 3)
    {
        printf(&quot;usage: %s ip netmask\n&quot;, argv[0]);
        exit(0);
    }   

    inet_aton(argv[1], &amp;ip);
    inet_aton(argv[2], &amp;netmask);

    // bitwise AND of ip and netmask gives the network
    network.s_addr = ip.s_addr &amp; netmask.s_addr;
    printf(&quot;network %s\n&quot;, inet_ntoa(network));

    // bitwise OR of network and complement of netmask gives the broadcast
    broadcast.s_addr = network.s_addr | ~netmask.s_addr;
    printf(&quot;broadcast %s\n&quot;, inet_ntoa(broadcast));

    return 0;
}
</pre>
<p>To compile it use the command:</p>
<pre class="brush: bash; title: ; notranslate">
gcc -Wall ipcalc.c -o ipcalc
</pre>
<p>The usage is really simple:</p>
<pre class="brush: bash; title: ; notranslate">
$ ./ipcalc
usage: ./ipcalc ip netmask
$ ./ipcalc 192.168.1.0 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
</pre>
<p>Feel free to use it and send me comments/suggestions <img src='http://www.coredump.gr/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/coredumpgr/~4/_U_KDfW27k8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.coredump.gr/programming/c-program-to-calculate-network-and-broadcast-ip-addresses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.coredump.gr/programming/c-program-to-calculate-network-and-broadcast-ip-addresses/</feedburner:origLink></item>
		<item>
		<title>How to Compress a VMWare Image File</title>
		<link>http://feedproxy.google.com/~r/coredumpgr/~3/VS_HbortvHA/</link>
		<comments>http://www.coredump.gr/admin/how-to-compress-a-vmware-image-file/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 17:59:54 +0000</pubDate>
		<dc:creator>Haris</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[compress]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.coredump.gr/?p=45</guid>
		<description><![CDATA[Recently I had to create a vmware image with Debian GNU/Linux that had to be as small as possible because people would have to download it. I started installing Debian &#8220;sid&#8221; by using debootstrap according to the following instructions: http://www.debian.org/releases/stable/i386/apds03.html.en#id2550848. When I completed the installation and after I removed all the unnecessery packages I had [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.coredump.gr/wp-content/uploads/2011/02/vmware-zipped.png" alt="" title="vmware-zipped" width="75" height="74" class="alignleft size-full wp-image-81" />Recently I had to create a vmware image with Debian GNU/Linux that had to be as small as possible because people would have to download it. I started installing Debian &#8220;sid&#8221; by using debootstrap according to the following instructions: <a href="http://www.debian.org/releases/stable/i386/apds03.html.en#id2550848" target="_blank">http://www.debian.org/releases/stable/i386/apds03.html.en#id2550848</a>. When I completed the installation and after I removed all the unnecessery packages I had a fully functional system that occupied 400MB of disk space. The problem was that the VMWare image size was 1.2GB although only 1/3 of it was actually being used.</p>
<p>I suppose this happens because VMWare preallocates space to improve the performance of IO operations. If I try to compress the image as it is the compression ratio will be really low. The reason is that the preallocated free space contains random data that is hard to compress. If we could fill this free space with a repeating pattern then we could achieve a much higher compression ratio.</p>
<p>The solution I found online is really simple and works. By running the following command we fill the extra space with zero bytes:</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">cat /dev/zero &gt; zero.fill; sync; sleep 1; sync; rm -f zero.fill</pre>
<p>After running the command I used gzip to compress the image to 178MB from 1.2GB!</p>
<img src="http://feeds.feedburner.com/~r/coredumpgr/~4/VS_HbortvHA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.coredump.gr/admin/how-to-compress-a-vmware-image-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.coredump.gr/admin/how-to-compress-a-vmware-image-file/</feedburner:origLink></item>
		<item>
		<title>Debian Package List Backup and Restore</title>
		<link>http://feedproxy.google.com/~r/coredumpgr/~3/xcbgKUU8GG0/</link>
		<comments>http://www.coredump.gr/linux/debian-package-list-backup-and-restore/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 17:44:09 +0000</pubDate>
		<dc:creator>Haris</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[packages]]></category>

		<guid isPermaLink="false">http://www.coredump.gr/?p=36</guid>
		<description><![CDATA[Update: Debian Lenny 5.0 now has support for the option autoremove of apt-get that is able to clean all unused dependencies Curiosity and laziness are the two most important reasons that my system ends up with lots of useless software after a couple months of usage. Many times I want to test drive a program [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Update: Debian Lenny 5.0 now has support for the option autoremove of apt-get that is able to clean all unused dependencies</p></blockquote>
<p><img src="http://www.coredump.gr/wp-content/uploads/2011/02/debian-backup.png" alt="" title="debian-backup" width="75" height="71" class="alignleft size-full wp-image-83" />Curiosity and laziness are the two most important reasons that my system ends up with lots of useless software after a couple months of usage. Many times I want to test drive a program and if it suits my needs I&#8217;ll keep it otherwise it will end up in /dev/null.</p>
<p>With apt-get magic it is amazingly easy to install lots of programs in seconds. The problem comes when you want to get rid of them because each program comes with a list of dependencies that get installed automatically for you. So you have to keep a list of the dependencies to be able to uninstall them when you don&#8217;t need the program anymore. I used to copy the dependencies from the apt-get confirmation screen to a text file so that I can remove them later. That didn&#8217;t work for me, thus I had to find a way to do it automatically.</p>
<p>I created two scripts that use Debian tools to create a checkpoint before I install a new program and then rollback to that state when I don&#8217;t need that program anymore. The first script is named <strong>dpkg-backup</strong> because it creates a backup copy of the installed packages list. Here it is:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh
# dpkg-backup.sh

dpkg --get-selections &gt; /tmp/dpkg-list.txt
</pre>
<p>The second script is named <strong>dpkg-restore</strong> because it restores the packages to the saved state. Source code:</p>
<pre class="brush: bash; title: ; notranslate">
#!/bin/sh
# dpkg-restore.sh

if [ -f /tmp/dpkg-list.txt ]
then
    /usr/bin/dpkg --clear-selections
    /usr/bin/dpkg --set-selections &lt; /tmp/dpkg-list.txt
    /usr/bin/dpkg --get-selections | sed -e \'s/deinstall/purge/\' &gt; /tmp/dpkg-list.txt
    /usr/bin/dpkg --set-selections &lt; /tmp/dpkg-list.txt
    rm /tmp/dpkg-list.txt
    /usr/bin/apt-get dselect-upgrade
else
    echo &quot;You must use dpkg-backup first.&quot;
fi
</pre>
<p><strong>Usage</strong> is pretty simple. All you have to do is run dpkg-backup.sh before you install a program with apt-get. Then use apt-get to install it and when you want to get rid of it use dpkg-restore.sh and everything associated with that program is gone for good <img src='http://www.coredump.gr/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . An example usage scenario is provided below:</p>
<pre class="brush: bash; title: ; notranslate">
$ dpkg-backup.sh
$ apt-get install test-program
...
# After playing around with the program you realize that you don't need it anymore!
$ dpkg-restore.sh
</pre>
<p>That&#8217;s it! I hope you find these two scripts as useful as I did. By the way both are licensed as GPLv2 so feel free to modify and distribute. If you find any bugs or have any ideas/comments on how to improve them let me know!</p>
<img src="http://feeds.feedburner.com/~r/coredumpgr/~4/xcbgKUU8GG0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.coredump.gr/linux/debian-package-list-backup-and-restore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.coredump.gr/linux/debian-package-list-backup-and-restore/</feedburner:origLink></item>
		<item>
		<title>Debian Minimal Installation for Desktop use</title>
		<link>http://feedproxy.google.com/~r/coredumpgr/~3/x9F92YZuyuc/</link>
		<comments>http://www.coredump.gr/linux/debian-minimal-installation-for-desktop-use/#comments</comments>
		<pubDate>Sat, 05 Feb 2011 17:31:15 +0000</pubDate>
		<dc:creator>Haris</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[minimal]]></category>

		<guid isPermaLink="false">http://www.coredump.gr/?p=23</guid>
		<description><![CDATA[Note: This post was written back when I used to have a Debian GNU/Linux machine as my desktop computer. The Debian version at that time was etch 4.0. Nowadays I have a new shiny MacBook Pro with Mac OS X Leopard that I use as my main work machine so some of the information in [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This post was written back when I used to have a Debian GNU/Linux machine as my desktop computer. The Debian version at that time was etch 4.0. Nowadays I have a new shiny MacBook Pro with Mac OS X Leopard that I use as my main work machine so some of the information in this page might be out-of-date or inaccurate.</p></blockquote>
<p><img src="http://www.coredump.gr/wp-content/uploads/2011/02/debian-logo.png" alt="" title="debian-logo" width="75" height="92" class="alignleft size-full wp-image-85" />Whenever I format my computer (and trust me that happens really often) I want only the programs I use to be installed and nothing else. I don&#8217;t like having my machine overloaded with crappy software that I never use (that&#8217;s the case with Microsoft Windows). So every time I have to remember which programs I want and install them one by one with apt-get. For that reason I decided to create a list with all the programs I need. In that way I can just copy &#8211; paste the list every time I format.</p>
<p>The following commands will create a very minimal desktop with only the packages I need installed. If you think those packages meet your needs then you might find these commands useful. I have tested them only with Debian GNU/Linux 4.0, they will probably work with other Debian based distributions like Ubuntu.</p>
<p>First, we install X.Org:</p>
<pre class="brush: bash; title: ; notranslate">apt-get install xserver-xorg-video-vesa xserver-xorg-input-kbd xserver-xorg-input-mouse
xserver-xorg-input-synaptics xserver-xorg-input-evdev xorg</pre>
<p>Then we remove two packages that are installed by the previous command and are unnecessary:</p>
<pre class="brush: bash; title: ; notranslate">
dpkg -P xserver-xorg-input-all xserver-xorg-input-wacom</pre>
<p>Finally, we install the rest of the packages including the desktop environment (Gnome):</p>
<pre class="brush: bash; title: ; notranslate">apt-get install gnome-core file-roller gcalctool gconf-editor gdm
xpdf-reader gnome-media gnome-system-monitor gnome-themes
gnome-volume-manager gtk2-engines libgnomevfs2-extra
xscreensaver gnome-power-manager gnome-utils msttcorefonts
alacarte alsa-utils less openssh-client mtr-tiny nmap pidgin
iceweasel</pre>
<p>That&#8217;s all folks, enjoy your newly formatted, minimal system! <img src='http://www.coredump.gr/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/coredumpgr/~4/x9F92YZuyuc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.coredump.gr/linux/debian-minimal-installation-for-desktop-use/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.coredump.gr/linux/debian-minimal-installation-for-desktop-use/</feedburner:origLink></item>
	</channel>
</rss>

