Problem with a UDP server implements

tao jiang jiangtao.jit at gmail.com
Sat Oct 15 04:29:45 EDT 2011


michi:

1.
Is that to create two sockets
and one bind to 10.0.0.1 the other bind to 10.0.0.2
then use epoll wait these two sockets ?

2.
Is there any way to find out the turple like TCP
then the UDP server can reply with exactly the ip it recieved the
client's request ?

Thanks.



2011/10/15  <michi1 at michaelblizek.twilightparadox.com>:
> Hi!
>
> On 01:51 Sat 15 Oct     , jiangtao.jit wrote:
>> Hi:
>>
>> I'm writing a UDP server and meet a problem
>> the UDP server program is run on a box with single card but has multi ip:
>> like    eth0        10.0.0.1
>>         eth0:1     10.0.0.2
>>               eth0:2          11.0.0.1
>>
>> I bind the server socket with INADDR_ANY
> ...
>> when a client send a request to 10.0.0.1(eth0); the server use 10.0.0.1 to response
>> and another client send a request to 10.0.0.2(eth0:1); the server use 10.0.0.2 to response
>
> Well, is seems there is neither a variant of recvfrom() which tells you your
> local address nor a variant of sendto() which allows you to specify your local
> address. I guess you have to call getaddrinfo() and create a socket for every
> address you want to bind to. If you want to stay single threaded you can
> switch them to nonblocking and use epoll to wait for packets.
>
>        -Michi
> --
> programing a layer 3+4 network protocol for mesh networks
> see http://michaelblizek.twilightparadox.com
>



More information about the Kernelnewbies mailing list