sock_recvmsg() doesnt work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,

i just wrote a kernel module which sends some data to a server. after the
server has received the data it sends back some data to the kernel module.
sending data from the module to the server works! but i cant get the
response sent by the server.
for receiving data within my kernel module i use the sock_recvmsg
function. the return value is always 0. does anybody know how i have
exactly to use this function so that i can receive any data within my
kernel module

here is my Send_Msg function within my Kernel Module:


int Send_Msg(const char *buffer)
{
	struct msghdr   send_msg;
	struct msghdr   recv_msg;
	struct iovec 	iov;
	struct timeval now1;
	mm_segment_t oldfs;
	int error,i,len,lat;
	char recv_buf[1024];
	int j = 0;


	iov.iov_base=(void *)buffer;
	iov.iov_len=strlen(buffer);
	printk("<1>Size of Buffer in Send_Msg: %d\n", sizeof(buffer));

	send_msg.msg_name=NULL;
	send_msg.msg_namelen=0; //sizeof(server);
	send_msg.msg_iov=&iov;
	send_msg.msg_iovlen=1;
	send_msg.msg_control=NULL;
	send_msg.msg_controllen=0;
	send_msg.msg_flags = 0;

	do_gettimeofday(&now1);

	oldfs = get_fs(); set_fs(KERNEL_DS);
	error = sock_sendmsg(Socket[0], &send_msg, (size_t)buffer);
	set_fs(oldfs);

	iov.iov_base=(void *)recv_buf;
	iov.iov_len=sizeof(recv_buf);

	recv_msg.msg_name=NULL;
	recv_msg.msg_namelen=0; //sizeof(server);
	recv_msg.msg_iov=&iov;
	recv_msg.msg_iovlen=1;
	recv_msg.msg_control=NULL;
	recv_msg.msg_controllen=0;
	recv_msg.msg_flags = 0;

	udelay(1000);


	oldfs = get_fs(); set_fs(KERNEL_DS);
	len = sock_recvmsg(Socket[0], &recv_msg, (size_t)recv_buf, MSG_WAITALL);
	set_fs(oldfs);

	if (len<0)
		printk(KERN_ALERT "ERRO receive ########\n");

	if (error<0)
	 	printk(KERN_ALERT "Erro send msg ERRO = %d buffer=%s\n",error,buffer);

	printk("<1>recieved bytes: %d\n", len);


        	sock_release(Socket[0]);
        	return 0;
}


the sock_sendmsg works fine, but the sock_recvmsg() always seems to fail!!!
Any help out there???


greetings
benny

-- 




--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux