Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 10-27-2014, 07:02 AM   #1
LQ Newbie
Registered: Oct 2014
Posts: 4

Rep: Reputation: Disabled
C: How to drop packet before full download


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:

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.

Old 10-27-2014, 11:26 AM   #2
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
getpeername() will tell you the source IP and can be called on the socket after you've accepted a connection before looking at application data.
Old 11-02-2014, 07:20 AM   #3
LQ Newbie
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks, that helped


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
ifconfig reports packet drop grob115 Linux - Networking 19 01-26-2016 08:17 AM
packet drop notifications vlyamtse Linux - Networking 0 12-07-2011 10:32 AM
Drop packet on eth1 tbaror Linux - Newbie 4 11-23-2008 10:21 AM
how to delay and drop the packet sonika_singhi Linux - Networking 4 04-02-2005 04:55 PM
drop packet in router becky_starr Programming 0 02-17-2004 08:43 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration