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"
Expand|Select|Wrap|Line Numbers
- #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.ifr_flags |= IFF_PROMISC;
- ioctl(fd, SIOCSIFFLAGS, ð);
- }