• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ GetIpAddrTable函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GetIpAddrTable函数的典型用法代码示例。如果您正苦于以下问题:C++ GetIpAddrTable函数的具体用法?C++ GetIpAddrTable怎么用?C++ GetIpAddrTable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetIpAddrTable函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: MyGetIpAddrTable

//----------------------------------------------------------------------------
// If returned status is NO_ERROR, then pIpAddrTable points to a Ip Address
// table.
//----------------------------------------------------------------------------
DWORD MyGetIpAddrTable(PMIB_IPADDRTABLE& pIpAddrTable, BOOL fOrder)
{
    DWORD status = NO_ERROR;
    DWORD statusRetry = NO_ERROR;
    DWORD dwActualSize = 0;
    
    // query for buffer size needed
    status = GetIpAddrTable(pIpAddrTable, &dwActualSize, fOrder);

    if (status == NO_ERROR)
    {
        printf("No error\n");
        return status;
    }
    else if (status == ERROR_INSUFFICIENT_BUFFER)
    {
        // need more space

        pIpAddrTable = (PMIB_IPADDRTABLE) malloc(dwActualSize);
        assert(pIpAddrTable);
        
        statusRetry = GetIpAddrTable(pIpAddrTable, &dwActualSize, fOrder);
        return statusRetry;
    }
    else
    {
        return status;
    }
}
开发者ID:AbdoSalem95,项目名称:WindowsSDK7-Samples,代码行数:33,代码来源:IPRoute.Cpp


示例2: Get_Table

IN_ADDR* Get_Table()
{
    PMIB_IPADDRTABLE pIPAddrTable;
    DWORD dwSize = 0;

    pIPAddrTable = (MIB_IPADDRTABLE *)MALLOC(sizeof (MIB_IPADDRTABLE));

    if (pIPAddrTable)
        if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER)
        {
            FREE(pIPAddrTable);
            pIPAddrTable = (MIB_IPADDRTABLE *)MALLOC(dwSize);
        }

    GetIpAddrTable(pIPAddrTable, &dwSize, 0);

    IN_ADDR* IPAddr = new IN_ADDR[pIPAddrTable->dwNumEntries];

    printf("List of the BroadCast Address: \n");
    for (int i = 0; i < (int)pIPAddrTable->dwNumEntries; i++)
    {
        IPAddr[i].S_un.S_addr = (u_long)pIPAddrTable->table[i].dwAddr | ~(u_long)pIPAddrTable->table[i].dwMask;
        printf("\tBroadCast[%d]: \t%s\n", i, inet_ntoa(IPAddr[i]));
    }

    FREE(pIPAddrTable);
    return IPAddr;
}
开发者ID:nonamerz,项目名称:SSOLN_2,代码行数:28,代码来源:SSOLN_3_new.cpp


示例3: get_if_index_ip

ULONG
get_if_index_ip(ULONG if_index)
{
	ULONG size, i;
	MIB_IPADDRTABLE *buf;
	ULONG result;

	size = 0;
	if (GetIpAddrTable(NULL, &size, FALSE) != ERROR_INSUFFICIENT_BUFFER)
		return (ULONG)-1;

	buf = (MIB_IPADDRTABLE *)malloc(size);
	if (buf == NULL)
		return (ULONG)-1;

	if (GetIpAddrTable(buf, &size, FALSE) != NO_ERROR) {
		free(buf);
		return (ULONG)-1;
	}

    result = 0;
	for (i = 0; i < buf->dwNumEntries; i++)
		if (buf->table[i].dwIndex == if_index) {
			result = buf->table[i].dwAddr;
			break;
		}

	free(buf);
	return result;
}
开发者ID:340211173,项目名称:hf-2011,代码行数:30,代码来源:tdifw_svc.c


示例4: addressToIndexAndMask

static os_result
addressToIndexAndMask(struct sockaddr *addr, unsigned int *ifIndex, struct sockaddr *mask )
{
    os_result result = os_resultSuccess;
    os_boolean found = OS_FALSE;
    PMIB_IPADDRTABLE pIPAddrTable = NULL;
    DWORD dwSize = 0;
    DWORD i;
    char* errorMessage;
    int errNo;

    if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {
        pIPAddrTable = (MIB_IPADDRTABLE *) os_malloc(dwSize);
        if (pIPAddrTable != NULL) {
            if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) != NO_ERROR) {
                errNo = os_sockError();
                errorMessage = os_reportErrnoToString(errNo);
                os_report(OS_ERROR, "addressToIndexAndMask", __FILE__, __LINE__, 0,
                      "GetIpAddrTable failed: %d %s", errNo, errorMessage);
                os_free(errorMessage);
                result = os_resultFail;
            }
        } else {
            os_report(OS_ERROR, "addressToIndexAndMask", __FILE__, __LINE__, 0,
                "Failed to allocate %d bytes for IP address table", dwSize);
            result = os_resultFail;
        }
    } else {
        errNo = os_sockError();
        errorMessage = os_reportErrnoToString(errNo);
        os_report(OS_ERROR, "addressToIndexAndMask", __FILE__, __LINE__, 0,
                    "GetIpAddrTable failed: %d %s", errNo, errorMessage);
        os_free(errorMessage);
        result = os_resultFail;
    }

    if (result == os_resultSuccess) {
        for (i = 0; !found && i < pIPAddrTable->dwNumEntries; i++ ) {
            if (((struct sockaddr_in* ) addr )->sin_addr.s_addr == pIPAddrTable->table[i].dwAddr) {
                *ifIndex = pIPAddrTable->table[i].dwIndex;
                ((struct sockaddr_in*) mask)->sin_addr.s_addr= pIPAddrTable->table[i].dwMask;
                found = OS_TRUE;
            }
        }
    }

    if (pIPAddrTable) {
        os_free(pIPAddrTable);
    }

    if (!found) {
        result = os_resultFail;
    }

    return result;
}
开发者ID:S73417H,项目名称:opensplice,代码行数:56,代码来源:os_socket.c


示例5: dest_to_endpoint

  /*!
   * @if jp
   * @brief 宛先アドレスから利用されるエンドポイントアドレスを得る
   * @else
   * @brief Getting network interface name from destination address
   * @endif
   */
  bool dest_to_endpoint(std::string dest_addr, std::string& endpoint)
  {
    Winsock winsock;
    {
      struct hostent* hp;
      hp = ::gethostbyname(dest_addr.c_str());
      if (hp == 0) { return false; }

      int i(0);
      while (hp->h_addr_list[i] != 0)
        {
          if(hp->h_addrtype == AF_INET)
            {
              struct sockaddr_in addr;
              memset((char*)&addr, 0, sizeof(addr));
              memcpy((char*)&addr.sin_addr, hp->h_addr_list[i], hp->h_length);
              dest_addr = inet_ntoa(addr.sin_addr);
              break;
            }
          ++i;
        }
    }
    
    UINT ipaddress(inet_addr(dest_addr.c_str()));
    if (ipaddress == INADDR_NONE) { return false; }
    
    DWORD bestifindex;
    if (NO_ERROR != GetBestInterface(ipaddress, &bestifindex)) { return false; }
        
    PMIB_IPADDRTABLE ipaddr_table;
    ipaddr_table = (MIB_IPADDRTABLE *) MALLOC(sizeof (MIB_IPADDRTABLE));
    if (ipaddr_table == 0) { return false; }

    // Make an initial call to GetIpAddrTable to get the
    // necessary size into the size variable
    DWORD size(0);
    if (GetIpAddrTable(ipaddr_table, &size, 0) == ERROR_INSUFFICIENT_BUFFER)
      {
        FREE(ipaddr_table);
        ipaddr_table = (MIB_IPADDRTABLE *) MALLOC(size);
      }
    if (ipaddr_table == 0) { return false; }
    if (GetIpAddrTable(ipaddr_table, &size, 0) != NO_ERROR) { return false; }
    
    for (int i(0); i < (int) ipaddr_table->dwNumEntries; ++i)
      {
        if (bestifindex == ipaddr_table->table[i].dwIndex)
          {
            IN_ADDR inipaddr;
            inipaddr.S_un.S_addr = (u_long) ipaddr_table->table[i].dwAddr;
            endpoint = inet_ntoa(inipaddr);
            return true;
          }
      }
    return false;
  }
开发者ID:pansas,项目名称:OpenRTM-aist-portable,代码行数:63,代码来源:Routing.cpp


示例6: Log

void MonitorIPs::CheckIPAddress()
{
    ULONG ulSize = 0;

    Log(LOG_DEBUG,__LINE__,">> MonIPs.ChkIPAddrs");

    //Get number of bytes required
    if(GetIpAddrTable(NULL,&ulSize,0)==ERROR_INSUFFICIENT_BUFFER)
    {
        //Aloocate required memory
        PMIB_IPADDRTABLE piat = reinterpret_cast<PMIB_IPADDRTABLE>(LocalAlloc(LMEM_FIXED,ulSize));
        if(piat)
        {
            //Retrive the list of IPs
            if(GetIpAddrTable(piat,&ulSize,0)==ERROR_SUCCESS)
            {
                WaitForSingleObject(m_hSync,MINUTE);
                m_ips.clear();

                for(DWORD dwIndex=0;dwIndex<piat->dwNumEntries;dwIndex++)
                {
                    //Trace all IPs
                    string strip;
                    char ip[_MAX_PATH] = {0};

                    PMIB_IPADDRROW prow = &piat->table[dwIndex];
                    _snprintf(ip,sizeof(ip)-1,"Addr %u, Idx %u, Mask %u, BCastAddr %u, ReasmSz %u, Tp %X.",
                                 prow->dwAddr,prow->dwIndex,prow->dwMask,prow->dwBCastAddr,prow->dwReasmSize,prow->wType);
                    strip.assign(ip);
                    if(prow->wType&MIB_IPADDR_PRIMARY)
                        strip.append("Primary.");
                    if(prow->wType&MIB_IPADDR_DYNAMIC)
                        strip.append("Dynamic.");
                    if(prow->wType&MIB_IPADDR_DISCONNECTED)
                        strip.append("Disconnected.");
                    if(prow->wType&MIB_IPADDR_DELETED)
                        strip.append("Deleted.");
                    if(prow->wType&MIB_IPADDR_TRANSIENT)
                        strip.append("Transient.");
                    if(prow->wType&MIB_IPADDR_DNS_ELIGIBLE)
                        strip.append("Published in DNS.");

                    m_ips.push_back(strip);
                }
                ReleaseMutex(m_hSync);
            }
            LocalFree(piat);
        }
    }

    HANDLE h;
    NotifyAddrChange(&h, &m_o);

    Log(LOG_DEBUG,__LINE__,"<< MonIPs.ChkIPAddrs");
}
开发者ID:degiuli,项目名称:SysStatus,代码行数:55,代码来源:MonitorIPs.cpp


示例7: mib2IpAddrInit

static void mib2IpAddrInit(void)
{
    DWORD size = 0, ret = GetIpAddrTable(NULL, &size, TRUE);

    if (ret == ERROR_INSUFFICIENT_BUFFER)
    {
        ipAddrTable = HeapAlloc(GetProcessHeap(), 0, size);
        if (ipAddrTable)
            GetIpAddrTable(ipAddrTable, &size, TRUE);
    }
}
开发者ID:iamfil,项目名称:wine,代码行数:11,代码来源:main.c


示例8: find_subnet_adapter

bool find_subnet_adapter(unsigned int if_subnet, unsigned int &addr) {
	// find the adapter with the appropriate subnet
	PMIB_IPADDRTABLE addr_table;
	DWORD dwSize = 0;

	addr_table = (PMIB_IPADDRTABLE)malloc(sizeof(MIB_IPADDRTABLE));

	// make an initial call to get the appropriate address table size
	if (GetIpAddrTable(addr_table, &dwSize, FALSE) == ERROR_INSUFFICIENT_BUFFER) {
		// free the original buffer
		free(addr_table);
		// make space, reallocate
		addr_table = (PMIB_IPADDRTABLE)malloc(dwSize);
	}

	// assert that we could allocate space
	if (addr_table == NULL) {
		printf("could not allocate space for addr table\n");
		return false;
	}

	// get the real data
	unsigned int if_addr = 0;
	if (GetIpAddrTable(addr_table, &dwSize, FALSE) == NO_ERROR) {
		// iterate through the table and find a matching entry
		for (DWORD i = 0; i < addr_table->dwNumEntries; i++) {
			unsigned int subnet = addr_table->table[i].dwAddr & addr_table->table[i].dwMask;
			if (subnet == if_subnet) {
				if_addr = addr_table->table[i].dwAddr;
				break;
			}
		}

		// free the allocated memory
		free(addr_table);
	}
	else {
		printf("error getting ip address table: %d\n", WSAGetLastError());
		// free the allocated memory
		free(addr_table);

		return false;
	}

	// check if we found a match
	if (if_addr != 0) {
		addr = if_addr;
		return true;
	}
	else {
		return false;
	}
}
开发者ID:FrozenXZeus,项目名称:cornell-urban-challenge,代码行数:53,代码来源:net_utility.cpp


示例9: mib2IpAddrInit

static void mib2IpAddrInit(void)
{
    DWORD size = 0, ret = GetIpAddrTable(NULL, &size, TRUE);

    if (ret == ERROR_INSUFFICIENT_BUFFER)
    {
        MIB_IPADDRTABLE *table = HeapAlloc(GetProcessHeap(), 0, size);
        if (table)
        {
            if (!GetIpAddrTable(table, &size, TRUE)) ipAddrTable = table;
            else HeapFree(GetProcessHeap(), 0, table );
        }
    }
}
开发者ID:AmesianX,项目名称:RosWine,代码行数:14,代码来源:main.c


示例10: Test_WSAIoctl_InitTest

BOOL Test_WSAIoctl_InitTest(
    OUT PMIB_IPADDRTABLE* ppTable)
{
    PMIB_IPADDRROW pRow;
    DWORD ret, i1;
    ULONG TableSize;
    PMIB_IPADDRTABLE pTable;

    TableSize = 0;
    *ppTable = NULL;
    ret = GetIpAddrTable(NULL, &TableSize, FALSE);
    if (ret != ERROR_INSUFFICIENT_BUFFER)
    {
        skip("GetIpAddrTable failed with %ld. Abort Testing.\n", ret);
        return FALSE;
    }

    /* get sorted ip-address table. Sort order is the ip-address. */
    pTable = (PMIB_IPADDRTABLE)malloc(TableSize);
    *ppTable = pTable;
    ret = GetIpAddrTable(pTable, &TableSize, TRUE);
    if (ret != NO_ERROR) 
    {
        skip("GetIpAddrTable failed with %ld. Abort Testing.\n", ret);
        return FALSE;
    }

    if (winetest_debug >= 2)
    {
        trace("Result of GetIpAddrTable:\n");
        trace("Count: %ld\n", pTable->dwNumEntries);
        pRow = pTable->table;
        for (i1 = 0; i1 < pTable->dwNumEntries; i1++)
        {
            trace("** Entry %ld **\n", i1);
            trace("  dwAddr %lx\n", pRow->dwAddr);
            trace("  dwIndex %lx\n", pRow->dwIndex);
            trace("  dwMask %lx\n", pRow->dwMask);
            trace("  dwBCastAddr %lx\n", pRow->dwBCastAddr);
            trace("  dwReasmSize %lx\n", pRow->dwReasmSize);
            trace("  wType %x\n", pRow->wType);
            pRow++;
        }
        trace("END\n");
    }

    return TRUE;
}
开发者ID:Moteesh,项目名称:reactos,代码行数:48,代码来源:WSAIoctl.c


示例11: pcap_ex_lookupdev

char *
pcap_ex_lookupdev(char *ebuf)
{
#ifdef _WIN32
	/* XXX - holy poo this sux */
	static char _ifname[8];
	MIB_IPADDRTABLE *ipaddrs;
	DWORD i, dsz, outip;
	pcap_if_t *pifs, *pif;
	struct pcap_addr *pa;
	char *name = NULL;
	int idx;
	
	/* Find our primary IP address. */
	ipaddrs = malloc((dsz = sizeof(*ipaddrs)));
	while (GetIpAddrTable(ipaddrs, &dsz, 0) == ERROR_INSUFFICIENT_BUFFER) {
		free(ipaddrs);
		ipaddrs = malloc(dsz);
	}
	outip = 0;
	for (i = 0; i < ipaddrs->dwNumEntries; i++) {
		if (ipaddrs->table[i].dwAddr != 0 &&
		    ipaddrs->table[i].dwAddr != 0x100007f
#if 0
		    /* XXX -no wType/MIB_IPADDR_PRIMARY in w32api/iprtrmib.h */
		    && ipaddrs->table[i].unused2 & 0x01
#endif
		    ) {
			outip = ipaddrs->table[i].dwAddr;
			break;
		}
	}
	free(ipaddrs);
	if (outip == 0) {
		/* XXX - default to first Ethernet interface. */
		return ("eth0");
	}
	/* Find matching pcap interface by IP. */
	if (_pcap_ex_findalldevs(&pifs, ebuf) == -1)
		return (name);
	
	for (pif = pifs, idx = 0; pif != NULL && name == NULL;
	    pif = pif->next, idx++) {
		for (pa = pif->addresses; pa != NULL; pa = pa->next) {
			if (pa->addr->sa_family == AF_INET &&
			    ((struct sockaddr_in *)pa->addr)->sin_addr.S_un.S_addr == outip) {
				sprintf(_ifname, "eth%d", idx);
				name = _ifname;
				break;
			}
		}
	}
	pcap_freealldevs(pifs);
	return (name);
#else
	return (pcap_lookupdev(ebuf));
#endif
}
开发者ID:WilenceYao,项目名称:pypcap,代码行数:58,代码来源:pcap_ex.c


示例12: GetBestInterface

/////////////////////////////////////////////////////////////////////////////////
// Initializes m_localIP variable, for future access to GetLocalIP()
/////////////////////////////////////////////////////////////////////////////////
void MyUPnP::InitLocalIP()
{
#ifndef _DEBUG
	try
#endif
	{
		DWORD best_if_index;
		GetBestInterface(inet_addr("223.255.255.255"), &best_if_index);

		PMIB_IPADDRTABLE ip_addr_table;
		char buffer[1024];
		ip_addr_table = (PMIB_IPADDRTABLE)buffer;
		DWORD size = sizeof(buffer);
		GetIpAddrTable(ip_addr_table, &size, 0);
		DWORD local_ip = 0;
		for (DWORD i=0; i<ip_addr_table->dwNumEntries; i++) {
			if (ip_addr_table->table[i].dwIndex == best_if_index) {
				local_ip = ip_addr_table->table[i].dwAddr;
				break;
			}
		}

		if (local_ip) {
			struct in_addr addr;
			addr.S_un.S_addr = local_ip;
			m_slocalIP = inet_ntoa(addr);
			m_uLocalIP = local_ip;
		} else {

		char szHost[256];
		if (gethostname(szHost, sizeof szHost) == 0){
			hostent* pHostEnt = gethostbyname(szHost);
			if (pHostEnt != NULL && pHostEnt->h_length == 4 && pHostEnt->h_addr_list[0] != NULL){
				UPNPNAT_MAPPING mapping;
				struct in_addr addr;

				memcpy(&addr, pHostEnt->h_addr_list[0], sizeof(struct in_addr));
				m_slocalIP = inet_ntoa(addr);
				m_uLocalIP = addr.S_un.S_addr;
			}
			else{
				m_slocalIP = _T("");
				m_uLocalIP = 0;
			}
		}
		else{
			m_slocalIP = _T("");
			m_uLocalIP = 0;
		}
		}
	}
#ifndef _DEBUG
	catch(...){
		m_slocalIP = _T("");
		m_uLocalIP = 0;
	}
#endif
}
开发者ID:rusingineer,项目名称:emulextreme-stulle,代码行数:61,代码来源:UPnP_acat.cpp


示例13: GetBroadcastIPList

void GetBroadcastIPList(vector<LPCTSTR> &broadcastIPList)
{
	PMIB_IPADDRTABLE pIPTable = nullptr;
	DWORD dwSize;
	GetIpAddrTable(pIPTable, &dwSize, true);

	pIPTable = new MIB_IPADDRTABLE[dwSize];
	GetIpAddrTable(pIPTable, &dwSize, true);

	broadcastIPList.clear();
	broadcastIPList.push_back(L"255.255.255.255");
	for (DWORD i = 0; i < pIPTable->dwNumEntries; i++)
	{
		if (pIPTable->table[i].dwAddr == 16777343)
		{
			continue;
		}

		int addr[] = {
			LOWORD(pIPTable->table[i].dwAddr & pIPTable->table[i].dwMask) & 0x00FF,
			LOWORD(pIPTable->table[i].dwAddr & pIPTable->table[i].dwMask) >> 8,
			HIWORD(pIPTable->table[i].dwAddr & pIPTable->table[i].dwMask) & 0x00FF,
			HIWORD(pIPTable->table[i].dwAddr & pIPTable->table[i].dwMask) >> 8
		};

		for (int j = 3; j >= 0; j--)
		{
			if (addr[j] == 0)
			{
				addr[j] = 255;
			}
			else
			{
				break;
			}
		}

		LPTSTR szIPAddr = new TCHAR[255];
		wsprintf(szIPAddr, L"%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
		broadcastIPList.push_back(szIPAddr);
	}
}
开发者ID:awfover,项目名称:Gobang,代码行数:42,代码来源:Util.cpp


示例14: ip_route_get

int ip_route_get(const char* destination, char ip[40])
{
	DWORD index = ~(-1);
	struct sockaddr_in addrin;
	MIB_IPADDRTABLE *table = NULL;
	ULONG dwSize = 0;
	DWORD errcode = 0;
	DWORD i = 0;

	addrin.sin_family = AF_INET;
	addrin.sin_port = htons(0);
	inet_pton(AF_INET, destination, &addrin.sin_addr);
	if(NO_ERROR != GetBestInterfaceEx((struct sockaddr*)&addrin, &index))
		return -1;

	errcode = GetIpAddrTable( table, &dwSize, 0 );
	assert(ERROR_INSUFFICIENT_BUFFER == errcode);

	table = (MIB_IPADDRTABLE*)malloc(dwSize);
	errcode = GetIpAddrTable( table, &dwSize, 0 );
	if(!table || NO_ERROR != errcode)
	{
		free(table);
		return -1;
	}

	ip[0] = '\0';
	for(i = 0; i < table->dwNumEntries; i++)
	{
		if(table->table[i].dwIndex == index)
		{
			sprintf(ip, "%d.%d.%d.%d", 
				(table->table[i].dwAddr >> 0) & 0xFF,
				(table->table[i].dwAddr >> 8) & 0xFF,
				(table->table[i].dwAddr >> 16) & 0xFF,
				(table->table[i].dwAddr >> 24) & 0xFF);
			break;
		}
	}
开发者ID:ireader,项目名称:sdk,代码行数:39,代码来源:ip-route.c


示例15: GetNumOfIpAddrs

DWORD
GetNumOfIpAddrs(void)
{
    PMIB_IPADDRTABLE pIpAddrTable = NULL;
    ULONG            dwSize;
    DWORD            code;
    DWORD            index;
    DWORD            validAddrs = 0;

    dwSize = 0;
    code = GetIpAddrTable(NULL, &dwSize, 0);
    if (code == ERROR_INSUFFICIENT_BUFFER) {
        pIpAddrTable = malloc(dwSize);
        code = GetIpAddrTable(pIpAddrTable, &dwSize, 0);
        if ( code == NO_ERROR ) {
            for ( index=0; index < pIpAddrTable->dwNumEntries; index++ ) {
                if (pIpAddrTable->table[index].dwAddr != 0)
                    validAddrs++;
            }
        }
        free(pIpAddrTable);
    }
    return validAddrs;
}
开发者ID:maxendpoint,项目名称:openafs_cvs,代码行数:24,代码来源:ipaddrchg.c


示例16: get_node_id

static int get_node_id(unsigned char *byMAC)
{
    DWORD               i, dwSize;
    PMIB_IPADDRTABLE    pAddr = NULL;
    MIB_IFROW           iInfo;
    PFIXED_INFO         pFI = NULL;

    /* Get all IP addresses held by this machine; if it's connected to a network, there's at least one
       that's not localhost */
    dwSize = 0;
    GetIpAddrTable(NULL, &dwSize, TRUE);
    pAddr = (PMIB_IPADDRTABLE)malloc(sizeof(BYTE) * dwSize);
    if (!GetIpAddrTable(pAddr, &dwSize, TRUE))
    {
        for (i = 0; i < pAddr->dwNumEntries; ++i)
        {
            if (IP_LOCALHOST != pAddr->table[i].dwAddr)
            {
                /* Not localhost, so get the interface */
                memset(&iInfo, 0, sizeof(MIB_IFROW));
                iInfo.dwIndex = pAddr->table[i].dwIndex;
                GetIfEntry(&iInfo);

                if (MIB_IF_TYPE_ETHERNET == iInfo.dwType)
                {
                    /*iInfo.bPhysAddr contains the MAC address of this interface*/
                    memcpy(byMAC, iInfo.bPhysAddr, iInfo.dwPhysAddrLen);
                    free(pAddr);
                    return 1;
                }
            }
        }
    }
    free(pAddr);
    return 0;
}
开发者ID:151706061,项目名称:Gdcm,代码行数:36,代码来源:gen_uuid.c


示例17: ssh_ip_route_get_ipaddrtable

static MIB_IPADDRTABLE *
ssh_ip_route_get_ipaddrtable(void)
{
  MIB_IPADDRTABLE *data = NULL;
  DWORD error;
  ULONG size;

  size = 0;
  error = GetIpAddrTable(NULL, &size, FALSE);
  if (error != ERROR_INSUFFICIENT_BUFFER)
    {
      if (error == ERROR_NO_DATA)
        {
          SSH_DEBUG(SSH_D_FAIL, ("No local IP addresses"));
          return NULL;
        }
      SSH_DEBUG(SSH_D_FAIL, ("GetIpAddrTable: error 0x%08X", (unsigned)error));
      return NULL;
    }

  if (!(data = ssh_malloc(size)))
    {
      SSH_DEBUG(SSH_D_FAIL, ("out of memory allocating IP address table"));
      return NULL;
    }

  error = GetIpAddrTable(data, &size, FALSE);
  if (error != NO_ERROR)
    {
      SSH_DEBUG(SSH_D_FAIL, ("GetIpAddrTable: error 0x%08X", (unsigned)error));
      ssh_free(data);
      return NULL;
    }

  return data;
}
开发者ID:patrick-ken,项目名称:kernel_808l,代码行数:36,代码来源:win_ip_route_ce.c


示例18: php_add4_to_if_index

int php_add4_to_if_index(struct in_addr *addr, php_socket *php_sock, unsigned *if_index)
{
	MIB_IPADDRTABLE *addr_table;
    ULONG size;
    DWORD retval;
	DWORD i;

	(void) php_sock; /* not necessary */

	if (addr->s_addr == INADDR_ANY) {
		*if_index = 0;
		return SUCCESS;
	}

	size = 4 * (sizeof *addr_table);
	addr_table = emalloc(size);
retry:
	retval = GetIpAddrTable(addr_table, &size, 0);
	if (retval == ERROR_INSUFFICIENT_BUFFER) {
		efree(addr_table);
		addr_table = emalloc(size);
		goto retry;
	}
	if (retval != NO_ERROR) {
		php_error_docref(NULL, E_WARNING,
			"GetIpAddrTable failed with error %lu", retval);
		return FAILURE;
	}
	for (i = 0; i < addr_table->dwNumEntries; i++) {
		MIB_IPADDRROW r = addr_table->table[i];
		if (r.dwAddr == addr->s_addr) {
			*if_index = r.dwIndex;
			return SUCCESS;
		}
	}

	{
		char addr_str[17] = {0};
		inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str));
		php_error_docref(NULL, E_WARNING,
			"The interface with IP address %s was not found", addr_str);
	}
	return FAILURE;
}
开发者ID:LTD-Beget,项目名称:php-src,代码行数:44,代码来源:multicast.c


示例19: _refresh_tables

static int
_refresh_tables(intf_t *intf)
{
	MIB_IFROW *ifrow;
	ULONG len;
	u_int i, ret;

	/* Get interface table. */
	for (len = sizeof(intf->iftable[0]); ; ) {
		if (intf->iftable)
			free(intf->iftable);
		intf->iftable = malloc(len);
		ret = GetIfTable(intf->iftable, &len, FALSE);
		if (ret == NO_ERROR)
			break;
		else if (ret != ERROR_INSUFFICIENT_BUFFER)
			return (-1);
	}
	/* Get IP address table. */
	for (len = sizeof(intf->iptable[0]); ; ) {
		if (intf->iptable)
			free(intf->iptable);
		intf->iptable = malloc(len);
		ret = GetIpAddrTable(intf->iptable, &len, FALSE);
		if (ret == NO_ERROR)
			break;
		else if (ret != ERROR_INSUFFICIENT_BUFFER)
			return (-1);
	}
	/*
	 * Map "unfriendly" win32 interface indices to ours.
	 * XXX - like IP_ADAPTER_INFO ComboIndex
	 */
	for (i = 0; i < intf->iftable->dwNumEntries; i++) {
		ifrow = &intf->iftable->table[i];
		if (ifrow->dwType < MIB_IF_TYPE_MAX) {
			_ifcombo_add(&intf->ifcombo[ifrow->dwType],
			    ifrow->dwIndex);
		} else
			return (-1);
	}
	return (0);
}
开发者ID:OPSF,项目名称:uClinux,代码行数:43,代码来源:intf-win32.c


示例20: php_if_index_to_addr4

int php_if_index_to_addr4(unsigned if_index, php_socket *php_sock, struct in_addr *out_addr)
{
	MIB_IPADDRTABLE *addr_table;
    ULONG size;
    DWORD retval;
	DWORD i;

	(void) php_sock; /* not necessary */

	if (if_index == 0) {
		out_addr->s_addr = INADDR_ANY;
		return SUCCESS;
	}

	size = 4 * (sizeof *addr_table);
	addr_table = emalloc(size);
retry:
	retval = GetIpAddrTable(addr_table, &size, 0);
	if (retval == ERROR_INSUFFICIENT_BUFFER) {
		efree(addr_table);
		addr_table = emalloc(size);
		goto retry;
	}
	if (retval != NO_ERROR) {
		php_error_docref(NULL, E_WARNING,
			"GetIpAddrTable failed with error %lu", retval);
		return FAILURE;
	}
	for (i = 0; i < addr_table->dwNumEntries; i++) {
		MIB_IPADDRROW r = addr_table->table[i];
		if (r.dwIndex == if_index) {
			out_addr->s_addr = r.dwAddr;
			return SUCCESS;
		}
	}
	php_error_docref(NULL, E_WARNING,
		"No interface with index %u was found", if_index);
	return FAILURE;
}
开发者ID:LTD-Beget,项目名称:php-src,代码行数:39,代码来源:multicast.c



注:本文中的GetIpAddrTable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetItemAt函数代码示例发布时间:2022-05-30
下一篇:
C++ GetInternal函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap