[SOLVED] "resource temporarily unavailable" in recv in socket programming
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.
"resource temporarily unavailable" in recv in socket programming
I want to read and write over Wanpipe driver (a network device driver for Sangoma cards) via socket programming but i get this message error: "resource temporarily unavailable". The card is working and i see it send and receive packets in ifconfig. I have included my code and would be very pleased if somebody help me in this.
A related question: I set the socket to blocking mode but the recv message does not block? how could i block the recv?
Code:
int main(void)
{
int sd;
int buflen=WP_HEADER + MAX_PACKET;
char buf[buflen];
struct wan_sockaddr_ll sa;
sd = socket(AF_WANPIPE, SOCK_RAW,0);
if (sd < 0) /* if socket failed to initialize, exit */
{
perror("Error Creating Socket");
exit(1);
}
printf("Socket Descriptor:%d\n",sd);
memset(&sa,0,sizeof(struct wan_sockaddr_ll));
strncpy((char*)sa.sll_card,"wanpipe1",sizeof(sa.sl l_card));
strncpy((char*)sa.sll_device,"w1g1",sizeof(sa.sll_ device));
sa.sll_protocol = htons(PVC_PROT);
sa.sll_family = AF_WANPIPE;
if(bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0)
{
perror("error bind failed");
close(sd);
exit(1);
}
int data=0;
int ret=ioctl(sd,FIONBIO,&data);
if (ret < 0) {
perror("ioctl error!");
close(sd);
return 1;
}
fd_set read_fds;
struct timeval timeout;
timeout.tv_sec = 10;
timeout.tv_usec = 0;
FD_ZERO(&read_fds);
FD_SET(sd,&read_fds);
if(select(sd+1, &read_fds, NULL, NULL, &timeout) < 0)
{
perror("select() error!");
exit(1);
}
if (FD_ISSET(sd,&read_fds))
printf("There is data for reading\n");
else
printf("There is no data for reading\n");
// MSG_WAITALL | MSG_PEEK | MSG_OOB
int r=recv(sd,buf,buflen,0);
if (r < 0) {
perror("Wanpipe raw socket reading");
close(sd);
exit(1);
}
printf("\nNumber of bytes read into the buffer: %d",r);
printf("\nThe read buffer: ");
puts(buf);
close(sd);
}
select() is timing out and the else message ("There is no data for reading\n") is in the output. then for recv i have "resource temporarily unavailable". if i put recv under [if (FD_ISSET(sd,&read_fds))] it is not called. In other words both select() and recv() indicate that there is no data! but as I said my card is receiving and sending. ifconfig shows there are transmitted and received packets. I do not know the problem is because of my code (select or recv) or from the card.
First, I don't know anything about the AF_WANPIPE protocol, so I could be off on this. Your problem may be what you're bind()ing to. About these two lines:
What are sizeof(sa.sll_card) and sizeof(sa.sll_device) (Check by printf()ing these sizes) and are they definitely char buffers, not pointers (I suspect so, but I'd check)? Also, is there definitely space to write all of the card/device strings in there with a null-terminator? (Remember strncpy() won't append one if there isn't enough space).
Also, do you realy need to htons(PVC_PROT), or do you just want PVC_PROT? And is it definitely htons(), not htonl() you want?
If all else fails, could you post the definition of the wan_sockaddr_ll struct? I can't seem to find it on my computer.
#define PVC_PROT 0x17
#define AF_WANPIPE 25
struct wan_sockaddr_ll
{
unsigned short sll_family;
unsigned short sll_protocol;
int sll_ifindex;
unsigned short sll_hatype;
unsigned char sll_pkttype;
unsigned char sll_halen;
unsigned char sll_addr[8];
unsigned char sll_device[14];
unsigned char sll_card[14];
unsigned int sll_active_ch;
unsigned char sll_prot;
unsigned char sll_prot_opt;
unsigned short sll_mult_cnt;
unsigned char sll_seven_bit_hdlc;
};
i am using a new address family (AF_WANPIPE). maybe i should include some headers files or sth else. do you think so?
in addition bind() does not return error. Does that mean the binding is ok?
maybe i should include some headers files or sth else. do you think so?
Do you get any errors or warnings when you compile? I mean any errors or warnings - pass the -Wall and -Wextra flags to gcc if you're not already, then fix any warnings and retry.
Quote:
Originally Posted by mrjmrj
in addition bind() does not return error. Does that mean the binding is ok?
That means it's bound to *something* - I suspect it's just not the right thing. Try removing the htons() around the PVC_PROT, this may not need to be in network byte order (after all, sa_family doesn't need to be).
How certain are you that the packets you expect are arriving? How are you looking at them? If the above two points don't work, try and get a Wireshark/tcpdump trace that shows the packets you expect to see and post it, along with which specific packets you want to see.
thank you JohnGraham
my problem is solved. it was hardware problem
Glad to hear it. Please mark the thread as solved so other people know without reading through the whole thread - there should be a link just above the first post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.