Re: wanted: sosend() howto
Re: wanted: sosend() howto
- Subject: Re: wanted: sosend() howto
- From: Hiroo Yamada <email@hidden>
- Date: Sat, 20 Sep 2003 21:00:02 +0900
- Organization: Active Open Communications K.K
Hi Stefan,
It's not so difficult to send UDP packets in a kernel.
Here is brief function calls.
function read/write tcp/udp in darwin kernel
{
thread_funnel_switch KERNEL_FUNNEL,NETWORK_FUNNEL
so=socreate AF_INET // create socket
soreserve so,1536,1536 // set max packet size
setup sockaddr_in sa (s_addr=dest. ip address or INADDR_BROADCAST)
if (udp)
sosetopt SOL_SOCKET,SO_BROADCAST,on // turn on broadcast option
else // tcp
{
soconnect so,&sa
check so_create !SS_ISCONNECTING // check connection state
}
setup uio UIO_SYSSPACE,UIO_WRITE
if (send)
sosend so,&sa,&uio,NULL,NULL,0 // send tcp/udp
else // receive
{
setup sockopt sopt SOL_SOCKET,SO_NREAD
sogetopt so,&sopt
if (sopt.sopt_val != 0) // check data available
soreceive so,NULL,&uio,NULL,NULL,&flag // receive tcp/udp
}
soclose so
thread_funnel_switch NETWORK_FUNNEL,KERNEL_FUNNEL
}
You can find udp samples by searching keyword 'SO_BROADCAST'.
Hope this helps.
hiroo / Hiroo Yamada / Active Open Communications K.K
--
>
Hi,
>
>
I want to send UDP packets from kernel space and am currently
>
struggling with the sosocket() call. It appears to be close to
>
undocumented and almost an hour of research on google did not turn up
>
much. I'd be very happy if I could get a simple code snippet that will
>
allow me to send a void* buffer (I haven't figured out how to use mbuf
>
yet) to a remote IP/Port. I found a little code in the nfs source code,
>
but I couldn't quite figure out where exactly the payload is and what
>
the other values mean.
>
>
Thanks a lot,
>
Stefan
--
Hiroo Yamada / JK1ASL ._ ... ._.. Internet: email@hidden
Active Open Communications K.K _._ NIFTY-Serve: SDI00177
http://www.activeopen.co.jp/ email@hidden
_______________________________________________
darwin-kernel mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/darwin-kernel
Do not post admin requests to the list. They will be ignored.