* Problem with a UDP server implements
@ 2011-10-14 17:51 jiangtao.jit
2011-10-15 6:04 ` michi1 at michaelblizek.twilightparadox.com
2011-10-15 11:58 ` Bernd Petrovitsch
0 siblings, 2 replies; 11+ messages in thread
From: jiangtao.jit @ 2011-10-14 17:51 UTC (permalink / raw)
To: kernelnewbies
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 packet to 10.0.0.2(the eth0:1 's ip)
the server can recieve the packet and reply, but the client can't recieve the server's response
I use wireshark to capture the response packet
and found that the server use 10.0.0.1(the eth0 's ip) as saddr in the response packet
I expected it to be 10.0.0.2 but it's not
my question : is there any way to let the UDP server relpy just use the ip it receieved the request ?
It's :
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
Thanks.
2011-10-15
jiangtao.jit
^ permalink raw reply [flat|nested] 11+ messages in thread* Problem with a UDP server implements
2011-10-14 17:51 Problem with a UDP server implements jiangtao.jit
@ 2011-10-15 6:04 ` michi1 at michaelblizek.twilightparadox.com
2011-10-15 8:29 ` tao jiang
2011-10-15 11:58 ` Bernd Petrovitsch
1 sibling, 1 reply; 11+ messages in thread
From: michi1 at michaelblizek.twilightparadox.com @ 2011-10-15 6:04 UTC (permalink / raw)
To: kernelnewbies
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-15 6:04 ` michi1 at michaelblizek.twilightparadox.com
@ 2011-10-15 8:29 ` tao jiang
2011-10-15 9:01 ` michi1 at michaelblizek.twilightparadox.com
0 siblings, 1 reply; 11+ messages in thread
From: tao jiang @ 2011-10-15 8:29 UTC (permalink / raw)
To: kernelnewbies
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@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
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-15 8:29 ` tao jiang
@ 2011-10-15 9:01 ` michi1 at michaelblizek.twilightparadox.com
2011-10-15 9:50 ` tao jiang
0 siblings, 1 reply; 11+ messages in thread
From: michi1 at michaelblizek.twilightparadox.com @ 2011-10-15 9:01 UTC (permalink / raw)
To: kernelnewbies
Hi!
On 16:29 Sat 15 Oct , tao jiang wrote:
> 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 ?
Yes, exactly.
> 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 ?
You should receive the packet only on the socket which is bound to the
address. You can save the bind address somewhere, so you know the local
address. You will know the client address because it is passed back by
recvfrom.
-Michi
--
programing a layer 3+4 network protocol for mesh networks
see http://michaelblizek.twilightparadox.com
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-15 9:01 ` michi1 at michaelblizek.twilightparadox.com
@ 2011-10-15 9:50 ` tao jiang
0 siblings, 0 replies; 11+ messages in thread
From: tao jiang @ 2011-10-15 9:50 UTC (permalink / raw)
To: kernelnewbies
michi:
Thanks for your help.
Much appreciated.
2011/10/15 <michi1@michaelblizek.twilightparadox.com>:
> Hi!
>
> On 16:29 Sat 15 Oct ? ? , tao jiang wrote:
>> 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 ?
>
> Yes, exactly.
>
>> 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 ?
>
> You should receive the packet only on the socket which is bound to the
> address. You can save the bind address somewhere, so you know the local
> address. You will know the client address because it is passed back by
> recvfrom.
>
> ? ? ? ?-Michi
> --
> programing a layer 3+4 network protocol for mesh networks
> see http://michaelblizek.twilightparadox.com
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-14 17:51 Problem with a UDP server implements jiangtao.jit
2011-10-15 6:04 ` michi1 at michaelblizek.twilightparadox.com
@ 2011-10-15 11:58 ` Bernd Petrovitsch
2011-10-17 23:26 ` tao jiang
1 sibling, 1 reply; 11+ messages in thread
From: Bernd Petrovitsch @ 2011-10-15 11:58 UTC (permalink / raw)
To: kernelnewbies
On Sam, 2011-10-15 at 01:51 +0800, 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 packet to 10.0.0.2(the eth0:1 's ip)
> the server can recieve the packet and reply, but the client can't recieve the server's response
> I use wireshark to capture the response packet
> and found that the server use 10.0.0.1(the eth0 's ip) as saddr in the response packet
> I expected it to be 10.0.0.2 but it's not
> my question : is there any way to let the UDP server relpy just use the ip it receieved the request ?
> It's :
> 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
You can always build the complete raw packet (including the IP header)
yourself.
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 11+ messages in thread* Problem with a UDP server implements
2011-10-15 11:58 ` Bernd Petrovitsch
@ 2011-10-17 23:26 ` tao jiang
2011-10-18 9:20 ` Bernd Petrovitsch
0 siblings, 1 reply; 11+ messages in thread
From: tao jiang @ 2011-10-17 23:26 UTC (permalink / raw)
To: kernelnewbies
Bernd:
Is it to create a SOCK_RAW socket for receieve and send?
Then is it means I have to parse the IP header and options if any?
Will it cause performance problem, compare to SOCK_DGRAM?
Thanks.
2011/10/15 Bernd Petrovitsch <bernd@petrovitsch.priv.at>:
> On Sam, 2011-10-15 at 01:51 +0800, 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 packet to 10.0.0.2(the eth0:1 's ip)
>> the server can recieve the packet and reply, but the client can't recieve the server's response
>> I use wireshark to capture the response packet
>> and found that the server use 10.0.0.1(the eth0 's ip) as saddr in the response packet
>> I expected it to be 10.0.0.2 but it's not
>> my question : is there any way to let the UDP server relpy just use the ip it receieved the request ?
>> It's :
>> 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
>
> You can always build the complete raw packet (including the IP header)
> yourself.
>
> ? ? ? ?Bernd
> --
> Bernd Petrovitsch ? ? ? ? ? ? ? ? ?Email : bernd at petrovitsch.priv.at
> ? ? ? ? ? ? ? ? ? ? LUGA : http://www.luga.at
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-17 23:26 ` tao jiang
@ 2011-10-18 9:20 ` Bernd Petrovitsch
2011-10-18 14:48 ` tao jiang
0 siblings, 1 reply; 11+ messages in thread
From: Bernd Petrovitsch @ 2011-10-18 9:20 UTC (permalink / raw)
To: kernelnewbies
On Die, 2011-10-18 at 07:26 +0800, tao jiang wrote:
[....]
> Is it to create a SOCK_RAW socket for receieve and send?
Only for sending. Search for sourcecode for `ping` - there are
several around that show how to do it.
You can use recvfrom() to get the senders address for each packet.
[...]
> Will it cause performance problem, compare to SOCK_DGRAM?
IMHO that won't measurably - either user-space constructs the UDP and IP
header or the kernel does. And we talk about a few bytes only.
[ Don't top-post. ]
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 11+ messages in thread* Problem with a UDP server implements
2011-10-18 9:20 ` Bernd Petrovitsch
@ 2011-10-18 14:48 ` tao jiang
2011-10-19 7:28 ` Bernd Petrovitsch
0 siblings, 1 reply; 11+ messages in thread
From: tao jiang @ 2011-10-18 14:48 UTC (permalink / raw)
To: kernelnewbies
Bernd:
Thanks for your guide.
But there is still a question
if recvfrom() used, how to figure out the client's dest ip for reply ?
i.e. on which ip the server receieved the request
when construct the IP header, i don't know which saddr to fill in
Thanks.
2011/10/18 Bernd Petrovitsch <bernd@petrovitsch.priv.at>:
> On Die, 2011-10-18 at 07:26 +0800, tao jiang wrote:
> [....]
>> Is it to create a SOCK_RAW socket for receieve and send?
>
> Only for sending. Search for sourcecode for `ping` - there are
> several around that show how to do it.
>
> You can use recvfrom() to get the senders address for each packet.
>
> [...]
>> Will it cause performance problem, compare to SOCK_DGRAM?
>
> IMHO that won't measurably - either user-space constructs the UDP and IP
> header or the kernel does. And we talk about a few bytes only.
>
> [ Don't top-post. ]
>
> ? ? ? ?Bernd
> --
> Bernd Petrovitsch ? ? ? ? ? ? ? ? ?Email : bernd at petrovitsch.priv.at
> ? ? ? ? ? ? ? ? ? ? LUGA : http://www.luga.at
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Problem with a UDP server implements
2011-10-18 14:48 ` tao jiang
@ 2011-10-19 7:28 ` Bernd Petrovitsch
2011-10-21 13:07 ` tao jiang
0 siblings, 1 reply; 11+ messages in thread
From: Bernd Petrovitsch @ 2011-10-19 7:28 UTC (permalink / raw)
To: kernelnewbies
Hi!
On Die, 2011-10-18 at 22:48 +0800, tao jiang wrote:
[...]
> Thanks for your guide.
> But there is still a question
> if recvfrom() used, how to figure out the client's dest ip for reply ?
> i.e. on which ip the server receieved the request
> when construct the IP header, i don't know which saddr to fill in
Ooops, forgot that we need the destination address of the received
packet too to construct the answer for it.
Then yes, it seems that you would need the raw packet on the receiving
side too.
[ Full quote deelted ]
Bernd
--
Bernd Petrovitsch Email : bernd at petrovitsch.priv.at
LUGA : http://www.luga.at
^ permalink raw reply [flat|nested] 11+ messages in thread* Problem with a UDP server implements
2011-10-19 7:28 ` Bernd Petrovitsch
@ 2011-10-21 13:07 ` tao jiang
0 siblings, 0 replies; 11+ messages in thread
From: tao jiang @ 2011-10-21 13:07 UTC (permalink / raw)
To: kernelnewbies
Bernd:
Thanks again.
2011/10/19 Bernd Petrovitsch <bernd@petrovitsch.priv.at>:
> Hi!
>
> On Die, 2011-10-18 at 22:48 +0800, tao jiang wrote:
> [...]
>> Thanks for your guide.
>> But there is still a question
>> if recvfrom() used, how to figure out the client's dest ip for reply ?
>> i.e. on which ip the server receieved the request
>> when construct the IP header, i don't know which saddr to fill in
>
> Ooops, forgot that we need the destination address of the received
> packet too to construct the answer for it.
> Then yes, it seems that you would need the raw packet on the receiving
> side too.
>
> [ Full quote deelted ]
>
> ? ? ? ?Bernd
> --
> Bernd Petrovitsch ? ? ? ? ? ? ? ? ?Email : bernd at petrovitsch.priv.at
> ? ? ? ? ? ? ? ? ? ? LUGA : http://www.luga.at
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-10-21 13:07 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-14 17:51 Problem with a UDP server implements jiangtao.jit
2011-10-15 6:04 ` michi1 at michaelblizek.twilightparadox.com
2011-10-15 8:29 ` tao jiang
2011-10-15 9:01 ` michi1 at michaelblizek.twilightparadox.com
2011-10-15 9:50 ` tao jiang
2011-10-15 11:58 ` Bernd Petrovitsch
2011-10-17 23:26 ` tao jiang
2011-10-18 9:20 ` Bernd Petrovitsch
2011-10-18 14:48 ` tao jiang
2011-10-19 7:28 ` Bernd Petrovitsch
2011-10-21 13:07 ` tao jiang
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.