Re: How to listen to more a specific IP and specific ports



Hi,
I have read this long time ago in the textbook Unix Network Programming
....Vol. 1 for Richard Stevense. The concept is called Multihomed hosts where
you have a system with more than one NIC, each has its own IP address, or one
NIC has been assigned more than on IP, with different subnet mask on both
cases.

Ok, I was looking for that section in book, I think I have forgot. As
explained in the book on page 93, that we can have mutiple running server
services, one for each interface, and we have to bind the socket to a
specific IP address in each running copy, or we can run a single server
service and connect our socket to INADDR_ANY and then listen for incoming
request. upon receiving a request, we check the destination IP address. If
the destination IP doesn't match one of the allowed registerd IPs in the
database, we just ignore that request, otherwise we proceed with processing
it.

However, I am thankful for you guys.

Regards
Bassam

"Arkady Frenkel" wrote:

Hi!
"Bassam" <Bassam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:12821CE1-47EB-45D1-8BA0-6075F0EEA366@xxxxxxxxxxxxxxxx
Dear Alexander,
Thanks for your clarification. Its clear to me on how to bind with
specific ports. My intention is to have a general solution in which I can
bind my socket to specific unlimited and selective IP addresses.
For example, a server machine has 5 interfaces, each one is configured
with
different subnet mask. At the time being I want to bind my server
application
service to two IP addresses and in the future I want to bind to the third
or
fourth ones. It is not feasible and practical to everytime edit my code
and
add or remove the socket combinationes!!?.



Moreover, in Unix/Linux Berekly network programming, you can determin the
IP
addresses that you may want to bind to. As I remeber, instead of using
INADDR_ANY, you can specify the IP addresses that you may want to bind to.

Where did you see that , can you provide the link ?
AFAIK no such at BSD sockets maybe Linux implementation add such feature...

Arkady

Please, get more clarification about this matter, whether possible to do
it
with microsoft network programming or not.

Regards
Bassam

"Alexander Nickolov" wrote:

You need 4 sockets bound to each combination of IP address
and port (2 IP addresses times 2 ports amounts to 4 sockets
necessary). If the computer only has these two IP addresses
and you don't mind listening to the loopback address, you
can use two sockets with INADDR_ANY and the two specific
port numbers.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Bassam" <Bassam@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:77BD5E60-9D57-484E-830E-E5456812B472@xxxxxxxxxxxxxxxx
Dear all,
I am writing a network application that requires me to bind it to
specific network IP addresses and specific ports.

The normal binding resides in filling up the SOCKADDR_IN structure with
any
IP "INADDR_ANY" or a particular IP "192.168.1.148" and a single port as
follows:

SOCKADDR_IN tcpaddr;
int port = 1812;

tcpaddr.sin_family = AF_INET;
tcpaddr.sin_port = htons(port); //Single port
tcpaddr.sin_addr.s_addr = htonl(INADDR_ANY); //Any IP
or
tcpaddr.sin_addr.s_addr = htonl("192.168.1.148"); //A particular IP

Also this can be achieved by filling up the ADDRINFO structure of the
hints
parameter of the address resolution function "getaddrinfo()" as
follows:

ADDRINFO hints;
LPADDRINFO resultPtr = NULL;

memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE; //to determin any IP
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;

getaddrinfo(NULL, "1812", &hints, &resultPtr);

The first argument of "getaddrinfo()" is NULL to determin that we are
willing to bind to any IP, and the second argument is a single port.

NOW: my question is how to listen to traffic coming through particular
IPs
(i.e., "192.168.1.148" and "192.168.10.30") on the server machin and
particular ports 1812 and 1813 at the same time?

Do I need to bind my single socket handler to different SOCKADDR_IN
structures each has its own IP address and port no.. However, I find
this
way
is not feasible because the particular IPs are not fixed. I mean
sometime
I
need to listen to one or two or more particular IPs.

I would appreciate if you shed light on this matter.

Regards
Bassam






.



Relevant Pages

  • Re: How to listen to more a specific IP and specific ports
    ... bind my socket to specific unlimited and selective IP addresses. ... Moreover, in Unix/Linux Berekly network programming, you can determin the ... port numbers. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Bind on port fails while switch the user.
    ... application was not able to bind on port. ... There is a socket option that you can ... int fd, err; ...
    (comp.sys.mac.programmer.help)
  • Re: How to listen to more a specific IP and specific ports
    ... bind my socket to specific unlimited and selective IP addresses. ... port numbers. ... is not feasible because the particular IPs are not fixed. ...
    (microsoft.public.win32.programmer.networks)
  • Re: How to listen to more a specific IP and specific ports
    ... bind my socket to specific unlimited and selective IP addresses. ... Moreover, in Unix/Linux Berekly network programming, you can determin the IP ... port numbers. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Problem with socket
    ... Be aware that those port numbers are part of the IANA-assigned range. ... socket operations on sockets for which there are no handles... ... The result of using comma lists is ... you have used the completely meaningless word "crash" to describe your ...
    (microsoft.public.vc.mfc)