Re: Socket does not receive UDP packet with source address 255.255.255.255
- From: "Alexander Nickolov" <agnickolov@xxxxxxxx>
- Date: Fri, 22 Jul 2005 11:50:24 -0700
Most likely the packet is dropped as invalid/corrupt at the
UDP layer.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Ricardo Vazquez" <Ricardo Vazquez@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:BF9D4BCD-D555-4554-90BF-A04C283CA77F@xxxxxxxxxxxxxxxx
> My problem is that I want the socket (I've tried both with the MFC
> CAsyncSocket and with the SOCKET of the API) in my application to receive
> an
> UDP packet whose source address is 255.255.255.255.
> A sniffer application (Ethereal) shows that packet arrives to my machine
> but
> it does not trigger the CAsyncSocket::OnReceive event function on my
> program (MFC version), nor the recvfrom function (sockets API version).
> Somehow the system is not passing that packet to the application level,
> although it arrives to the correct port; apparently because of its
> extrange
> source address.
>
> It does not receive either if the source address of the packet was
> 192.168.0.255 (subnet mask 255.255.255.0)
>
> If the source address is any other (for example, 192.168.0.80) I receive
> the
> packet.
>
> Does anyone know what is happening? Any explanations?
> Is there any way to set the operating system or to set my socket so that
> it
> receives the packet?
>
> Thank you in advanced,
>
> Ricardo Vázquez.
> Madrid, Spain.
>
>
> Sockets API code below, just in case someone needs it to answer my
> question:
> -------------------------------------------------------------------
> int nRet;
> CString msg, err;
>
> // Create an UDP socket, set to send broadcast
> //
> if (!AfxSocketInit())
> {
> AfxMessageBox("Windows Sockets initialization failed.");
> return;
> }
>
> m_listenSocket = socket(AF_INET, SOCK_DGRAM, 0);
> if (m_listenSocket == INVALID_SOCKET)
> {
> err.Format("Could not create listen socket: %ld", WSAGetLastError());
> AfxMessageBox(msg);
> return;
> }
>
> int nVal = 1;
> nRet = setsockopt (m_listenSocket, SOL_SOCKET, SO_BROADCAST, (char*)&nVal,
> sizeof(nVal));
> if (nRet == SOCKET_ERROR)
> {
> err.Format("setsockopt(SO_BROADCAST) error: %ld", WSAGetLastError());
> AfxMessageBox(err);
> }
>
> // Bind our name to the socket
> //
> SOCKADDR_IN saServer;
> saServer.sin_addr.s_addr = INADDR_ANY;
> saServer.sin_port = htons(23000);
> saServer.sin_family = AF_INET;
>
> nRet = bind(m_listenSocket, (sockaddr*)&saServer, sizeof(saServer));
> if (nRet == SOCKET_ERROR)
> {
> err.Format("bind() error: %ld", WSAGetLastError());
> AfxMessageBox(msg);
> closesocket(m_listenSocket);
> return;
> }
>
> // Broadcast message
> //
> msg = "$(FF FF FF FF FF FF) MAC";
>
> SOCKADDR_IN saServer2;
> char szAdd [] = "192.168.0.255";
> saServer2.sin_addr.s_addr = inet_addr(szAdd);
> saServer2.sin_port = htons(23081);
> saServer2.sin_family = AF_INET;
>
> if (sendto (m_listenSocket, msg, msg.GetLength(), 0,
> (LPSOCKADDR)&saServer2,
> sizeof(struct sockaddr)) != msg.GetLength())
> {
> err.Format("sendto() error: %ld", WSAGetLastError());
> AfxMessageBox(msg);
> return;
> }
>
> // Receive (on port 23000)
> //
> char szBuffer [2048];
> int nBytesRead;
> struct sockaddr_in from;
> int fromlen = sizeof(from);
>
> nBytesRead = recvfrom(m_listenSocket, szBuffer, sizeof(szBuffer), 0,
> (struct
> sockaddr*)&from, &fromlen); // <-- program stops here forever: it never
> receives
>
> if (nBytesRead == SOCKET_ERROR)
> {
> err.Format("recvfrom() error: %ld", WSAGetLastError());
> AfxMessageBox(msg);
> return;
> }
>
> szBuffer[nBytesRead] = 0;
> AfxMessageBox(szBuffer);
>
.
- Follow-Ups:
- Re: Socket does not receive UDP packet with source address 255.255.255.255
- From: Alan J. McFarlane
- Re: Socket does not receive UDP packet with source address 255.255.255.255
- From: Arkady Frenkel
- Re: Socket does not receive UDP packet with source address 255.255.255.255
- References:
- Socket does not receive UDP packet with source address 255.255.255
- From: Ricardo Vazquez
- Socket does not receive UDP packet with source address 255.255.255
- Prev by Date: Re: Posting multiple acceptex and netstat
- Next by Date: Re: Handling Unknown Sockets in WSPSelect
- Previous by thread: Socket does not receive UDP packet with source address 255.255.255
- Next by thread: Re: Socket does not receive UDP packet with source address 255.255.255.255
- Index(es):
Relevant Pages
|