Posts

Showing posts from January, 2014

Examples of Ping Command

Ping command is used to check the network status between two nodes. Developed by : Mike Muss Abbreviation : Packet INternet Grouper How it Works : Ping works by sending an ICMP Echo Request(Type 8) packet to the other node specifying that Iam Alive and asking about his status,if the other node receives the packet he will reply with an ICMP Echo Reply(Type 0) packet telling the node he is also Alive. With this ICMP messages Ping gives us the time that takes to reach and get back the reply from a node(round trip time). Syntax : ping <ip_address> Example : ping 192.168.1.5 We will see different examples in which we can use ping 1.Setting the Interval:              By default ping sends an Echo Request for every one second. If you want to change the interval you can do it by specifying with 'i' option. If you want to have anything beyond 200 ms you have to be in root permissions       Suppose if we want to send an ICMP Echo Request every 500 ms then we h

Lifecycle from .c to .out in Linux

Suppose we have written a C-Program as the following #include<stdio.h> #define pi 3.14 int main() {         printf("\n the value of pi is %d",pi);         return 0; } Stage 1: Pre-Processing:           In this stage all the things which start with a #(macros,includes) gets expanded.All the comments will also be removed in this stage(//, /* */) In our example the contents of stdio.h will be included in our file and pi will be replaced with 3.14 O/P of Pre-processing stage is still a C file Linux Command: gcc -E file.c Step 2: Compiling         In this stage c code will be  converted into assembly code.First the syntax checking will be done if the syntax is ok then each C instruction will be converted into its assembly instruction. The code will now have instructions such as push,movx etc O/P of compiling stage is Assembly Code Linux Command : gcc -S file.c Step3: Assembly:   The assembly code is given as input to the assembler and he ge

pcap_findalldevs example

The program lists out all the interfaces present on the system which can be processed by using pcap library #include<stdio.h> #include<pcap.h> int main(int argc,char *argv[]) {     char error[PCAP_ERRBUF_SIZE];     pcap_if_t *interfaces,*temp;     int i=0;     if(pcap_findalldevs(&interfaces,error)==-1)     {         printf("\nerror in pcap findall devs");         return -1;        }     printf("\n the interfaces present on the system are:");     for(temp=interfaces;temp;temp=temp->next)     {         printf("\n%d  :  %s",i++,temp->name);             }         return 0; }

pcap_lookupdev example

#include<stdio.h> #include<pcap.h> #define ERROR_BUFFER_SIZE 20 int main(int argc,char *argv[]) { /* First thing we have to do here is know the  network interface which we have to listen. If we already know the interface which Ww have to listen then we can directly specify it or we can ask libpcap give us the interface with the function char* pcap_lookupdev(char *errbuf).This function returns the pointer to the string specifying the interface which is suitable for packet capturing */ char *interface,error[PCAP_ERRBUF_SIZE]; interface=pcap_lookupdev(error); if(interface == NULL){ printf("no interface exist on which we can listen"); return -1; } printf("\n the interface on which we can listen is %s",interface); return 0; } My Previous posts has how to install pcap library if you have not installed yet Use the following command to generate the binary gcc -o test test.c -lpcap and run it by using roo

How to install libpcap library into ubuntu12.04

Steps for installing libpcap library Step1: Download libpcap.tar.gz from www.tcpdump.org and decompress it by using tar -xzvf Step2: Download the latest version of flex.tar.gz from  http://flex.sourceforge.net/  and decompress it by using the same command Step3: Download the latest version of bison.tar.gz from  ftp://ftp.gnu.org/gnu/bison/  and decompress it Step4: Download the lateest version of m4.gz  from  ftp://ftp.gnu.org/gnu/m4/  and decompress it Step5 : Go inside each directory and run the following commands              sudo ./configure             sudo make             sudo make install Step6:  Follow the order in this m4->flex->bison->libpcap Your libpcap libraries will be installed in the /usr/local/lib folder you can check it with by typing ls-l /usr/local/lib | grep "libpcap" copy all into the /usr/lib/pcap and now you can start programming ...

How to extract tar.gz and tar.bz2 files in Ubuntu 12.04

Now we are going to see how to extract the most common tar files : tar.gz and tar.bz2. gz: GNU zip bz2: bunzip2 In order to extract the files with the following extensions we will use the command "tar" For extracting gz files: tar -xzvf filename.gz For extracting bz2 files tar -xjvf filename.bz2 For more details you can do man tar in your command line

Open the Terminal Option in the Right Click Ubuntu

We can open  the terminal by a right click and selecting Open in Terminal if we install the following package step1: Open the terminal(ctrl+alt+t) Step2: sudo apt-get install nautilus-open-terminal Step3 : nautilius -q Now u can open the terminal anywhere  by just right click