sendto returns ENOTBLK error
Hi all,
I have a socket for each client to receive UDP packets from the clients and then send it to a SIP server. I receive the packets from the clients correctly without any errors. I then use the same socket for sending USP packets back to the clients but when I try to send a packet through the socket, a call to sendto returns an error with code 15 which corresponds to ENOTBLK. I cannot relate this error code to any problem regarding sockets. Does anyone have a hint about what may be the problem? Thanks in advance, Antonio |
Errors are generally easier to diagnose if one has the benefit of seeing the code that is causing the error. Therefore, could you please post the code where you are performing the sendto(), including the declarations and setup of variables that hold the data that is being sent?
P.S. Perhaps you are using the incorrect descriptor for the socket? |
You mean 'sendto' returned 15?
|
Hi, yes sendto return 15.
|
Hi all, an small correction to my previous post:
sendto returns -1, and consulting errno gives me the error code 15: ENOTBLK I have not provided the code because it does not have anything particular. The main issue is that sendto should not return this error!!! Regarding source code: This is how the socket is opened: handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if(handle == -1) return(ERROR); x=fcntl(handle,F_GETFL,0); // Get socket flags fcntl(handle,F_SETFL,x | O_NONBLOCK); // Add non-blocking flag ac5xServiceAddr.sin_family = AF_INET; ac5xServiceAddr.sin_addr.s_addr = htonl(INADDR_ANY); ac5xServiceAddr.sin_port = htons(SourcePort); ReturnedStatus = bind(handle, (struct sockaddr *)&(ac5xServiceAddr), sizeof(struct sockaddr_in)); and this is how data is sent: BytesSent = sendto(handle, pPacket, Size, 0, (struct sockaddr*)ac5xServiceAddr, sizeof(struct sockaddr_in)); if (BytesSent==-1) { errorNum = errno; printf("error=0x%08X", errorNum); } and this is how data is received: struct sockaddr_in SocketAddr; int SocketAddrSize; pPacketSize = recvfrom(handle, pPacketBuffer, MAX_SIZE, 0, (struct sockaddr*)&SocketAddr, (socklen_t *)&SocketAddrSize); I have a thread that is continuosly (with some usleep) checking data received and another thread that send data onto the same socket. I can receive packets but I cannot send packets through this socket. Regards |
Try this to switch to non-blocking mode:
Code:
int optval= 1; |
Quote:
|
Quote:
Code:
BytesSent = sendto(handle, pPacket, Size, 0, (struct sockaddr*)&SocketAddr, sizeof(struct sockaddr_in)); |
Hi, the client is the same that sent the packet received by the server.
I have tried to change the address to a different client (ADDR1) in order to route the packet to another client but the result is the same. I have created a mirror socket to send the same packet to another address(ADDR1), and in this case I can send the packet without any problem. I believe it is something related of how the socket is created. Regards PS: I made a mistake, in fact in my code I have: BytesSent = sendto(handle, pPacket, Size, 0, (struct sockaddr*)&SocketAddr, sizeof(struct sockaddr_in)); |
Okay, now leave out everything from your code that is not essential in reproducing the problem, and past in the rest. But do use [code] and [/code] tags.
|
Quote:
Regards |
Which part of my suggestion is problematic? Okay, I'll rephrase it:
Okay, now leave out everything from your code that is not essential in reproducing the problem, until you get a complete and working minimal-program that shows the problem. Then paste it in, but do use [code] and [/code] tags. |
Quote:
I've been finding some particularities: 1. I have besides this socket, an management socket, created in this manner but it is only opened once and sends and receives packets without any problem. 2. This socket that experiences this problem is opened and closed several times (for reconfiguration purposes). 3. I have created a mirror socket which sends every data the server sends to the clients to my PC. This socket works great but it is opened like a client (OpenRecordingSocket). Which condition(s) may originate the error I am getting, ENOTBLK? Open Socket Code:
int OpenServerSocket(int SourcePort, U8 BroadCast) Code:
int ReceiveMiiPacket(int socketHandle, char* pPacketBuffer, int* pPacketSize) Send Packet Code:
int SendMiiPacket(int socketHandle, char* pPacket, int Size) Code:
int OpenRecordingSocket(void) |
Quote:
Regards |
Quote:
I will try to get this done but the core functions used are the ones posted. Regards |
All times are GMT -5. The time now is 06:44 AM. |