LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


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

Rep: Reputation: Disabled
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
 
Old 10-27-2014, 11:26 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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.
 
Old 11-02-2014, 07:20 AM   #3
chelem
LQ Newbie
 
Registered: Oct 2014
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thanks, that helped
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:50 PM.

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