I'm developing a experimental Linux Kernel module, so...
How to UDP Broadcast from Linux Kernel?
-
Mm, I wish I had more time to help you out.
To get UDP multicasting to work, it has to be baked into your kernel. You have to enable it when you configure your kernel. Google should have more info; I hope this puts you on the right track.
Daniel Silveira : This is valid for both user and kernel spaces? I can broadcast in user space, but not in kernel space. -
-13 is -EACCES. Do you have SO_BROADCAST set? I believe sock_sendmsg returns -EACCES if SO_BROADCAST isn't set and you're sending to a broadcast address.
You're looking for <errno.h> for error codes.
What kernel version are you developing under? I'd like to browse thru the kernel source briefly. I'm not seeing how -ENOPKG can be returned from sock_set, but I do see that -ENOPROTOOPT can be returned (which is errno 92 in kernel 2.6.27).
Oh-- and repost that bit of code where you're setting SO_BROADCAST, if you would. I didn't make a note of it and I'd like to look at it again.
Try calling it with SOL_UDP. I think that's what you're looking for. I don't have a 2.6.18 build environment setup anywhere to play w/ this, but give that a shot.
No-- nevermind-- that's not going to do what you want. I should've read a little further in the source. I'll keep looking. This is kinda fun.
I suppose you could just set the broadcast flag yourself! smile
lock_sock(sock->sk); sock->sk->broadcast = 1; release_sock(sock->sk);
You've got me stumped, and I've got to head off to bed. I did find this bit of code that might be of some assistance, though these guys aren't doing broadcasts.
http://kernelnewbies.org/Simple_UDP_Server
Good luck-- I wish I could have solved it for you.
-
@adjuster..
Acctually, I just got it. When I'm setting
SO_BROADCAST, I'm receiving 92 (Package not installed)What package should I install, then?
Edit: The Kernel version is 2.6.18, and you are right! 92 is
ENOPROTOOPT//Socket creation sock_create(AF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock); //Broadcasting int broadcast = 1; int err; if( (err = sock->ops->setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&broadcast, sizeof broadcast)) < 0 ) { printk(KERN_ALERT MODULE_NAME ": Could not configure broadcast, error %d\n", err); return -1; }
Edit: I've got this from
setsockoptman page...ENOPROTOOPT
The option is unknown at the level indicated....so, I supose that
SOL_SOCKETisn't the right value to pass. I've also triedIPPROTO_UDPinstead ofSOL_SOCKETwith no luck.
Edit: http://docs.hp.com/en/32650-90372/ch02s10.html says that
SO_BROADCASTis an option of theSOL_SOCKETlevel, but I continue to get -92
Edit: I'm desperate, so I've tried
SOL_UDP, still -92.
Yes, it is fun :) ... Good synergy! At the end (I hope we get there soon) let's assembly a definitive answer clean and nice! :)
Edit: Even if a hard set the broadcast flag, the
sock_sendmsgwill fail (-13, "Permission denied")sock->sk->sk_flags |= SO_BROADCAST;I really need some help on this one..
-
Look at the IPVS (linux virtual server) code in the Linux kernel. It already has a working implementation of UDP multicast, which it uses to share connection state for failover.
Having already taken a look at this and knowing some people who have done this, I would really recomend creating a netfilter link and using a userspace daemon to broadcast the information over the network.
0 comments:
Post a Comment