Hi,

i need to get MAC Address IP Address for IPv6 with C Programming for 
OpenSolaris.

I found the following code:

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
 
main(int argc,char *argv)
{
    unsigned char eth_addr[6];
    int i,j,sock;
    unsigned char *p;
    struct lifconf lic;
    struct lifreq lifrs[30];
    struct lifnum num;
    struct arpreq ar;
    struct sockaddr_in *soap,*soap2;
    
    /* Enumerate all IP addresses of the system */
    sock=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
    num.lifn_family=AF_INET;
    num.lifn_flags=0;
    ioctl(sock,SIOCGLIFNUM,&num);
    lic.lifc_family=AF_INET;
    lic.lifc_flags=0;
    lic.lifc_len=sizeof(lifrs);
    lic.lifc_buf=(caddr_t)&(lifrs[0] );
    ioctl(sock,SIOCGLIFCONF,&lic);
 
    /* Get the ethernet address for each of them */
    for(i=0;i<num.lifn_count;i++)
    {
        /* Get IP address */
        ioctl(sock,SIOCGLIFADDR,&(lifrs[ i ]));
        soap=(struct sockaddr_in *)&(lifrs[ i ].lifr_addr);
        soap2=(struct sockaddr_in *)&(ar.arp_pa);
        *soap2=*soap;
 
        /* Print IP address */
        p=(unsigned char *)&(soap->sin_addr);
        printf("%s: %u.%u.%u.%u - ",lifrs[ i ].lifr_name,
            p[0],p[1],p[2],p[3]);
        
        /* Get ethernet address */
        if(ioctl(sock,SIOCGARP,&ar)<0)
        {
            printf("No ethernet address.\n");
        }
        else
        {
            p=(unsigned char *)&(ar.arp_ha.sa_data);
            printf("%02X:%02X:%02X:%02X:%02X:%02X\n",
                p[0],p[1],p[2],p[3],p[4],p[5]);
        }
    }
 
    close(sock);
}



But this work only for IPv4. I changed Addressfamily and structures to IPv6, 
but it does not work.
Can anybody help me to get a list of Interfaces with corresponding Mac-Adress 
and all IP Adresses(IPv4 and IPv6).
On Linux i can use getifaddr but it does not exists on Solaris.

Thanks in advance
-- 
This message posted from opensolaris.org
_______________________________________________
opensolaris-code mailing list
opensolaris-code@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to