When I run a simple packet sniffer encoded in C on my Mac OS X, I didn’t get anything at all, this is a strange thing! can someone help me understand what is happening.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void) { int i, recv_length, sockfd; u_char buffer[9000]; if ((sockfd = socket(PF_INET, SOCK_RAW, IPPROTO_TCP)) == -1) { printf("Socket failed!!\n"); return -1; } for(i=0; i < 3; i++) { recv_length = recv(sockfd, buffer, 8000, 0); printf("Got some bytes : %d\n", recv_length); } return 0; }
I compile it and run on my box, and nothing happens:
MacOsxBox:Desktop evariste$sudo ./simpleSniffer
Thank you for your help.
c sockets macos packet-sniffers sniffing
funnyCoder
source share