Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to open and set options for socket. I am getting "protocol error" for the setsockopt() function. I did not include the libraries here.
All functions above the setsockopt, return 0.
Any help will be appreciated.
For what it's worth, I did stage this program and see the EXACT same problem you're seeing. I searched a bit for information or examples related to multicast. I don't see what's wrong. I did feel that you ought to have looked at your interim results from socket(), setsockopt(), and so forth.
The other comments are when you perform the setsockopt() for IP_ADD_MEMBERSHIP, you do that twice, I'm guessing because you added debug via copy/paste. Either case, keep the second iteration of it and remove the first one.
Next, in the line where you set up mreg.imr_multiaddr.s_addr I think you need to use addr and perform a memcpy of the structure:
Code:
memset(&addr, 0, sizeof(addr)); /* fill memory with 0*/
addr.sin_family=AF_INET;
addr.sin_port=htons(MCAST_PORT);
addr.sin_addr.s_addr=MCAST_GROUP;
memcpy(&mreq.imr_multiaddr.s_addr, &addr, sizeof(struct in_addr));
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
However this doesn't work either. My editing of your code ended up getting the same errno you're seeing.
Maybe search for some examples of multicast out there in code and copy exactly to see if they work first and then edit them to match what you specifically want.
Here's my total effort, sorry I was not able to find a resolution either.
In the future, it's more helpful if you use [code][/code] tags to put in code, it retains the format and allows for better cut/paste. Further, adding the includes and your entire file is helpful so that other programmers won't have to search for the thread of needed include files. There's a link in my signature to describe how to do that.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.