Hi all,

I'm trying to join a UDP multicast group in my kernel module - using standad sockets.

Here's how:

/* UDP */
struct socket *udp_socket = NULL;
struct sockaddr_in udp_bind_addr;
struct ip_mreq udp_multicast_req;

if (sock_create(AF_INET, SOCK_DGRAM, 0, &udp_socket) < 0)
printk(KERN_ERR "(/proc/%s): Failed to create UDP socket!\n", PROCFS_NAME);
goto exit2;

udp_bind_addr.sin_family = AF_INET;
udp_bind_addr.sin_port = htons(UDP_PORT);
udp_bind_addr.sin_addr.s_addr = htonl((uint32_t)LOCAL_IP);
memset(&(udp_bind_addr.sin_zero), 0, ;
if (udp_socket->ops->bind(udp_socket, (struct sockaddr*)&udp_bind_addr, sizeof(struct sockaddr)) < 0)
printk(KERN_ERR "(/proc/%s): Failed to bind UDP socket!\n", PROCFS_NAME);
goto exit1;

udp_multicast_req.imr_interface.s_addr = htonl((uint32_t)LOCAL_IP);
udp_multicast_req.imr_multiaddr.s_addr = htonl((uint32_t)UDP_MULTICAST_IP);
if ((ret_val = udp_socket->ops->setsockopt(udp_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&udp_multicast_req, sizeof(udp_multicast_req))) < 0)
printk(KERN_ERR "(/proc/%s): Failed to join UDP multicast group %d!\n", PROCFS_NAME, ret_val);
goto exit1;

Everything seems fine, up to the point where I use setsockopt to ADD_MEMBERSHIP to the multicast group - I get an EFAULT error.

I've used many times the UDP multicast join socket option in user-space and it worked great - but somehow, in kernel space I seem to be missing something...

Please help,