Note that there are some explanatory texts on larger screens.

plurals
  1. POUDP Socket receive Garbage Value
    primarykey
    data
    text
    <p>System Configuration: Win XP (i7 2.1 Ghz) External USB NIC. Communication : Master slave communication. Constrain - Communication Protocol UDP.</p> <p>Socket Configuration: RecvFrom - Non blocking. Socket size changed to 1*1024*1024 using setsockopt.</p> <p>My setup consist of a node communicating with the master over UDP, it send fragmented data in the Payload of the UDP frame. This fragmented data consist of 5 framents per Ethernet frame. The slave node sends 1270 bytes of fragmented data to the master. Slaves send 18 - 20 Frames in less than 2 Milliseconds.</p> <p>The master receives this frames periodically without dropping them. However randomly the payload data from the UDP frame, containing 2 correct fragments and rest of the 3 fragemts are garbage value. I observed the trace on wireshark there in the smae fragment correct data can be observed, but some how the recvfrom API collects garbage data in these 3 fragements. It seems some how the actually information is replaced by this garbage value. and this behaviour drops when i reduce the numbeer of packets to 2 - 3 per 2 msec.</p> <p>Trace from the console:</p> <pre><code>_recvBuf[2]: 0x5b _recvBuf[256}: 0x5c _recvBuf[510]: 0x5d _recvBuf[764}: 0x5e _recvBuf[1018}: 0x5f _recvBuf[2]: 0x60 _recvBuf[256}: 0x61 _recvBuf[510]: 0x64 _recvBuf[764}: 0x0 _recvBuf[1018}: 0x0 Expected and as in the Wireshark trace: _recvBuf[510]: 0x64 --&gt; should be _recvBuf[510]: 0x62 _recvBuf[764}: 0x0 --&gt; should be _recvBuf[510]: 0x63 _recvBuf[1018}: 0x0 --&gt; should be _recvBuf[510]: 0x64 </code></pre> <p>and garbage value offently repeats to 0xcd, for random packet number.</p> <p>!!! Packet 200 - Error !!! Packet 20000 - Error !!! Packet 60000 - Error !!! Packet 2 - Error</p> <p>i am not able to understand why is this behaviour.</p> <p>code:</p> <pre><code>receive() { rc = select(_sock_fd+1, &amp;read_fd, &amp;write_fd, &amp;excep_fd, &amp;to); if (rc == 0 ) acess = 1; else if (rc == SOCKET_ERROR) { closesocket(_sock_fd); return -1; } else { if (!FD_ISSET(_sock_fd, &amp;read_fd)) { LogError("XCP: select() wrong socket descr"); return -1; } else { rc = recvfrom(_sock_fd, (char *)_recvBuf, UDP_RECVBUFLEN, 0, (LPSOCKADDR)&amp;_saddr, &amp;cli_alen); printf("_recvBuf[3]: 0x%x _recvBuf[2]: 0x%x _recvBuf[256}: 0x%x _recvBuf[510]: 0x%x _recvBuf[764}: 0x%x _recvBuf[1018}: 0x%x\n",_recvBuf[3],_recvBuf[2],_recvBuf[256],_recvBuf[510],_recvBuf[764],_recvBuf[1018]); _recvBuf[*(&amp;rc)]='\0'; if(rc == SOCKET_ERROR) { closesocket(_sock_fd); return -1; } _recvBufLen = rc; if (_recvBufLen &gt; 0) { int rc = 0; acess = 0; if (_rxNotification != NULL) _rxNotification(_parent, _xhdl, _recvBuf, _recvBufLen); RxbufferLen=*(u16*)&amp;_recvBufLen; /* Proto RX Queue Implementation Start */ if(!(Fullqueue(Rxbufferqueue))) Enqueue(Rxbufferqueue,_recvBuf); if(_recvBuf[4]==0xff) acess = 1; else acess = 0; return rc; } else return 0; } } </code></pre> <p>Additional information about the functions:</p> <pre><code>void XcpTransportUdp::Enqueue (Queuetype &amp;queue, unsigned char buf[MAX_BUFFER_SIZE_QUEUE],u16 _recvBufLen) // Push Function for Queue { Rxbufferqueue.BackPointer=(Rxbufferqueue.BackPointer+1)%MAX_BUFFER_IN_QUEUE; Rxbufferqueue.Recv_length[Rxbufferqueue.BackPointer]=_recvBufLen; memcpy(Rxbufferqueue.Buffer[Rxbufferqueue.BackPointer],buf,Rxbufferqueue.Recv_length[Rxbufferqueue.BackPointer]); } u16 XcpTransportUdp::Dequeue (Queuetype &amp;queue, unsigned char Output_buffer[MAX_BUFFER_SIZE_QUEUE]) // Pop Function for Queue { Rxbufferqueue.Frontpointer =(Rxbufferqueue.Frontpointer+1)%MAX_BUFFER_IN_QUEUE; BufLen=Rxbufferqueue.Recv_length[Rxbufferqueue.Frontpointer]; memcpy(Output_buffer,Rxbufferqueue.Buffer[Rxbufferqueue.Frontpointer],Rxbufferqueue.Recv_length[Rxbufferqueue.Frontpointer]); return BufLen; } </code></pre> <p>:::Edir1::: i found the error has to do with the memory initialization and not the with the sockets. the memcpy function in the enqueue function reports the error of the length being 0cCD. do any one know the solution for this issue..?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload