ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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?
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.
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.
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
tags.
Hi there, sorry for the delay but see bellow the source code.
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)
{
int ReturnedStatus;
int handle = -1;
int BufferSize;
int VarLength = sizeof(BufferSize);
int x;
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(handle == -1)
return -1;
x=fcntl(handle,F_GETFL,0); // Get socket flags
fcntl(handle,F_SETFL,x | O_NONBLOCK); // Add non-blocking flag
memset(&ac5xServiceAddr, 0, sizeof(ac5xServiceAddr));
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));
if (ReturnedStatus == -1)
{
int yes = 1;
setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, sizeof(yes));
getsockopt(handle, SOL_SOCKET, SO_REUSEADDR, (char*)&yes, (socklen_t *)&VarLength);
ReturnedStatus = bind(handle, (struct sockaddr *)&(ac5xServiceAddr), sizeof(struct sockaddr_in));
}
if(ReturnedStatus == -1)
{
ReturnedStatus = close(handle);
return -1;
}
int on = (int)BroadCast;
setsockopt(handle, SOL_SOCKET, SO_BROADCAST, (char*)&on, sizeof(on));
getsockopt(handle, SOL_SOCKET, SO_BROADCAST, (char*)&on, (socklen_t *)&VarLength);
return handle;
}
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
tags.
My project is too complex to simulate in an small program the problems that I am getting (there's a complex process of client configurations prior of normal operation).
I will try to get this done but the core functions used are the ones posted.
Regards
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.