Setting a NIC to Promiscuous Mode

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kardon33
    New Member
    • May 2007
    • 158

    Setting a NIC to Promiscuous Mode

    Hello all,

    I am trying to write a C program on Unix (OpenBSD 4.3) that will be sniffing a certain packet which is being sent by a diff rent machine to another different machine.

    The only way I believe this is possible is to set my NIC into promiscuous mode.

    I would like to set the NIC to Promiscuous mode in my C program but I would also be content if anyone knows a way to just set it in that mode permanently, but thats more of a question for an BSD forum.

    As for the code method, I have searched google for awhile now but have still not found a technique that works, everything I try usually doesn't work because the header file #include <netinet/tcp.h> has errors in it.


    Here is the method that I found in a bunch of places online, I get syntax errors in the #include <netinet/ip.h> #include <netinet/tcp.h> header files.

    /usr/include/netinet/ip.h:156: error: syntax error before "n_time"


    Code:
    #include <stdlib.h>
    #include <sys/socket.h>
    #include <netinet/ip.h>
    #include <netinet/tcp.h>
    #include <linux/if.h>
    #include <sys/ioctl.h>
    
    int promisc(){
    
    	int fd;
    	struct ifreq eth;
    	
    	fd = socket(AF_INET, SOCK_PACKET, htons(0x800));
    	
    	strcpy(eth.ifr_name, "eth0");
    	
    	ioctl(fd, SIOCGIFFLAGS, &eth);
    	
    	eth.ifr_flags |= IFF_PROMISC;
    	
    	ioctl(fd, SIOCSIFFLAGS, &eth);
    
    
    }
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    I grepped for n_time in the folder /usr/include/netinet and got these
    $ grep n_time /usr/include/netinet/*.h
    /usr/include/netinet/in_systm.h:type def u_int32_t n_time; /* ms since 00:00 GMT, byte rev */

    Try including this header file or check whether you have to have some specific #define for this

    Raghu

    Comment

    Working...