c++network-programmingmulticast

Error received when passing in &mreq argument into setsockopt method


I want to add a socket to a group which receives data from the network host. The page http://www.tldp.org/HOWTO/Multicast-HOWTO-6.html explain clearly well how the socket option IP_ADD_MEMBERSHIP and the ip_mreq data structure are used to acquire this. So I create my ip_mreq data structure(I call my instance mreq) and fill in both of its properties imr_multiaddr and imr_interface, but when I pass the value &mreq into the optval parameter, I get the error:

Error: Argument of type 'ip_mreq *' is incompatible with parameter of type 'const char *'

But why does that parameter require 'const char *', when the guide I'm following states that the parameter should be of type 'cont void *'. Before this issue I had a problem with the ip_mreq data structure not being defined, but I solved that by importing the Ws2ipdef header library. I think the issue may be that I imported the wrong library or I may need to import an additional library.

Also I am coding my solution in C++ using visual basics.

Thank you


Solution

  • But why does that parameter require 'const char *', when the guide I'm following states that the parameter should be of type 'const void *'?

    Because setsockopt() is used for dozens of socket options besides IP_ADD_MEMBERSHIP.

    You have to cast.

    NB Arbitrary Internet resources are not normative references.