LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   C: How to drop packet before full download (https://www.linuxquestions.org/questions/linux-networking-3/c-how-to-drop-packet-before-full-download-4175523461/)

chelem 10-27-2014 07:02 AM

C: How to drop packet before full download
 
Hi,

I'm creating a personal app for network filtering using C. I already know that you can log and analyze a downloaded packet's info using this code:

Code:

tcpPacket = recvfrom(raw_socket , buffer , 65536 , 0 , &serverAddress , &serverAddressSize);
but this requires that the tcp packet be downloaded first. What I need is that the filter will be acted out even before it is downloaded, let's say it examines the source IP and based on that, it either accepts or rejects it.

Note: Yes I am aware of iptables, but I do not want to use it because I want to learn how to do it using raw sockets.

Thanks

linosaurusroot 10-27-2014 11:26 AM

getpeername() http://man7.org/linux/man-pages/man2/getpeername.2.html will tell you the source IP and can be called on the socket after you've accepted a connection before looking at application data.

chelem 11-02-2014 07:20 AM

Thanks, that helped


All times are GMT -5. The time now is 12:47 AM.