Re: Problem with a UDP server implements

2011-10-19 Thread Bernd Petrovitsch
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 : be...@petrovitsch.priv.at
 LUGA : http://www.luga.at


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem with a UDP server implements

2011-10-18 Thread Bernd Petrovitsch
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 : be...@petrovitsch.priv.at
 LUGA : http://www.luga.at


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem with a UDP server implements

2011-10-17 Thread tao jiang
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 be...@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 : be...@petrovitsch.priv.at
                     LUGA : http://www.luga.at



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem with a UDP server implements

2011-10-15 Thread michi1
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:
 likeeth010.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

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem with a UDP server implements

2011-10-15 Thread tao jiang
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  mic...@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


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Problem with a UDP server implements

2011-10-15 Thread tao jiang
michi:

Thanks for your help.
Much appreciated.



2011/10/15  mic...@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


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Problem with a UDP server implements

2011-10-14 Thread jiangtao.jit
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:
likeeth010.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 


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies