How to use iptables in an Android application
Asked Answered
R

1

7

How can I use iptables in an Android application? I need this for a firewall-like functionality i.e. packet filtering, blocking sites etc.

I'm also not sure whether iptables are available in the Android kernel.

I previously heard that I'd have to create cross-compiled binaries of iptables – but how can I do that? And how can I use them in the application?

Region answered 11/1, 2011 at 14:26 Comment(0)
E
5

It's definitely possible. You might consider looking at the source code of Droidwall.

DroidWall - Android Firewall is a front-end application for the powerful iptables Linux firewall. It allows you to restrict which applications are permitted to access your data networks (2G/3G and/or Wi-Fi).

Check out the iptables API from Droidwall for specific examples.

Note that when using iptables you need root access to your phone.

Eer answered 11/1, 2011 at 14:30 Comment(7)
i saw that,but how do i create that iptables binary....and use it inside the application... and what it will contain.Region
now that android kernel does not have iptables inbuilt, so whether that binary only will supply the functionality? so that means rules have to be put inside once..and in the droidwall, the main api which handles the communication between the main application and the iptables contains some rules and some shell script that will may be executed in the kernel.Region
so how can rules be edited dynamically... and actually i plan to keep rulesets in an seprate file...and only when the internet connection is activated, the file will be loaded in the memory and interface with the iptables...Region
i dont know how far clear i am able to make myself...but this is what i need to do...Region
I'm sorry, I don't really have the time to look into that. Maybe make your question clearer by putting your comments in it and somebody has a clue!Eer
ok..i am still studying iptables thoroughly.. and some android internal as well... lets c if i can find some way out...Region
anyways...thankyou very much for giving time to answer the Q.Region

© 2022 - 2024 — McMap. All rights reserved.