Network programming

Hi,
I`m trying to do some multicast programming, and i`m looking for a C-function to convert an Interfacename to an IP-address or/and a C-function to convert an Interfaceindex to an IP-address.

I need it for the mcast_set_if(int sockfd, const char *ifname (!), u_int ifindex(!)) function by STEVENS.

Perhaps I'm wrong, but I think the INTERFACENAME is something like eth0 ??!!??!?!?
And what is the index, is there kind of table for each system/ computer ???

        like:   loopback  --> 0
                 eth0         --> 1

and so on.

Thanks for the help! :wink:

Hi,

  I have some hint for you. You have a C function called the gethostbyname and gethostbyaddr. I think this should solve your problem. else you can also try "resolver", but i guess "resolver" is linux specific.

regards
penguin

Even easier than getpeername() is the function gethostname(). It returns the name of the computer that your program is running on. The name can then be used by gethostbyname(), to determine the IP address of your local machine.

#include <unistd.h>

int gethostname(char *hostname, size_t size);

The arguments are simple: hostname is a pointer to an array of chars that will contain the hostname upon the function's return, and size is the length in bytes of the hostname array.

The function returns 0 on successful completion, and -1 on error, setting errno as usual.