A
A
antonyter2013-01-10 17:07:45
Android
antonyter, 2013-01-10 17:07:45

Falls on bind () in native?

I write the following native code:

sock = socket(AF_INET, SOCK_DGRAM, 0);<br>
    if(sock < 0) return false;<br>
    <br>
    addr.sin_family = AF_INET;<br>
    addr.sin_port = htons(UDP_PORT);<br>
    addr.sin_addr.s_addr = htonl(INADDR_ANY);<br>
<br>
    if(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) return false;<br>
<br>
...//читаем из сокета данные<br>

Falls on bind - 'Permission denied'
If set addr.sin_addr.s_addr is known to be correct - 'Cannot assign requested adress'

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vladimir Dubrovin, 2013-01-11
@antonyter

memset for addr done?

S
Sergey Melnikov, 2013-01-10
@RainM

Try to change addr.sin_addr.s_addr to a real IP or at least loopback
Does it work on Windows/Linux?

P
PVOID, 2013-01-10
@PVOID

Forgotten in the manifest
<uses-permission android:name="android.permission.INTERNET" />
?

J
jcmvbkbc, 2013-01-10
@jcmvbkbc

May be

sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question