I am trying to create a raw socket that sends and receives a message with the ip / tcp header under linux. I can successfully bind to a port and receive a tcp message (i.e.: syn) However, the message seems to be processed by os, but not mine. I just read it (e.g. wirehark). My raw socket binds to port 8888, and then I try to connect to that port. In wirehark, this shows that port 8888 answers "the first time" when it receives a "syn" request. In my program, he shows that he is receiving a new message, and he is not responding with any message.
Any way to bind to this port? (forbid to process it)
Here is part of my code, I am trying to shorten this error checking for easy reading
sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_TCP); int tmp = 1; const int *val = &tmp; setsockopt (sockfd, IPPROTO_IP, IP_HDRINCL, val, sizeof (tmp)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(8888); bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr));
user194420
source share