From mboxrd@z Thu Jan 1 00:00:00 1970 From: michi1@michaelblizek.twilightparadox.com (michi1 at michaelblizek.twilightparadox.com) Date: Sat, 15 Oct 2011 08:04:44 +0200 Subject: Problem with a UDP server implements In-Reply-To: <201110150151405785431@gmail.com> References: <201110150151405785431@gmail.com> Message-ID: <20111015060444.GA2282@grml> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org 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