Wednesday, September 14, 2011

Packet flow in Network

DATA FLOW
A typical data flow which we deal with on daily bases in our homes and offices is like this:
Host A -> Switch -> Router R -> Switch -> Host B
  1. The 1.x host A wants to send to 2.x host B.
  2. Host A realises B is on a different network judging from the subnet mask and ip addresses and knows it need help from a router.
  3. Host A does an ARP operation to find out the MAC address of its default gateway, which is a router R.
  4. Host A sends to router R with source MAC = A‘s MAC and destination MAC = R‘s MAC. The switches in between them pass the frames intact.
  5. Router R sends to host B through the switch in between, rewriting the source MAC to R‘s MAC and the destination MAC to B‘s MAC (before this it should have an ARP entry of host B; otherwise it would do an ARP operation to find out B‘s MAC).

packet creation layer  from url type to page opening ? how pkt flows ? if there are 2 router in subnet ?
when is dns query fired ???  

    Wednesday, June 16, 2010

    Some question

    CA
    Remote login Through C code ?
    Return of printf?  printf("%d",m) whede m = 987

    -------------juniper

    Endianess happens because of what ? why cant OS take  care of it ?
    how to write code which can be easily ported across OS?
    Static Function?
    Hashing how to decide hash funciton?
    AVL tree ,  bst--Binary tree ? Complexity ot binary tree?  how nlogn comes?
    ---------------------------------
    LG.
    Q If i do malloc for 64 MB will it go if yes how .  Does process memory increases .
    Q Is Stack frame Size constant .  what is stack corruption.
    Q Use of extern in C++
    Q Can we have static  Ctor od Dtor  if not why??
    Press ENTER to look up in Wiktionary or CTRL+ENTER to look up in Wikipedia

    Friday, June 11, 2010

    Linux Find If Processor / CPU is 64 bit / 32 bit ( long mode ~ lm )

    for OS

    uname -a

     CPU
    grep flags /proc/cpuinfo 

    CPU Modes:

    lm means Long mode - 64 bit CPU

    Real mode 16 bit CPU

    Protected Mode is 32-bit CPU

     

    Monday, May 10, 2010

    Extensible Authentication Protocol - EAP

    * Extension to PPP
    * Authentication Framework , not a Specific Authentication Mechanism
    * Desired Authentication Method can be Negotiated  like EAP-TTLS, EAP-MD5, EAP-TLS,EAP-PSK
    * In 80.11 it is used to negotiate Secure PMK (Pairwise Master key )

    TTLS -Tunneled Transport Layer Security
    PSK- Pre Shared Key







    Codes :
    EAP                                          Radius
    1--Request                              1--Access Request
    2--Success                              2--Access Accept
    3--Response                           3--Access Reject
    4--Failure                               4--Accounting Request
                                                  5--Accounting Response

    Authentication in Wimax System

















    Protocols  Stack :

      

    Thursday, May 6, 2010

    Any real problem faced

    I face a problem wehre RAw Socket was in promniiscous mode and lietening to all intefaces  though it was intended to listen on one Inteface .
    // creation of raw socket 

     read_sockfd = socket( AF_PACKET , SOCK_RAW, htons(ETH_P_ALL)) ;
    This stmt was success but not solving purpose
    setsockopt(read_sockfd , SOL_SOCKET , SO_BINDTODEVICE , BIND_DEV , devlen+1 )


    Solution
        struct sockaddr_ll sa
        int interfaceId =-1;
        struct ifreq ifr;

        memset(&sa, 0, sizeof(sa));
        strncpy(ifr.ifr_name,BIND_DEV, devlen+1);
        sa.sll_family = AF_PACKET;
    // get interface index
        interfaceId = ioctl(read_sockfd ,SIOCGIFINDEX,&ifr);
        sa.sll_protocol = htons(ETH_P_ALL);
        sa.sll_ifindex =ifr.ifr_ifindex 
       bind( g_frame_read_sockfd , (struct sockaddr*) &sa, sizeof(sa));

    Thing is we have to explicitly bind raw socket to socket address structure(with proper interface index )
    Man page clearly says
    By default all packets of the specified protocol type are passed  to  a    packet  socket.    To  only  get  packets    from  a specific interface use  bind(2) specifying an address in  a  struct  sockaddr_ll  to  bind  the
     packet    socket     to  an  interface.  Only  the    sll_protocol  and  the  sll_ifindex address fields are used for purposes of binding.

    ------------------------------------------
     tcpdump  -d   vlan and ip  
    tcpdump -dd vlan and \(ip or arp \)
    tcpdump -d ether src 00:80:42:1B:1D:94 and vlan and \(ip or arp \)
    tcpdump -d not ether src 00:80:42:1B:1D:94 and vlan and \(ip or arp \)

    Friday, April 16, 2010

    Compiling Shared Libraries .so


    Need to compile Library in Position independent code 

    When the object files are generated, we have no idea where in memory they will be inserted in a program that will use them. Many different programs may use the same library, and each load it into a different memory in address. Thus, we need that all jump calls ("goto", in assembly speak) and subroutine calls will use relative addresses, and not absolute addresses. Thus, we need to use a compiler flag that will cause this type of code to be generated

    gcc -fPIC -c util_file.c
    gcc -fPIC -c util_net.c
    gcc -fPIC -c util_math.c
    gcc -shared libutil.so util_file.o util_net.o util_math.o
    Why is this Required ??
    dlopen()  --Thing is inspite of Loading library at begining . 
    From program we can specify when to Load and unload a Library 
    and what to use. 
    dlopen returns a handler on success 
    lib_handle = dlopen("/full/path/to/library", RTLD_LAZY); 
    
    
     
    RTLD_LAZY  -- Lazy aproach --defining whether all 
    symbols refered to by the library need to be checked immediately or When used 
    
    dlopen() UNLOAD


    Reference:
    http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html