I am doing a port scanner program as part of a school project where am using raw sockets. My understanding is this:
When using multithreading with raw sockets, each pthread does NOT get a copy of the packets seen by the NIC. Hence to handle all the different thread, I would need a receiving thread that passes messages to the correct thread.
Is this correct?
EDIT : My hypothesis is, the OS sends the packet only once to the process. If the wrong pthread was receiving the packet, the packet could be missed.
I think if you want to receive the packets in all threads, you just need to create a separate raw socket (with the same arguments) in each thread. I haven't found a good resource describing this on Linux, but that's how it's documented on Windows:
if several SOCK_RAW sockets are open on a computer at the same time, the same datagrams may be delivered to all the open sockets
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.