Wednesday, October 28, 2015

gdb unable to find shared symbols

This primarily happens when you trace your gdb to an unknown terrain - i.e. you enter part of the shared library's code whose symbols have not been loaded by gdb yet.

I encountered this problem while building a device mapper library. Even though I spent a couple of hours going through the Makefile, ensuring that I was configuring the library using the --enable-debug option, when I ran the library with gdb and traced to the part of the code located in the library using 'n' and 's' commands (Please read what they are meant for if you don't have an idea about them), I kept falling into the same pit - no debug symbols found.

I then came across this blog

Which basically stated that all shared libraries loaded by gdb for a particular run can be viewed using the following command:


(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd9aa0  0x00007ffff7df5590  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7b78330  0x00007ffff7bc320f  Yes      * /lib/libdevmapper.so.1.02
0x00007ffff77c34f0  0x00007ffff7916354  Yes         /lib/x86_64-linux-gnu/libc.so.6
0x00007ffff759e190  0x00007ffff75a1167  Yes         /lib/x86_64-linux-gnu/librt.so.1
0x00007ffff7383a90  0x00007ffff7390c41  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007ffff707b5a0  0x00007ffff70ecc61  Yes         /lib/x86_64-linux-gnu/libm.so.6
(* No debug symbols found)

This made me realise that /lib/libdevmapper.so.1.02 is the library for the default devicemapper package and that my own library with all debug symbols was not being read by gdb at all!

To correct this, I simply installed my library to override the existing /lib/libdevmapper.so.1.02 library. Rerunning gdb now gives me access to all symbols in my libdevmapper.so.1.02 library!

(gdb) info sharedlibrary
From                To                  Syms Read   Shared Object Library
0x00007ffff7dd9aa0  0x00007ffff7df5590  Yes         /lib64/ld-linux-x86-64.so.2
0x00007ffff7b78330  0x00007ffff7bc320f  Yes         /lib/libdevmapper.so.1.02
0x00007ffff77c34f0  0x00007ffff7916354  Yes         /lib/x86_64-linux-gnu/libc.so.6
0x00007ffff759e190  0x00007ffff75a1167  Yes         /lib/x86_64-linux-gnu/librt.so.1
0x00007ffff7383a90  0x00007ffff7390c41  Yes         /lib/x86_64-linux-gnu/libpthread.so.0
0x00007ffff707b5a0  0x00007ffff70ecc61  Yes         /lib/x86_64-linux-gnu/libm.so.6

Go nuts with gdb!




Tuesday, December 9, 2014

Gesture Recognition for your Computer /*from scratch*/

Step 1.

What you need:

Virtual Box
Virtual Box Extension Pack
https://www.virtualbox.org/wiki/Downloads
Ubuntu VM (tried it on 12.04)

Need to install Extension Pack. Then goto devices -> USB -> enable Camera/unknown device

Note: I am trying this using integrated camera in Lenovo T420. Please check if camera is easily detectable from Windows Host. If not, then fix that first.

Once the camera has been attached to the Ubuntu VM inside Virtual Box, check the camera settings using cheese.

Step 2.

What you need.

install libgtk2.0-dev and pkg-config.
Open CV source code. Install directly from the source webpage:
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html


Step 3.

All the Hand Gesture code in the world that you will need to get it going :D

http://www.intorobotics.com/9-opencv-tutorials-hand-gesture-detection-recognition/

Wednesday, August 14, 2013

Creating an ISO Image from CD/DVD in Ubuntu using terminal

First of all, know where your CD Drive is mounted. You can run the following command to do the same:

shehbaz@Augustus:~$ mount | grep sr
 
/dev/sr0 on /media/UDF Volume type udf (ro,nosuid,nodev,uid=1000,gid=1000,iocharset=utf8,
umask=0077,dmode=0500,uhelper=udisks)

The CD / DVD is mounted in /dev filesystem in linux. running the mount command itself could help you to figure out the location where CD / DVD is mounted.

Next, you could do the following

cat /dev/sr0 > dumb.iso

which, as the name suggests, is a dumb way of creating the iso file.

why you ask? because, there is no error checking while reading from the Disk (/dev/iso) and writing to our iso image file. Here, I introduce before you the command

readom

Which stands for read - optical - media : your disk.

This command is available in the package wodim and can be installed using

sudo apt-get install wodim

readom not only creates a new, error-free iso image, but also retries reading from the cd drive in case the drive is busy / error occoured in copying a specific block/sector.

readom dev=/dev/sr0  f=smart.iso

Note : If you get the following error:

shehbaz@Augustus:~$ readom dev=/dev/sr0 f=smart.iso
Error trying to open /dev/sr0 exclusively (Device or resource busy)... retrying in 1 second.
just eject the CD Drive, and reinsert it, and close any auto msg boxes that pop up.

readom will ensure that the final CD/DVD iso image that is created is authentic, which would help you save lot of time playing around with erroneous iso image files.

Wednesday, August 7, 2013

How to Kill the Init Process (And recover from It)

What happens when we kill the init process?

Question 1 : Why the hell would you kill an init process?
Answer 1: To know what happens if someone,anyone tries to kill the init process
Answer 2: Inquisitiveness (My case!)

To see for yourself, please try the following:

1. Open a terminal
2. Type kill -9 [pid of init process]

The pid (or process id) of the init process can easily be obtained using the

top

command, or the following command

ps -afx | grep init

I think it is 1 for all the processes, but try the above two commands just to be sure.

Now, after killing the init process, reboot your system.

Rebooting will cause a kernel panic!

Cause :

Kernel panics because it tries to initialize the init process after initializing the kernel processes. However, it is unable to do so (because during previous shutdown, init process did not comprehensively free all user applications, which would lead to clearing all kernel data structures)

Note that some of these data structures would be maintained in the swap space (in the disk), also, the super block (in your bootable device i.e. disk) may get corrupted due to improper shutdown in the previous boot.  

Solution to rectify this problem :



In my case, using a live USB, I performed a memory check and a disk check. Ubuntu Live USB showed me two files in the superblock in the bootable device [HDD /dev/sda8] had been corrupted. In order to rectify these files, I did the following

sudo fsck /dev/sda8

A simple filesystem check was sufficient to recover my bootable device, without any data loss.

To check my file systems normal operation, I mounted the filesystem (/dev/sda8) using the Live USB itself. And it worked like a charm.

Rebooted the system, removed the USB, and my HDD was able to successfully boot my laptop. :)


Wednesday, July 17, 2013

Kerberos, LDAP and NFS

Recently I took a project to setup a SSO (Single Sign On) System for a small lab. We had a set of 25 computers, each with the following configuration:
  • i3 processors (two cores)
  • 500 GB HDD
  • 4GB RAM
We had to install Fedora 19 in each of these machines, along with some standard softwares.

The Incremental Model:

1st architecture:

1 Server, the master server, who shall be thus referred to as cnl.cnl.net. (cnl stands for computer networks lab, for the more inquisitive readers). cnl.net is the realm/ring that we label all the computers in the lab with.

Day 1:

Setting up Server, DHCP Hostname.
  1. We setup a single server, a Debian OS. (We do that because of an innate bias towards Debian OS, also due to over familiarity with using Ubuntu. :P)
  2. We configure the servers dhcp client name (Note that all the machines in the lab are dhcp clients, including our Kerberos server, LDAP Server). for this we need to make changes in /etc/hosts file.
  3. We decide to name the realm cnl.net . (A better extension would have been cnl.lab, but that is something we are going to ignore).
  4. Hence the name assigned to the server ends with cnl.net. The hostname is now cnl.cnl.net. (This can be checked using the command hostname -f )

Setting up the Kerberos Server.
                                                                               
I followed this to setup the Kerberos Server. Its pretty much self explanatory. Few changes :

  1. During installation of krb5-admin-server ,  there are a few default realm names, passwords, and principal users that are asked for. They are also self explanatory, just keep in mind to end the hostname with cnl.net.
  2. My /etc/krb5.conf file looks like this: 

 [realms]
CNL.NET = {
kdc = cnl.cnl.net:88
admin_server = cnl.cnl.net:749
default_domain = cnl.net
}

[domain_realm]
.cnl.net = CNL.NET

[libdefaults]
default_realm = CNL.NET
dns_lookup_realm = false
dns_lookup_kdc = false

[kdc]
profile = /etc/krb5kdc/kdc.conf

[logging]
default = FILE:/var/log/kerberos/krb5libs.log
kdc = FILE:/var/log/kerberos/krb5kdc.log
admin_server = FILE:/var/log/kerberos/kadmind.log



Kerberos Architecture defines AS and TGS as two separate entities. In our setup, they are the same host : cnl.cnl.net.

Troubleshooting and Testing The server:

principal :  any identity that asks for a ticket is called a principal [READ THIS]. For our usage, we setup the following principals.

  1. harshal/admin@cnl.net
  2. shehbaz@cnl.net.
format of a principal:

primary/instance@REALM

Note that for shehbaz, the default non-admin instance is taken.

some useful krb server commands:

server# kadmin -p krbadmin/admin
kadmin: listprincs
kadmin: addprinc root/admin
kadmin: addprinc shehbaz
Kerberos testing

Create ticket
server# kinit shehbaz Password for shehbaz@CNL.NET:
Verify ticket

server# klist
# klist Ticket cache: FILE:/tmp/krb5cc_0 Default principal: shehbaz@CNL.NET
Valid starting Expires Service principal 09/01/11 00:56:58 09/01/11 10:56:58 krbtgt/CNL.NET@CNL.NET renew until 09/02/11 00:56:53

Day 2

1. Options to install Fedora on the Client Machine are here.
2. copy the /etc/krb.conf file from the server to the client machine.


Installing Kerberos clients for Debian and Fedora


Setting up LDAP

Running into a lot of issues right now. Messed up slapd configuration files. restoration took a lot of effort.
[TODO] Read up on ldap before trying to configure it.

Day 3 

Continuing with LDAP. Reading this and this to configure LDAP.

LDAP terminologies given here                         
                                                  

Day 4

Sweet Success!! :D

After a lot of reading, understood a bit of LDAP structure. Refer this this and this for a more detailed understanding.

Heres are some interesting things that one should know:
  1. LDAP is basically a database in the form of a tree, just like a phonebook or yellow-pages.
  2. It is a database structure optimized for reads rather than writes, so you basically make lots of searches and less number of additions/deletions/modifications. 
  3. Three things: schema , objectclass , attributes :
    schema is the template on which the entries (actual physical elements of the database are configured). these are located in /etc/ldap/schema folder. these are of three types : structural, abstract, and auxillary.
    objectclass is a label on the schema. first node in the tree is top. other objectclasses inherit top and have other child objectclasses.
    attributes are properties of the objectclass, some are mandatory, while others are optional.                        
  4. Main operations performed on an ldap database ldapadd, ldapsearch, ldapmodify.
NOTE :
  1. There are a lot of objectclasses already available (defined in ldap), like person, organization etc.
  2. slapd.conf is outdated, now they use OLC (Online control) (cn=config) file for ldap support. Though support for slapd.conf is still supported.
ldapadd

ldapadd -H ldap://cnl.cnl.net -x -D "cn=admin,dc=cnl,dc=net" -f demo.ldif -w <password>

My sample demo.ldif file:

dn: ou=admin,dc=cnl,dc=net
objectclass:top
objectclass: organizationalUnit
ou: admin

dn: ou=student,dc=cnl,dc=net
objectclass: top
objectclass: organizationalUnit
ou: student

dn: cn=harshal,ou=admin,dc=cnl,dc=net
objectclass: top
objectclass: person
objectclass: organizationalPerson
sn: Muknak
cn: Harshal Muknak
ou: admin

dn: cn=shehbaz,ou=student,dc=cnl,dc=net
objectclass: top
objectclass: person
objectclass: organizationalPerson
sn: Jaffer
cn: Shehbaz Jaffer
ou: student


NOTE that I did not have to add any schema definitions for creating the ldap directory structure (i.e. adding objectclass). I have used inbuilt schemas like person and organizationalUnit.

For LDAP Clients, on Fedora use this.

 

Day 6

Setting up NFSv4.

/etc/exports file:

/media/student        *(rw,nohide,no_root_squash,no_subtree_check,sync,fsid=0)

mount command:

sudo mount -v -t nfs4 192.168.10.150:/ /home/student

alternatively, for mounting on boot, add this to the end of /etc/fstab of the client:

192.168.10.150:/ /home/students nfs4 defaults       0 0

Note that the ip mentioned is the server IP. We mounted the whole '/' directory, however, only /media/student (the mountable directory on the server) gets mounted.

Follow the above statements as-is, or you will get lots of issues (No route to host etc).








Tuesday, July 16, 2013

Installing Fedora 19 using LiveUSB

I am trying to install Fedora 19 on one of the hosts. There are a lot of issues that I ran into, which I have documented here.

1. Creating A Live USB using Unetbootin

I am using a Debian Wheezy to create a Fedora 19 bootable USB. Unetbootin for Debian Wheezy has support for building only Fedora 16 x86_64 OS, but we are proceeding with choosing Fedora 16 x86_64 option and installing a Fedora 19 disk Image.

Errors:

After creating the Live USB, on boot the computer gives the following message:

No DEFAULT or UI configuration directive found!
boot:

To correct this, I formatted the pendrive using gparted   and created a FAT32 filesystem.

Install packages:

sudo apt-get install gparted dosfstools

Run gparted

sudo gparted

select the USB from devices menu (/dev/sdb in my case). and create a FAT32 filesystem for my USB.

Run unetbootin

sudo unetbootin

Select the appropriate Fedora 19 x86_64 iso image and install it on USB Image.

Live USB is ready.


The Fedora Setup

After choosing the Run Default option from UnetBootin Screen, I divided the fedora partitions into 3 parts:
Label Type Mount Point Size
LinuxLocalFolder ext4 / 380 GB
WindowsLocalFolder ext4 /var 40GB
root /home ext4 20GB
Swap Space swap swap 20GB

LVM (Logical Volume Mount)

Something new, unlike previous Primary Partitions (4 in number ) and countless Logical Partitions, Fedora 19 gives us LVM, where we can just assign each partition the label LVM, and Fedora itself configures what to take as a primary partition and what to take as a logical partition.

Thursday, May 30, 2013

Tweaking tcp port - Improving performance of network intensive applications over high latency network

Building an application over a low latency network could give you very good performance, but sometimes over a high latency network, read() or write() system calls could be a cause of bottleneck for the applications performance.

Consider a network intensive application running on server A. This server continuously generates log and sends it over the network to another server B . Now, server B may be slow (low computation power) or the network may have high error/ latency, due to which the write buffer of A gets saturated. As a result server A stalls (write buffer of A is filled, but B is not ready to read the data yet).

By default in the linux kernel, each tcp port is configured with around 64-80KB read/write buffer.

This can be seen using the command :

$sudo su
#sysctl -a | grep net | grep mem

...
net.ipv4.tcp_mem = 93132        124179  186264
net.ipv4.tcp_wmem = 4096        16384   3973728
net.ipv4.tcp_rmem = 4096        87380   3973728
...

The numbers represent the minumum, default and maximum memory allocated to every tcp port  that is created on a machine.

For solving our current problem, all we need to do is increase the default port size to a larger value. Increasing the memory associated with a port can be done as follows:

#sysctl -w net.ipv4.tcp_rmem='4096        3000000   3973728'
#sysctl -w net.ipv4.tcp_rmem='4096        3000000   3973728'

NOTE: This change gets reflected on every port that is created on the server. Hence, one should be careful not to increase the default port size to a very large value, as each new connection would result in higher memory usage.





 

Thursday, May 2, 2013

Templates in C [Macros!]

Today I faced this problem of writing a generalized function in C that would accept a "configurable" type of argument. i.e. the function should be able to accept any kind of argument that I pass to it, and it should be able to do something with it (say print the value of the argument passed).

What I wanted could easily be done in C++ using TEMPLATES; create a function with a signature

void foo(class Template <T> x){
     cout << "x" << "\n";
     return ;
}

This cannot be done in C, as it is a middle level language (yes I said it! if you do not agree, go learn C++ STL :P ).

Now, there is NO (absolutely NO) way you can do function/operator overloading in C, hence we resort to finding workarounds... say what? macros biaatch!


MACROS - a coders nemesis -

Why:
1. Its difficult to write  a macro.
2. Its even more difficult to read a program with macros, you practically end up expanding the whole macros in your notebook / as comments in your code.
3. CSCOPE /CTAGS dont work on MACROS. you end up using grep instead to find out the exact place where the macro gets expanded.


Then Why do we still use it:
1. Makes ur code compact.
2. 1st reason is enough.

Without further ado, i present to you using macros to compactify (i just made that word up) your code.

consider the program :

int main(){
     callPrint_int(1);
     callPrint_float(4.2);
     callPrint_char('b');
     return 0;


1. Program without a macro:

callPrint_int(int x){
     cout << x;
}


callPrint_float(float x){
     cout << x;


callPrint_char(char x){
    cout << x;
}

2. Program with a macro: 

#define callPRINT(T) \
    void callPRINT_##T(T x) { cout << x ; }

callPRINT(int);
callPRINT(float);  
callPRINT(char);
  
each of the above three lines give you basically functions in part 1. but look at how compact your code becomes. isn't she a beauty :P.










  


Saturday, January 5, 2013

Ubuntu Cropping Videos using VLC [Notes]

go to command prompt.

Start vlc.

Check the box  View -> Advanced Controls.

A new pannel appears below the vlc video.

Click on the red dot. Record starts.

Click on the Red dot again. Record stops.

Where is the video saved?

dont know. But you can specify the path using the command line option

vlc --input-record-path=/home/shehbaz/videos/ sample_video.mp4


Friday, December 7, 2012

Shell scripting - sleep for milliseconds

Ever tried to make your shell script sleep for milliseconds? I tried, and failed miserably in doing so. I didnt know that decimal numbers are not allowed after the sleep command.

I found the following command that could be used for "virtually simulating" the millisecond sleep command:

typeset -i count=0;
while [[ ${count} -le 5700 ]];
do
      count=${count}+1
done

decrease the value 5700 to a value which would suit your needs. 5700 gives you ~1 sec time.


Tuesday, November 20, 2012

Setting up LAMP on Ubuntu 12.04

LAMP - Linux Apache MySQL PhP.

Most of the stuff mentioned here is inspired from :: https://help.ubuntu.com/community/ApacheMySQLPHP

first to install apache use the following:

1> sudo apt-get install apache2

restart/start apache2 services using the following command:

2>  sudo /etc/init.d/apache2 restart

This will restart apache services.

Check whether the apache2 services have started again by visiting http://localhost. You should get the message "It works!" on your browser. If it actually works, move to point 3. else:

reasons:

a. check /var/log/apache2/error.log.** where ** is the most recent(largest) value. you will get some kind of error message. Though it is self explanatory (eg. could not access some file) which means that there is a mode problem (you have to make /var/www/index.html 744).

b. error log is empty - problem with browser caching - try removing recent content (if you have tried logging into localhost many times, browser caches your page). To remove this clear your browser cache.

3> "It works!" page is located at /var/www/index.html. This is the default root hosting directory for linux. for multiple sites or your own website, you do not want to clutter your /var/www directory. Therefore it is suggested you change your default browsing directory.

How do I do that you say?

for every website , apache creates a config file in the directory
/etc/apache2/sites-available/

with the name of the website. Opening the configuration file, you will notice a xml file like this:



Saturday, September 8, 2012

Ubuntu 12.04LTS Bug - Close, minimize and Maximize button becomes invisible in GNOME

Recently, I faced this issue of application window not showing the top most bar - containing close, minimize and maximize button.

I was using Ubuntu 12.04 LTS with GNOME Desktop Theme. As usual the problem was with ccsm (CompizConfig Setup Manager).

All I had to do was to go to Application -> Settings ->Compizconfig Setup manager (just type ccsm on the shell.)

once that is done, unmark (if already marked) and then mark again the Effects -> Window manager tab.



Try opening a shell. I hope this time you see the close minimize and maximize buttons.

==Don==

Wednesday, September 5, 2012

DPRINTF Debug Macro in C

Extremely useful for Debugging projects in C.


#define DEBUG   // comment if you do not want the debug statments to appear.

#ifdef DEBUG
#define DPRINTF(fmt, ...) \
    do { printf("my_file: " fmt, ## __VA_ARGS__); } while (0)
#else
#define DPRINTF(fmt, ...) \
    do { } while (0)
#endif




Usage -> DPRINTF("This is a debug statement");

if you want the debug statements to appear, then define DEBUG
#define DPRINTF
at start of the code.

if, on the other hand, you do not wish the debug statements to appear, comment it.

you can add additional information to your debug statement, for example -

DPRINTF("%p:%d Debug statement\n",__func__,__LINE__);

this gives both the function name and the line number of the DPRINTF statement along with the message "Debug statement".



Sunday, September 2, 2012

Get real clock time in C to nanosecs approximation

struct timespec start,end;

clock_gettime (CLOCK_REALTIME, &start);
<add code here>
clock_gettime (CLOCK_REALTIME, &end);
float time= (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000;

This code snippet would give you the time taken to execute the added code in real time.

Dont forget to compile your code with a -lrt flag. Not including this flag could  give you a ld error for not finding clock_gettime function.

Thursday, August 9, 2012

How to Start a stopped process in Linux

While running a process in Linux, Sometimes we press Ctrl+Z unintentionally (or by choice). This makes the program STOP.

For example while running a GDB Session, I accidentally pressed Ctrl + Z, which stopped the gdb and the process came out of the gdb session, giving the Stopped message :


I wanted to continue (not restart) the session, for restarting, i couldve killed the process checking the pid and killing the process by its pid, but that would require me to start debugging my program all over again, which is a pain.

So, with a little help from google, i discovered that when we stop a process (using Ctrl +Z ), it basically goes into the background, and goes into sleep mode.

This can be seen from bg command

bash$ bg



Now to continue the program from its sleep mode, we need to bring it to the foreground.this can be done using fg command.

bash $fg <JOB_ID>


where JOB_ID is obtained using the command jobs , which matches process name to job#.

bash $jobs


Thats all! fg will bring your stopped command back to life! 


Sunday, July 22, 2012

Core dump file not found

Has it ever occurred to you that you ran a program, it aborted saying 'core dumped' , but then when you go around looking for the core dump file, you cant find it anywhere? 0-o

Well it happened to me today. I tried finding the 'core' file in each of the possible directories - the pwd, the executable directory, all the directories in the $PATH variable.

To my dismay, none of them had the core file in them.

After some google search, I found that there may be cases where the core file is not created to save space. (Core files are usually large ~1GB ).

I also found out that in my system (Ubuntu 12.04 LTS), the default size allocated to core files is 0.

This can be found using the command

ulimit -a


 If you see ulimit -c 0 , that means 0 blocks have been allocated to core dump file , and hence core dump file is not formed.

To enable the core dump, we can do the following :


ulimit -c unlimited

This increases the coredump size to unlimited. Now, try executing the code that caused Aborted (Core dump formed).

and check the pwd (present working directory) for 'core'  file. You will notice that core file is very large. And hence I feel that in Ubuntu, as  a protective measure, the core dump file has been allocated 0 blocks by default.

NExT up -> tips on how to use objdump for debugging through core file. :)

Wednesday, July 18, 2012

binary files diff and patch

I wanted to send this large sized data from a server to a client multiple times.
Though the change in data in every iteration was negligible, it was essential that the copy be made exactly similar on both client and server.

The time taken to transfer this data was huge. We had to decrease this. Hence it was required that only changes made in the file be diff 'ed  and this file be scp'ed over the client.

Also, at the client end, the file had to be patch'ed, so that the client had the exact same copy as the server.

Heres how we go about this:

1> Diff the file

diff old_file new_file > patch_file   

// old_file was created in previous iteration and new_file created in current iteration.

2> copy the patch file to the client

scp patch_file client@client_IP:patch_file



3> AT CLIENT END :: patch the file in the client

patch old_file patch_file > new_file

for more information please see man patch and man diff.

In order to do this for binary files, you need to install bsdiff.

for Ubuntu use

sudo apt-get install bsdiff


then do ::

bsdiff old_file new_file patch_file
scp patch_file client@clientip:
AT CLIENT END:
bspatch old_file patch_file > new_file.

NOTE :: Check whether the checksum of the newly created file is same as that of the previous file.
This can be done using cksum command.

If they are not the same, you can use jdiff (source code given here :: http://jojodiff.sourceforge.net/)

Also, note that jdiff and jpatch, the two binaries that can be used from the source code are compiled on 32 bit kernel. (use file command for checking the binary type)

For kernel version 3 and above, this will work perfectly fine. However if you plan to use jdiff and jpatch for machines with kernel level 2.6 or so, you will need to recompile it for 64 bit machine.

This regenerates jdiff and jpatch with 1-2 trivial error resolutions.

bsdiff  OR  jdiff, which one is better?

bsdiff takes more time but uses internal compression algorithm for creating small sized patch. It goes without saying the time taken to generate the patch is more.

jdiff on the other hand takes less time, generates larger patch, but gives you the gurantee that the final file after patch is exact replica of the original binary file (verified using cksum ). Also, it is meant for 32 bit OS. 

Wednesday, June 27, 2012

Analyse network traffic using tcpdump and tcpstat

The other day I was doing a set of system programming experiments which required me to generate graphs of network traffic per second between two hosts.

Though I knew wireshark was one reliable automated tool with a pretty GUI, I was in search of some better tool that could give me exact stats, rather exact distribution of the packets recieved per second by one host from the other host.

Searching over the net I tumbled upon '''tcpdump''', which has the capability to "sniff" packets over LAN or any localized network.

At first I tried running it by making it catch hold of all the packets that it could get a hand on. And that included network traffic of Office of the HOD of my college :P , and packets of some three or four other Professors. Though I didn't try and read the contents of the packets, i strongly believe tcpdump can be used to do that in verbose mode using vvv option. But thats something I'll try some other day.  

Well it was fun using it in amorous mode (yes thats the exact term given to listening to all the packets that are circulating in the network), but due to shortage of time and the perennial project advisor's pressure, I had to abstain myself from getting adventurous.

Comming back to tcpdump option - I used the following command to analyze the traffice between two hosts ::

tcpdump -f -n -S host $host1 and host $host2 -w file1.cap

This results in the generation of a binary file that can be read by tcpdump using the following command ::


tcpdump -r file1.cap

So far so good. But there was one problem. My intention was to give a comprehensive time varied traffic rate between two hosts. and tcpdump gave me a bunch of packets with their sizes. So creating a assorted list of packets and bandwidth usage per second would have required me to write a new script.

 This is when tcpstat came to the rescue. Using tcpstat, we can read the binary file (created above by the tcpdump command) and get a time sliced version of the network traffic using the following command

tcpstat -r file1.cap $timeslice

timeslice denotes the time scale on which packets are  analysed. for my purpose I set it to 5.

This blog in no means is comprehensive and I would strongly advise the reader to look at man page for tcpdump and tcpstat.

Notes::

How do we run tcpdump as a non-sudo user?

groupadd tcpdump
addgroup <username> tcpdump
chown root.tcpdump /usr/sbin/tcpdump
chmod 0750 tcpdump
setcap "CAP_NET_RAW+eip" /usr/sbin/tcpdump


==Don Jaffer==

Friday, June 8, 2012

UBUNTU ctrl key doesnt work on Vncviewer

its a gnome problem.

goto :  System -> Configuration tools ->  /desktop/gnome/peripherals/mouse/locate_pointer

unmark the checkbox. done.

Well for a strange reason sometimes this may not work.. So for that you need to install kde in Ubuntu.

This can be done using apt-get. No need to install kubuntu or anything.

Sunday, May 20, 2012

Passwordless ssh into a server

You have a machine to which you have to login all the time. and that includes entering your password to authenticate yourself to the server. Taxing! isint it??

A simple quirk is to make yourself "known" to the server so that it doesnt ask you to authenticate yourself everytime you login to the server...

2 steps , thats all you need baby!

* ssh-keygen
* ssh-copy-id <servername>

Consider Host A and Host B. Host A is your local computer and Host B is your Server.

'''On Host A'''
 ssh-keygen
this will create two keys id_rsa and id_rsa.pub in your local machine.

'''On Host A'''
ssh-copy-id mcs112578@palasi.cse.iitd.ac.in
this will copy the id_rsa.pub file into the authenticate keys. Done!

Now try ssh ing into the Server... see the difference !! (No password required !!)

==Don Jaffer==