Netlink socket creation failed even on rooted phone

2,064 views
Skip to first unread message

Prajakta Chaudhari

unread,
May 11, 2011, 5:22:55 PM5/11/11
to android-ndk
Hi all:

i need to use the ulogd user space application on android. It involves
creating netlink sockets. My phone is rooted.

As a root when i try to run the application, the netlink socket gets
created but fails to bind. I dont understand why

this should happen since i am a root user.


I tried this sample code but it fails to bind the socket.


void main()
{
int netlink_socket;
int seq=0;
struct sockaddr_nl addr;
int status;



netlink_socket = socket(PF_NETLINK,SOCK_DGRAM,NETLINK_NFLOG);

printf("\nSocket created");
if(netlink_socket <0)
{
return;
}

/*set up the socket address structure*/
memset(&addr,0,sizeof(struct sockaddr_nl));
addr.nl_family=AF_NETLINK;
addr.nl_pid=getpid();/*packets are destined for the kernel*/
addr.nl_groups=1;/*we don’t need any multicast groups*/

status = bind(netlink_socket, (struct sockaddr *)&addr, sizeof(addr));

printf("\nBinding process\n\n\n");
if(status<0)
{
printf("\nBinding fialed\n\n\n");

}


}


Any help will be appreciated.

Thank you,
regards,
Prajakta

Chris Stratton

unread,
May 11, 2011, 6:58:09 PM5/11/11
to andro...@googlegroups.com
On Wednesday, May 11, 2011 5:22:55 PM UTC-4, Prajakta Chaudhari wrote:
As a root when i try to run the application, the netlink socket gets
created but fails to bind. I dont understand why

this should happen since i am a root user.

Android applications started in the normal manner cannot run as root, even on a rooted phone.

Normally a "root required" type of application launches a native executable as root to do privileged work on its behalf, while the application's main process remains unprivileged.


 

prajakta choudhari

unread,
May 11, 2011, 9:44:39 PM5/11/11
to andro...@googlegroups.com
The above application is native executable.  when i execute it, the owner is root and it has all the possible permissions. But still the binding fails.

Thank you,
Regards,
Prajakta


--
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.

Tim Mensch

unread,
May 13, 2011, 4:46:41 PM5/13/11
to andro...@googlegroups.com
On 5/11/2011 7:44 PM, prajakta choudhari wrote:
> The above application is native executable. when i execute it, the
> owner is root and it has all the possible permissions. But still the
> binding fails.


Given that native rooted executables are not part of the NDK, you might have more luck with this question on one of the lists that deals with Android internals. I don't muck with things outside of the NDK, so I don't know what list to recommend; sorry.

Tim

Chris Stratton

unread,
May 13, 2011, 9:57:36 PM5/13/11
to andro...@googlegroups.com
On Wednesday, May 11, 2011 9:44:39 PM UTC-4, Prajakta Chaudhari wrote:
The above application is native executable.  when i execute it, the owner is root and it has all the possible permissions. But still the binding fails

On a test device running a customized variation of froyo, your test program fails to create a socket.

On a different device running a customized gingerbread, your program behaves the same way as it does on a desktop linux machine, ie, it binds the socket if and only if actually launched as root.  
I added a call to geteuid() to verify that - you might want to do the same.

$ whoami
app_9
$ ./a.out
Socket created
geteuid() returns 10009
Binding process
Binding fialed

# whoami
root
# ./a.out
Socket created
geteuid() returns 0
Binding process

prajakta choudhari

unread,
May 13, 2011, 9:59:11 PM5/13/11
to andro...@googlegroups.com
Thank you so much for your help.

strexxx

unread,
Nov 5, 2012, 12:10:25 PM11/5/12
to andro...@googlegroups.com, prajakta...@gmail.com
Have faced the same issue today.
Think it is related to the way the kernel was configured.

btw, do someone know where one can find the list of .config files used by manufacturer ?

Onur Cinar

unread,
Nov 5, 2012, 5:43:16 PM11/5/12
to andro...@googlegroups.com, prajakta...@gmail.com

Hi,

It is usually available as /proc/config.gz .

-onur

strexxx

unread,
Nov 6, 2012, 4:59:34 AM11/6/12
to andro...@googlegroups.com, prajakta...@gmail.com
Hi,

Thanks.

A quick check seems to indicate it is related to wether CONFIG_INET_TCP_DIAG is set or not.
Reply all
Reply to author
Forward
0 new messages