Re: Sniffing on a specific NIC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 28 Nov 2001 17:49:54 +0530
"chakri" <chakraa@future.futsoft.com> wrote:

> Hi,
> 
> I have a machine with multiple NICs supported.
> I am trying to capture packets using the PACKET_SOCKET directly on the
> Ethernet.
> It is observed that recvfrom () captures packets received on all the
NICs
> supported in the host.
> I do have a mechanism of sorting the packets based on NIC (using sa_addr
> member of sockaddr structure). But how do I capture only those packets
> coming on a specific NIC (say eth1). Is there a way wherein I specify to
> receive packets coming at a particular interface only?

int openintf(char *d)                                                     
                                 
{                                                                         
                               
   int fd;                                                                
                                   struct ifreq ifr;                      
                                                                   int s; 
                                                                          
                      
   fd=socket(AF_INET, SOCK_PACKET, htons(0x800));                         
                                   if(fd < 0)                             
                                                                   {      
                                                                          
                           perror("cant get SOCK_PACKET socket");         
                                                           exit(0);       
                                                                          
             }                                                            
                                             strcpy(ifr.ifr_name, d);     
                                                                          
  s=ioctl(fd, SIOCGIFFLAGS, &ifr);                                        
                                  if(s < 0)                               
                                                                  {       
                                                                          
                          close(fd);                                      
                                                          perror("cant get
flags");                                                                  
               exit(0);                                                   
                                            }                             
                                                                          
 ifr.ifr_flags |= IFF_PROMISC;                                            
                                 s=ioctl(fd, SIOCSIFFLAGS, &ifr);         
                                                                 if(s < 0)
perror("cant set promiscuous mode");                                      
                      return fd;                                          
                                                    }                     
                                                                          
          
May be it is what you want?
Parameter for openintf() must be the name of an interface to open, t.e.
for example "eth1".
And after it you can read()/write() from/to obtained socket.

> 
> Re,
> Chuks

---
WBR. //s0mbre
-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux