* query about sending udp packets in kernel mode
@ 2001-02-16 12:26 aprasad
2001-02-16 15:44 ` Andi Kleen
2001-02-17 10:44 ` Olaf Titz
0 siblings, 2 replies; 3+ messages in thread
From: aprasad @ 2001-02-16 12:26 UTC (permalink / raw)
To: linux-kernel
Hi All,
I need to send udp packets in a kernel module. but i am unable to figure
out how to specify fill the struct msghdr to be used by the sendmsg handler
of the socket.
my skeleton is something like (by going through the kernel code:>)
struct socket *sock;
struct sockaddr_in sin;
struct msghdr msg;
sock_creat(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock);
sin.sin_family = AF_INET;
sin.sin_port = htons((unsigned short)serv_port);
sin.sin_addr.s_addr = htonl(INADDR_ANY); /*i am not sure about this*/
msg.msg_name = &sin;
msg.msglen = sizeof(struct sockaddr_in);
msg.msg_iov = iovec_containg the message;
msg.msg_iovlen = 1;
msg.msg_control = NULL;
msg.msg_controllen=0;
msg.msg_flags =0;
sock->ops->sendmsg(sock,&msg,count,0);
________________________________________________
i am getting EFAULT.
or can anybody suggest me how to fill the address field of sin_addr in
kernel of any known remote address(corresponding inet_addr) so that
sendto/send can be used.
Any pointers will be greatly appreciated.
Thanks,
Anil.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: query about sending udp packets in kernel mode
2001-02-16 12:26 query about sending udp packets in kernel mode aprasad
@ 2001-02-16 15:44 ` Andi Kleen
2001-02-17 10:44 ` Olaf Titz
1 sibling, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2001-02-16 15:44 UTC (permalink / raw)
To: aprasad; +Cc: linux-kernel
aprasad@in.ibm.com writes:
> i am getting EFAULT.
Use
mm_segment_t oldseg = get_fs();
set_fs(KERNEL_DS);
... sendmsg
set_fs(oldseg);
-Andi
P.S.: This is really getting a FAQ. If it isn't already please someone add
it to the linux-kernel FAQ.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: query about sending udp packets in kernel mode
2001-02-16 12:26 query about sending udp packets in kernel mode aprasad
2001-02-16 15:44 ` Andi Kleen
@ 2001-02-17 10:44 ` Olaf Titz
1 sibling, 0 replies; 3+ messages in thread
From: Olaf Titz @ 2001-02-17 10:44 UTC (permalink / raw)
To: linux-kernel
> sock_creat(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock);
> sin.sin_family = AF_INET;
> sin.sin_port = htons((unsigned short)serv_port);
> sin.sin_addr.s_addr = htonl(INADDR_ANY); /*i am not sure about this*/
Needs the target IP address here.
> msg.msg_name = &sin;
> msg.msglen = sizeof(struct sockaddr_in);
> msg.msg_iov = iovec_containg the message;
> msg.msg_iovlen = 1;
> msg.msg_control = NULL;
> msg.msg_controllen=0;
> msg.msg_flags =0;
{ mm_segment_t fs=get_fs();
set_fs(get_ds());
> sock->ops->sendmsg(sock,&msg,count,0);
set_fs(fs); }
"count" needs to be the total length of the message. The 0 is
redundant, sendmsg() takes only three arguments since Linux 2.1 (five
under 2.0).
Olaf
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-02-17 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-16 12:26 query about sending udp packets in kernel mode aprasad
2001-02-16 15:44 ` Andi Kleen
2001-02-17 10:44 ` Olaf Titz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®