Re: UDP broadcast with 2 adapters



Denville,
I don't think the answers you got previously are right and I don't think
your "receive" code does what you think it does.

You have the comment "binds to all ip's" where you used INADDR_ANY. That is
not the effect of using INADDR_ANY in your bind call. The effect is that
you are letting the system decide which local interface to bind to (assuming
there is more than one). A bind only binds to one address and it is always
a local address. A connect deals with a remote address.

If I have understood you correctly, what you really want to do is use the
address of one of the two physical NICs on your PC in the bind call. This
will mean that any broadcast you do on the associated socket will go out
only to the network to which that NIC belongs.

Luke

"Denville Longhurst" <Denville@xxxxxxxxxxx> wrote in message
news:fGuUf.6395$g76.4519@xxxxxxxxxxxxxxxxxxxxxxx
Hello

I use UDP broadcasts on a small network to synchronise applications and
share info - all without problems, lon-term stable.

I broadcast the info on specific UDP ports:

SockAddr.sin_addr.s_addr = htonl(INADDR_BROADCAST) ;
SockAddr.sin_port = htons( (unsigned short)nPort ) ;
SockAddr.sin_family = AF_INET ;
Socket = socket( AF_INET, SOCK_DGRAM, 0 ) ;

status = setsockopt( Socket, SOL_SOCKET, SO_BROADCAST,
(char *)&enable, sizeof(enable) ) ;

....

nSent = sendto( Socket, msg, len, 0,
(LPSOCKADDR)&SockAddr, sizeof(SockAddr) ) ;

And I receive broadcasts thus:

SockAddr.sin_port = htons( (unsigned short)nPort ) ;
SockAddr.sin_family = AF_INET ;
SockAddr.sin_addr.s_addr = htonl(INADDR_ANY) ; // binds to all ip's
(multiple receipts if multiple IP's !)
Socket = socket( AF_INET, SOCK_DGRAM, 0 ) ;

status = bind( Socket, (LPSOCKADDR)&SockAddr, sizeof(SockAddr) ) ;

n = recvfrom( Socket, buf, max, 0, &sAddr, &nsAddr ) ;

Now, I have to use a couple of PC's that have two physical network cards.
One network is our small network as usual; the other is big and unknown
(completely different sub-net of course). So, question is:

How do I ensure that 'my' UDP sends on, and receives on, only our network
interface, and neither broadcasts nor listens on t'other ? The system
should configure automatically as far as possible with the minimal amount of
network-specific information, just enough to discriminate generaly between
the two and then to detect and use 'our' interface.

Many thanks in advance,

Denville.









.



Relevant Pages

  • Re: UDP broadcast with 2 adapters
    ... Microsoft MVP, MCSD ... I broadcast the info on specific UDP ports: ... And I receive broadcasts thus: ... I have to use a couple of PC's that have two physical network cards. ...
    (microsoft.public.win32.programmer.networks)
  • Re: UDP multicast componet
    ... When fighting with broadcasts on 1GB network with my protocol, I had to configure network adapter to stall switch ... This was to prevent data loss. ... Do not length of complete packed added with UDP headers to exceed 1536 bytes or that you have set. ...
    (microsoft.public.windowsxp.embedded)
  • Re: BIND 9 on a dynamic ip address
    ... Andrew P. wrote: ... All I am looking to do is to use bind for hosts in my network ... configuring a DNS server ...
    (freebsd-questions)
  • Re: IBM TV network--a history twist
    ... > Why do you assume the TV broadcasts would have been available to the ... Note that AT&T developed radio equipment for use in the telephone ... It's entirely possible IBM would have developed an experimental TV ... station and network as a test bed for new technologies and ending up as ...
    (rec.arts.tv)
  • Re: Local DNS Caching not caching on external interface
    ... I am very new to Bind and FreeBSD. ... I have just configured a Local DNS server using the built-in Bind ... query the caching name server from my local network. ...
    (freebsd-questions)