How can I get CPU id and MAC address under QNX 6.5 in my C p

Hi:
I want to get the CPU id and MAC address in my c program, but I don’t know which API to use under QNX6.5.

Could you give me some information about this? thanks

Hi,

Concerning MAC address (and other net information), you can get it with the following piece of code :

void            ShowIpAddresses (void)
{
    struct ifaddrs * ifAddrStruct;
    struct ifaddrs * ifa;


    ifAddrStruct = NULL;
    getifaddrs(&ifAddrStruct);

    ifa = ifAddrStruct;
    while (ifa != NULL)
    {
        if (ifa->ifa_addr)
        {
            if (ifa->ifa_addr->sa_family == AF_INET)    // IPV4 ?
            {   // Is a valid IPV4 Address
                struct sockaddr_in *pAddr;
                struct sockaddr_in *pNetmask;
                char addressBuffer[INET_ADDRSTRLEN];
                char netmaskBuffer[INET_ADDRSTRLEN];

                pAddr    = (struct sockaddr_in *)(ifa->ifa_addr);
                pNetmask = (struct sockaddr_in *)(ifa->ifa_netmask);
                inet_ntop(AF_INET, &pAddr->sin_addr, addressBuffer, INET_ADDRSTRLEN);
                inet_ntop(AF_INET, &pNetmask->sin_addr, netmaskBuffer, INET_ADDRSTRLEN);

                printf("%s IP Address %s/%s\n", ifa->ifa_name, addressBuffer, netmaskBuffer);
            }
            else if (ifa->ifa_addr->sa_family == AF_INET6)  // IPV6 ?
            {   // Is a valid IPV6 Address
                struct sockaddr_in6 *pAddr;
                struct sockaddr_in6 *pNetmask;
                char addressBuffer[INET6_ADDRSTRLEN];
                //char netmaskBuffer[INET6_ADDRSTRLEN];
                char *pAddrType;
                uint32_t scopeid;

                pAddr    = (struct sockaddr_in6 *)(ifa->ifa_addr);
                pNetmask = (struct sockaddr_in6 *)(ifa->ifa_netmask);


                if (IN6_IS_ADDR_LINKLOCAL(&pAddr->sin6_addr))
                {
                    pAddr->sin6_scope_id = ntohs(*(uint16_t *)&pAddr->sin6_addr.s6_addr[2]);
                    *(uint16_t *)&pAddr->sin6_addr.s6_addr[2] = 0;
                    pAddrType = "link-local";
                }
                else if (IN6_IS_ADDR_SITELOCAL(&pAddr->sin6_addr))
                {
                    pAddrType = "site-local";
                }
                else if (IN6_IS_ADDR_V4MAPPED(&pAddr->sin6_addr))
                {
                    pAddrType = "v4mapped";
                }
                else if (IN6_IS_ADDR_V4COMPAT(&pAddr->sin6_addr))
                {
                    pAddrType = "v4compat";
                }
                else if (IN6_IS_ADDR_LOOPBACK(&pAddr->sin6_addr))
                {
                    pAddrType = "host";
                }
                else if (IN6_IS_ADDR_UNSPECIFIED(&pAddr->sin6_addr))
                {
                    pAddrType = "unspecified";
                }
                else
                {
                    pAddrType = "global";
                }

                scopeid = pAddr->sin6_scope_id;
                inet_ntop(AF_INET6, &pAddr->sin6_addr, addressBuffer, INET6_ADDRSTRLEN);
                //inet_ntop(AF_INET6, &pNetmask->sin6_addr, netmaskBuffer, INET6_ADDRSTRLEN);

                printf("%s IP Address %s/%d scopeid %d (%s)\n", ifa->ifa_name, addressBuffer, Ip6MaskLength(pNetmask->sin6_addr), scopeid, pAddrType);
            }
            else if (ifa->ifa_addr->sa_family == AF_LINK)  // MAC address ?
            {
                struct sockaddr_dl *pAddr;
                uint8_t Index;
                uint8_t Counter;


                pAddr = (struct sockaddr_dl *)ifa->ifa_addr;

                Index = 0;
                printf("AF_LINK : \n");
                printf("  Interface Index : %d\n", pAddr->sdl_index);
                printf("  Interface type  : %d\n", pAddr->sdl_type);
                //printf("  Name length : %d\n", pAddr->sdl_nlen);
                //printf("  Addr length : %d\n", pAddr->sdl_alen);
                //printf("  Selector length : %d\n", pAddr->sdl_slen);
                printf("  Name : ");
                for (Counter=0; Counter < pAddr->sdl_nlen; Counter++)
                {
                    printf("%c", pAddr->sdl_data[Index]);
                    Index++;
                }
                printf("\n");
                printf("  Addr : ");
                for (Counter=0; Counter < pAddr->sdl_alen; Counter++)
                {
                    printf("%02X", (uint8_t)pAddr->sdl_data[Index]);
                    Index++;
                }
                printf("\n");
                if (pAddr->sdl_slen)
                {
                    printf("  Selector : ");
                    for (Counter=0; Counter < pAddr->sdl_slen; Counter++)
                    {
                        printf("%02X", pAddr->sdl_data[Index]);
                        Index++;
                    }
                    printf("\n");
                }
            }
            else
            {
                printf("Unknown -> %d (%s -> %04X)\n", ifa->ifa_addr->sa_family, ifa->ifa_name, ifa->ifa_flags);
            }
        }
        else
        {
            printf("???\n");
        }

        ifa = ifa->ifa_next;
    }

    if (ifAddrStruct != NULL)
    {
        freeifaddrs(ifAddrStruct);
    }
}

Regards,
Nicolas

What do you call CPU Id ?