亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

獲取本地網(wǎng)卡適配器信息具體代碼

 更新時間:2013年12月31日 16:35:00   作者:  
這篇文章主要介紹了獲取本地網(wǎng)卡適配器信息具體代碼,有需要的朋友可以參考一下

效果如下:

具體代碼如下:

復制代碼 代碼如下:

#include <Windows.h>
#include <IPHlpApi.h>
#include <stdio.h>

#pragma comment(lib, "IPHlpApi")
#pragma comment(lib, "ws2_32")

int main(int argc, char **argv)
{
    PIP_ADAPTER_INFO pAdapterInfo = NULL;
    ULONG ulLen = sizeof(IP_ADAPTER_INFO);
    struct tm newtime;
    char szBuffer[32];
    errno_t error;

    //為適配器結構申請內存
    //pAdapterInfo = (PIP_ADAPTER_INFO)GlobalAlloc(GPTR, ulLen);
    pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
    if (NULL == pAdapterInfo)
    {
        printf("Error allocating memory needed to call GetAdaptersInfo.\n");
        return 1;
    }

    if (ERROR_BUFFER_OVERFLOW == GetAdaptersInfo(pAdapterInfo, &ulLen))
    {
        HeapFree(GetProcessHeap(), 0, pAdapterInfo);
        pAdapterInfo = (PIP_ADAPTER_INFO)HeapAlloc(GetProcessHeap(), 0, ulLen);
        if (NULL == pAdapterInfo)
        {
            printf("Error allocating memory needed to call GetAdaptersInfo.\n");
            return 1;
        }
    }

    //取得本地適配器結構信息
    if (ERROR_SUCCESS != GetAdaptersInfo(pAdapterInfo, &ulLen))
    {
        printf("GetAdaptersInfo error!\n");
        return 0;
    }
    if (NULL == pAdapterInfo)
    {
        printf("There is no adapters!\n");
        return 0;
    }

    SetConsoleTitle(TEXT("本地網(wǎng)卡適配器信息"));

    do
    {
        printf("ComboIndex:%d\n", pAdapterInfo->ComboIndex);
        printf("Adapter Name:%s\n", pAdapterInfo->AdapterName);
        printf("Adapter Desc:%s\n", pAdapterInfo->Description);
        printf("Adapter Addr:");
        for (size_t i = 0; i < pAdapterInfo->AddressLength; i++)
        {
            if (i == (pAdapterInfo->AddressLength - 1))
            {
                printf("%02X", (int)pAdapterInfo->Address[i]);
            }
            else
            {
                printf("%02X-", (int)pAdapterInfo->Address[i]);
            }
        }
        printf("\n");
        printf("Index:%d\n", pAdapterInfo->Index);
        printf("Type:");
        switch (pAdapterInfo->Type)
        {
        case MIB_IF_TYPE_OTHER:printf("Other\n"); break;
        case MIB_IF_TYPE_ETHERNET:printf("Ethernet\n"); break;
        case MIB_IF_TYPE_TOKENRING:printf("Token Ring\n"); break;
        case MIB_IF_TYPE_FDDI:printf("FDDI\n"); break;
        case MIB_IF_TYPE_PPP:printf("PPP\n"); break;
        case MIB_IF_TYPE_LOOPBACK:printf("Lookback\n"); break;
        case MIB_IF_TYPE_SLIP:printf("Slip\n"); break;
        default:printf("Unknow type %ld\n", pAdapterInfo->Type); break;
        }
        printf("IP Address:%s\n", pAdapterInfo->IpAddressList.IpAddress.String);
        printf("IP Mask:%s\n", pAdapterInfo->IpAddressList.IpMask.String);
        printf("Gateway:%s\n", pAdapterInfo->GatewayList.IpAddress.String);

        if (pAdapterInfo->DhcpEnabled)
        {
            printf("DHCP Enabled:Yes\n");
            printf("DHCP Server:%s\n", pAdapterInfo->DhcpServer.IpAddress.String);
            printf("Lease Obtained:");
            error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseObtained);
            if (error)
            {
                printf("Invalid Argument to _localtime32_s.\n");
            }
            else
            {
                error = asctime_s(szBuffer, 32, &newtime);
                if (error)
                {
                    printf("Invalid Argument to asctime_s.\n");
                }
                else
                {
                    printf("%s", szBuffer);
                }
            }

            printf("Lease Expires:");
            error = _localtime32_s(&newtime, (__time32_t*)&pAdapterInfo->LeaseExpires);
            if (error)
            {
                printf("Invalid Argument to _localtime32_s.\n");
            }
            else
            {
                error = asctime_s(szBuffer, 32, &newtime);
                if (error)
                {
                    printf("Invalid Argument to asctime_s.\n");
                }
                else
                {
                    printf("%s", szBuffer);
                }
            }
        }
        else
        {
            printf("DHCP Enabled:No\n");
        }

        if (pAdapterInfo->HaveWins)
        {
            printf("Have Wins:Yes\n");
            printf("Primary Wins Server:%s\n", pAdapterInfo->PrimaryWinsServer.IpAddress.String);
            printf("Secondary Wins Server:%s\n", pAdapterInfo->SecondaryWinsServer.IpAddress.String);
        }
        else
        {
            printf("Have Wins:No\n");
        }

        printf("=================================================================\n");

        pAdapterInfo = pAdapterInfo->Next;
    } while (pAdapterInfo);

    if (pAdapterInfo)
    {
        HeapFree(GetProcessHeap(), 0, pAdapterInfo);
    }

    return 0;
}

相關文章

  • 用貪心法求解背包問題的解決方法

    用貪心法求解背包問題的解決方法

    本篇文章是對用貪心法求解背包問題的解決方法進行了詳細的分析介紹,需要的朋友參考下
    2013-05-05
  • C語言完整實現(xiàn)12種排序算法(小結)

    C語言完整實現(xiàn)12種排序算法(小結)

    本文主要介紹了C語言完整實現(xiàn)12種排序算法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-05-05
  • C語言程序中結構體的內存對齊詳解

    C語言程序中結構體的內存對齊詳解

    這篇文章主要為大家詳細介紹了C語言程序中結構體的內存對齊的相關資料,文中的示例代碼講解詳細,具有一定的參考價值,感興趣的小伙伴可以了解一下
    2022-11-11
  • C語言算法練習之打魚還是曬網(wǎng)

    C語言算法練習之打魚還是曬網(wǎng)

    這篇文章主要該大家分享C語言打魚還是曬網(wǎng)的練習,文章主要通過三天打魚兩天曬網(wǎng)的俗語提出問題,在某一天輪到打魚還是曬網(wǎng),下面來看詳細內容吧,需要的朋友可以參考一下
    2022-03-03
  • 一篇文章讓你徹底明白c++11增加的變參數(shù)模板

    一篇文章讓你徹底明白c++11增加的變參數(shù)模板

    C++11的新特性--可變模版參數(shù)(variadic templates)是C++11新增的最強大的特性之一,它對參數(shù)進行了高度泛化,它能表示0到任意個數(shù)、任意類型的參數(shù),這篇文章主要給大家詳細介紹了關于c++11增加的變參數(shù)模板的相關資料,需要的朋友可以參考下
    2021-08-08
  • 使用C++實現(xiàn)工資管理中的隨機教師信息生成功能

    使用C++實現(xiàn)工資管理中的隨機教師信息生成功能

    這篇文章主要介紹了使用C++實現(xiàn)工資管理中的隨機教師信息生成功能,想要做一個教師工資管理系統(tǒng),就必須得準備好數(shù)據(jù),但是這些數(shù)據(jù)如果用手一行一行地敲,那么工作量是非常大的,因此,我就產生了用C語言實現(xiàn)直接生成大量的教師基本信息的想法,需要的朋友可以參考下
    2023-05-05
  • 關于C++出現(xiàn)Bus error問題的排查與解決

    關于C++出現(xiàn)Bus error問題的排查與解決

    項目代碼中經常出現(xiàn)莫名其妙的Bus error問題,并且代碼中增加很多try catch 后依然不能將錯誤捕獲,一旦Bus erro出現(xiàn),進程直接崩潰掉,所以本文給大家介紹了關于C++出現(xiàn)Bus error問題的排查與解決,需要的朋友可以參考下
    2024-01-01
  • 基于C++實現(xiàn)去除字符串頭尾指定字符功能

    基于C++實現(xiàn)去除字符串頭尾指定字符功能

    編程時我們經常需要對字符串進行操作,其中有一項操作就是去除字符串的頭(尾)指定的字符,比如空格。本文為大家詳細介紹了如何利用C++實現(xiàn)這一效果,需要的可以參考一下
    2022-04-04
  • Atom安裝配置C/C++詳細教程

    Atom安裝配置C/C++詳細教程

    Atom (一款開源的代碼編輯器)是github專門為程序員推出的一個跨平臺文本編輯器。這篇文章主要介紹了Atom安裝配置C/C++教程,需要的朋友可以參考下
    2020-05-05
  • c++ 解析yaml文件的步驟

    c++ 解析yaml文件的步驟

    這篇文章主要介紹了c++ 解析yaml文件的步驟,幫助大家更好的理解和使用c++,感興趣的朋友可以了解下
    2020-12-12

最新評論