LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-22-2018, 07:58 AM   #1
Poison Nuke
Member
 
Registered: Aug 2012
Location: Germany
Posts: 41

Rep: Reputation: Disabled
receiving UDP with sock_recvmsg() in kernel results in "14 - bad address" error


Hello,

has someone an idea, why I get constantly an error 14? Sometimes (like every 100 UDP packets), there is no error and I can process the packet.

Regarding to another forum, the buffer might not be correct initialized, but I cant see why:


Code:
int ksocket_receive(struct socket* sock, struct sockaddr_in* addr, unsigned char* buf, int len) {
	struct msghdr msg;
	struct iovec iov;
	mm_segment_t oldfs;
	int size = 0;

	if (sock->sk == NULL) return 0;

	iov.iov_base = buf;
	iov.iov_len = len;


	msg.msg_flags = 0;
	msg.msg_name = addr;
	msg.msg_namelen = sizeof(struct sockaddr_in);
	msg.msg_control = NULL;
	msg.msg_controllen = 0;
	msg.msg_iter.iov = &iov;
	msg.msg_iter.count = len;
	msg.msg_iter.type = ITER_IOVEC;
	msg.msg_iter.nr_segs = 1;
	msg.msg_control = NULL;

	oldfs = get_fs();
	set_fs(KERNEL_DS);
	size = sock_recvmsg(sock, &msg, msg.msg_flags);
	set_fs(oldfs);

	return size;
}

int bufsize = 10;
unsigned char buf[bufsize + 1];
memset(&buf, 0, bufsize + 1);
size = ksocket_receive(kthread->sock, &kthread->addr, buf, bufsize);

can anyone point me in the right direction?
 
Old 06-22-2018, 02:13 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
errno value 14 is EFAULT.

Please check the manual page for recvmsg() to learn what it that return value can mean.
 
Old 06-22-2018, 05:56 PM   #3
Poison Nuke
Member
 
Registered: Aug 2012
Location: Germany
Posts: 41

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
errno value 14 is EFAULT.

Please check the manual page for recvmsg() to learn what it that return value can mean.

The answer to that is in the thread-title. Ok Ive only written implicitly that the buffer-pointer address is meant by that.

But as Iam asking, I do not know how that is possible. The buffer is initialized as array and set to zero with memset. I have double checked if any parameter is given as pointer or value and for me in looks like as there is everything fine. And as mentioned, the strange thing is, every 100 packets or so it is working.

So why is the buffer-pointer pointing to nowhere in 99% of the cases? Have I missed any star or ampersand ?
 
Old 07-27-2018, 03:49 AM   #4
Poison Nuke
Member
 
Registered: Aug 2012
Location: Germany
Posts: 41

Original Poster
Rep: Reputation: Disabled
so is this an bug in the kernel? If yes, is there any suitable workaround?
 
Old 07-29-2018, 05:59 PM   #5
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Nevermind ...

Last edited by crts; 08-02-2018 at 01:01 PM.
 
  


Reply



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
Usage of "-f" option of grep in a script results in "Permission Denied" error zaayu87 Linux - Newbie 3 07-25-2013 12:45 PM
wget returns "HTTP 200 OK" for bad symbolic address Sanford Stein Linux - General 3 10-06-2011 02:34 PM
"bad tty" & "file descriptor error" while building RPM on F13 gosssamer Linux - Software 7 12-28-2010 05:02 PM
rmmod results in "bad file descriptor" wpbgent Linux - Newbie 1 07-29-2008 09:57 AM
"/usr/tux/backup/login: Bad Address" dri95 Linux - Security 0 02-26-2002 07:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:42 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration