LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-12-2013, 08:01 AM   #1
mrjmrj
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Rep: Reputation: Disabled
"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);
}
thank you in advance.

Last edited by mrjmrj; 02-12-2013 at 12:48 PM.
 
Old 02-12-2013, 11:00 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
First of all, please place all code in code tags.

Second, is your select() timing out? You appear to be recv()ing whether or not you've seen FD_ISSET().
 
Old 02-12-2013, 12:57 PM   #3
mrjmrj
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
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.
 
Old 02-12-2013, 05:40 PM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
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:

Code:
strncpy((char*)sa.sll_card,"wanpipe1",sizeof(sa.sl l_card));
strncpy((char*)sa.sll_device,"w1g1",sizeof(sa.sll_ device));
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.
 
Old 02-13-2013, 05:29 AM   #5
mrjmrj
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
thank you for reply.
i changed the code to:

Code:
strcpy( sa.sll_device,"w1g1");
strcpy( sa.sll_card,"wanpipe1");
but it still does not work other definition are:

Code:
#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?
 
Old 02-13-2013, 07:27 AM   #6
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by mrjmrj View Post
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 View Post
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.
 
Old 02-20-2013, 07:43 AM   #7
mrjmrj
LQ Newbie
 
Registered: Feb 2013
Posts: 12

Original Poster
Rep: Reputation: Disabled
thank you JohnGraham
my problem is solved. it was hardware problem
 
Old 02-21-2013, 04:01 AM   #8
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 138Reputation: 138
Quote:
Originally Posted by mrjmrj View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"fatal IO error 11 (Resource temporarily unavailable) on X server" with two windows 10_GOTO_10 Linux - Software 0 08-05-2011 02:44 PM
Samba "mount error(11): Resource temporarily unavailable" RWallett Linux - Server 1 07-01-2010 01:00 PM
"FUTEX WAIT EAGAIN (Resource temporarily unavailable )" jungbg Linux - Newbie 1 12-22-2009 05:07 PM
Cifs "mount error 11 = Resource temporarily unavailable" humbletech99 Linux - Networking 1 09-26-2006 12:04 PM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration