csocketsipv6ipv4datagram

How to convert a multicast address string to in_addr or in_addr6


I'm writing a program where a datagram socket should be able to receive multicast datagrams. I already found out that before a host can receive IP multicast datagrams, the host must become a member of one, or more IP multicast groups with a setsockopt() call. The application should work for both IPv4 and IPv6.

The thing that i don't know is how to properly convert my IPv4/IPv6 multicast address string for example "ff14::60" into a in_addr or in_addr6 struct for the different setsockopt() calls.

I appreciate your help and suggestions!


Solution

  • The inet_pton() function can be used for this according to the manpage.