socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP)

2,070 views
Skip to first unread message

strexxx

unread,
May 25, 2012, 12:26:30 PM5/25/12
to android-ndk
Hi,

socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP)

I have searched for some of the combination of the words from the
subject (plus android) but, unfortunately, I have found nothing.
The functionality exists for instance on Mac OS X where it permits to
make a ping with no setuid.
There are also a lot of traceroute and ping utilities for android that
exists on the market, and I thought they benefited from such things...

Still, I wonder, is this available ?
(actually, for linux, I have found no clear evidence of if it was
something mainstream, or not)

when I ndk-build a piece of code for this, everything is fine.
I call it from JNI (with INTERNET permission in the manifest) and it
got correctly called.
but, sendto fails and errno to 9 (EBADF)...

The same piece of code -with the jni signature removed- works
perfectly on Mac OS X...
(but can put the raw code here if anyone wants).

Has someone some advice to give ?
Is someone willing to share some pointers about this ?
Is it something available at all ?

strexxx

unread,
May 26, 2012, 1:32:06 PM5/26/12
to android-ndk
socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP)
(with proper INTERNET permission)
gives a non-null fd but,
it also gives errno 9 (EBADF) when sendto is called...

is this kind of socket really available ?

(possible duplicate of a not acknowledged post)

Stéphane WUSTNER

unread,
May 26, 2012, 6:35:26 PM5/26/12
to android-ndk
I should have double checked twice,
socket(PF_INET, SOCK_DGRAM, IPPROTO_ICMP)
returns -1 and errno gives EPROTONOSUPPORT
so, I think it means it is not available...

sorry for the disturbance.
Thx

Stéphane WUSTNER

unread,
May 26, 2012, 7:57:40 PM5/26/12
to android-ndk
I figured out from some readings that the ICMP socket patch* had found its way through kernel 3.*
I have no ICS device to test with, so, I wonder if this option is activated ?


* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=c319b4d76b9e583a5d88d6bf190e079c4e43213d

David Turner

unread,
May 29, 2012, 9:09:29 AM5/29/12
to andro...@googlegroups.com
Even if it was available, you wouldn't be able to use these sockets without root. The only protocols supported for applications are TCP and UDP.


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


strexxx

unread,
May 29, 2012, 10:12:15 AM5/29/12
to android-ndk
> Even if it was available, you wouldn't be able to use these sockets without
> root.
I thought that the entire purpose of such a patch would be to support an (even limited) access to this kind of "socket" *without* root...
(Still, I have finally tested with an iconia under Android 4.0.3 -kernel '2.6.34.4+' -, and still the same error….
maybe with some later kernel…)

> The only protocols supported for applications are TCP and UDP.
So, there is no support also for SCTP ?
Stuck with the ping binary for ping, traceroute, etc?

David Turner

unread,
May 29, 2012, 10:44:33 AM5/29/12
to andro...@googlegroups.com
On Tue, May 29, 2012 at 4:12 PM, strexxx <str...@free.fr> wrote:
> Even if it was available, you wouldn't be able to use these sockets without
> root.
I thought that the entire purpose of such a patch would be to support an (even limited) access to this kind of "socket" *without* root...
(Still, I have finally tested with an iconia under Android 4.0.3 -kernel '2.6.34.4+' -, and still the same error….
maybe with some later kernel…)

You are probably right, sorry for my confusion. I assume you're referring to something like http://lwn.net/Articles/443051/

I have no idea when/if this will/is part of the Android kernel source tree for a given device, nor if it is/will be enabled on stock Android builds though.
 
> The only protocols supported for applications are TCP and UDP.
So, there is no support also for SCTP ?
Stuck with the ping binary for ping, traceroute, etc?

At the moment that's true, I'm afraid.

strexxx

unread,
May 29, 2012, 10:57:19 AM5/29/12
to android-ndk
You are probably right, sorry for my confusion.
(I fear I have caused it with too many posts)

I assume you're referring to something like http://lwn.net/Articles/443051/ 
Yes, exactly !
I have no idea when/if this will/is part of the Android kernel source tree
I actually wondered where the kernel source tree was available indeed. (or just the changelog of features)

 for a given device, nor if it is/will be enabled on stock Android builds though.
How does it works ? Have manufacturers the habit of rejecting a kernel feature ?

David Turner

unread,
May 29, 2012, 4:41:32 PM5/29/12
to andro...@googlegroups.com
On Tue, May 29, 2012 at 4:57 PM, strexxx <str...@free.fr> wrote:
You are probably right, sorry for my confusion.
(I fear I have caused it with too many posts)
I assume you're referring to something like http://lwn.net/Articles/443051/ 
Yes, exactly !
I have no idea when/if this will/is part of the Android kernel source tree
I actually wondered where the kernel source tree was available indeed. (or just the changelog of features)

https://android.googlesource.com/kernel/common.git contains the "common" Android kernel tree that is shared by various other ones.

For example, https://android.googlesource.com/kernel/omap.git contains the OMAP-specific kernel sources which are built on top of it, iirc.

These come from the core Android system/kernel team. OEM might have customized trees themselves. You would need to check their own sites to get the relevant sources. 
 for a given device, nor if it is/will be enabled on stock Android builds though.
How does it works ? Have manufacturers the habit of rejecting a kernel feature ?

I don't have much detail, but we have a Compatibility Test Suite that checks for a number of required features. I don't have the exact list, but apart from these, OEMs are free to do what they want (i.e. add or remove features if they are not required by the CTS).

Chris Stratton

unread,
Jun 3, 2012, 9:06:46 PM6/3/12
to android-ndk
On May 29, 9:09 am, David Turner <di...@android.com> wrote:
> Even if it was available, you wouldn't be able to use these sockets without
> root.

Not that it changes the situation for applications, but I believe it's
actually root, or shell. At least ping worked from the adb shell last
time I tried it

David Turner

unread,
Jun 4, 2012, 4:34:45 AM6/4/12
to andro...@googlegroups.com
That's because /system/bin/ping is a setuid program, so it essentially runs as root even when invoked from the 'shell' usedID (or an APP UID).
That's completely different from trying to implement the ping functionality from a normal application.
Reply all
Reply to author
Forward
0 new messages