How to transfer UDP from Linux kernel?

I am developing an experimental Linux kernel module , so ...

How to broadcast UDP from Linux kernel?

+3
source share
5 answers

-13 - -EACCES. Do you have SO_BROADCAST installed? I believe sock_sendmsg returns -EACCES if SO_BROADCAST is not set and you send to the broadcast address.


You are looking for <errno.h> for error codes.


What kernel version are you developing? I would like to briefly review the source of the kernel. I do not see how -ENOPKG can be returned from sock_set, but I see that -ENOPROTOOPT can be returned (which is errno 92 in kernel 2.6.27).

Oh-- and repeat this bit of code in which you set SO_BROADCAST if you want. I did not notice this, and I would like to look at him again.


Try calling it with SOL_UDP. I think what you are looking for. I don’t have the 2.6.18 build environment setup anywhere to play with her, but give her a shot.

No, never think you're not going to do what you want. I should have read a little further in the source. I will continue to watch. It's fun.


I suppose you could just set the broadcast flag! smile

lock_sock(sock->sk); sock->sk->broadcast = 1; release_sock(sock->sk); 

You're stumping me and I need to go to bed. I found this piece of code that may be of some help, although these guys do not broadcast.

http://kernelnewbies.org/Simple_UDP_Server

Good luck. I wish I could solve it for you.

+3
source

@adjuster ..

In fact, I just got it. When I set SO_BROADCAST , I get 92 (package not installed)

Which package should I install, then?


Edit: kernel version 2.6.18, and you're right! 92 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 have this from the setsockopt man page ...

ENOPROTOOPT
The option is unknown at the specified level.

... therefore, I believe SOL_SOCKET not a valid value. I also tried IPPROTO_UDP instead of SOL_SOCKET with no luck.


Edit: http://docs.hp.com/en/32650-90372/ch02s10.html says that SO_BROADCAST is a SOL_SOCKET level SOL_SOCKET , but I keep getting -92


Edit: I'm desperate, so I tried SOL_UDP , another -92.
Yes, this is fun:) ... Good synergy! In the end (I hope we get there soon) let the assembly of the final answer be clean and enjoyable! :)


Edit: even if the broadcast flag is hard-set, sock_sendmsg will fail (-13, "Permission denied")

 sock->sk->sk_flags |= SO_BROADCAST; 

I really need help with this ...

+2
source

Um, I wish I had more time to help you.

In order to receive UDP multicast, it must be baked in your kernel. You must enable it when configuring the kernel. Google should have more information; Hope this puts you on the right track.

+1
source

Look at the IPVS (linux virtual server) code in the Linux kernel. It already has a working UDP multicast implementation that it uses to share connection status for fault tolerance.

Having already considered this and knowing some of the people who did this, I would really recommend creating a netfilter link and using a user daemon to transfer information over the network.

0
source

The following worked for me (so finally this thread could be closed).

 int yes = 1; sock_setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &yes, sizeof(yes)); sock->ops->connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr), 0); 

Here sock is the initialized socket of the structure, and addr should be struct sockaddr_in with the broadcast address in it.

0
source

All Articles