A
August
The intention is to listen the packets from certain port,
port 1900, which is pre-defined UPnP V1 port. The packets
may come from a multicast group, or may come from a
certain device using unicast.
To do this, first, I creat a socket, set it as reuseable,
and then bind it to that port:
sockfd = socket( AF_INET, SOCK_DGRAM, 0)
setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, ...)
SOCKADDR_IN sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(1900); // UPnP V1 port
bind(sockfd, (LPSOCKADDR)&sin, sizeof (sin))
Then join the multicast group:
ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr( MULTICAST_ADDR );
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt( sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)
&mreq, sizeof(mreq));
I did error checking for each step, and there is no error
in between. Then call recvfrom(...).
In Win2000, both unicast packets and multicast packets can
be received after binding and after joining the multicast
group;
In WinXP, once joining the multicast group, the unicast
packets will be lost, but if it's "after binding and
before joining the multicast group", unicast packets and
multicast packets can be received.
Does anyone have any idea about the reason?
Thanks for your attention in advance!
port 1900, which is pre-defined UPnP V1 port. The packets
may come from a multicast group, or may come from a
certain device using unicast.
To do this, first, I creat a socket, set it as reuseable,
and then bind it to that port:
sockfd = socket( AF_INET, SOCK_DGRAM, 0)
setsockopt( sockfd, SOL_SOCKET, SO_REUSEADDR, ...)
SOCKADDR_IN sin;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(1900); // UPnP V1 port
bind(sockfd, (LPSOCKADDR)&sin, sizeof (sin))
Then join the multicast group:
ip_mreq mreq;
mreq.imr_multiaddr.s_addr = inet_addr( MULTICAST_ADDR );
mreq.imr_interface.s_addr = INADDR_ANY;
setsockopt( sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)
&mreq, sizeof(mreq));
I did error checking for each step, and there is no error
in between. Then call recvfrom(...).
In Win2000, both unicast packets and multicast packets can
be received after binding and after joining the multicast
group;
In WinXP, once joining the multicast group, the unicast
packets will be lost, but if it's "after binding and
before joining the multicast group", unicast packets and
multicast packets can be received.
Does anyone have any idea about the reason?
Thanks for your attention in advance!