Socket Creation fails in native code

893 views
Skip to first unread message

Riasat Abir

unread,
Mar 29, 2011, 12:27:28 AM3/29/11
to android-ndk
Hi all,

I've created a socket in the native code.

m_sock = socket(m_iAf, m_iType, m_iProtocol); // m_iAf = 2, m_iType= 2, m_iProtocol = 17(udp)

Through debugging with ndk-gdb, I found that it's returning -1 that means socket creation has failed.

How can I find it out why it fails?

I tried to debug with: printf("errno = %d, %s\n", errno, strerror(errno));

But printed line doesn't show up in the console of ndk-gdb.

Any help?

Regards,
Riasat

Riasat Abir

unread,
Mar 29, 2011, 2:04:55 AM3/29/11
to android-ndk
m_sock = socket(AF_INETSOCK_DGRAM, m_iProtocol); //udpprotocol

Ok I found the errno: 13
and the reason says  0xafd471ec "Permission denied"

What does it mean?
Which permission to enable for socket creating?

Thanks,
Riasat
--

HimHim

Srinidhi K V

unread,
Mar 29, 2011, 2:10:17 AM3/29/11
to andro...@googlegroups.com
You need "su" permission to create a socket, unless you hack the kernel.

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

Riasat Abir

unread,
Mar 29, 2011, 2:12:33 AM3/29/11
to andro...@googlegroups.com
I am running on windows platform with Cygwin.
--

HimHim

Riasat Abir

unread,
Mar 29, 2011, 3:06:03 AM3/29/11
to andro...@googlegroups.com
I've tried in ubuntu with super user mode.
Says the same.

Permission denied, errno 13

On Tue, Mar 29, 2011 at 12:10 PM, Srinidhi K V <srini...@yahoo.co.in> wrote:



--

HimHim

Riasat Abir

unread,
Mar 29, 2011, 3:20:09 AM3/29/11
to andro...@googlegroups.com
I've figured out the solution.
My application didn't have internet access permission.

I added this line:

<uses-permission android:name="android.permission.INTERNET" />

So if anyone faces problem with permission, check the application permission.

Thanks,
Riasat
--

HimHim

Nasif Noorudeen

unread,
Mar 29, 2011, 1:49:52 PM3/29/11
to andro...@googlegroups.com
you have to give android permission for internet in manifest file



If you want to see the datas that is printed in native side


you have to use functions from android/log.h in the android-ndk/platform/include.....




and LOCAL_LDLIBS --llog in android.mk
Reply all
Reply to author
Forward
0 new messages