您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ GetIpAddrTable函数代码示例

51自学网 2021-06-01 21:09:38
  C++
这篇教程C++ GetIpAddrTable函数代码示例写得很实用,希望能帮到您。

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

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


示例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,


示例3: get_if_index_ip

ULONGget_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,


示例4: addressToIndexAndMask

static os_resultaddressToIndexAndMask(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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例15: GetNumOfIpAddrs

DWORDGetNumOfIpAddrs(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,


示例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,


示例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,


示例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,


示例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,


示例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,


示例21: main

int main (int argc, char **argv) {  LPSTR environment;  LPSTR position;  LPSTR commandline;  MIB_IPADDRTABLE ipatab;   DWORD iptab_size;   environment = GetEnvironmentStrings();  position = environment;  while(strlen(position) > 0) {	printf("%s/n", position);		position += strlen(position) + 1;  }  commandline=GetCommandLine();  printf("commandline: %s/n",commandline);  GetIpAddrTable(&ipatab, &iptab_size, false);   return 0; }
开发者ID:carsten-clauss,项目名称:MP-MPICH,代码行数:23,


示例22: switch

//.........这里部分代码省略.........                bool bSyncToVideoTime = AppConfig->GetInt(TEXT("Audio"), TEXT("SyncToVideoTime")) != 0;                SendMessage(GetDlgItem(hwnd, IDC_SYNCTOVIDEOTIME), BM_SETCHECK, bSyncToVideoTime ? BST_CHECKED : BST_UNCHECKED, 0);                //------------------------------------                bool bUseMicQPC = GlobalConfig->GetInt(TEXT("Audio"), TEXT("UseMicQPC")) != 0;                SendMessage(GetDlgItem(hwnd, IDC_USEMICQPC), BM_SETCHECK, bUseMicQPC ? BST_CHECKED : BST_UNCHECKED, 0);                                //------------------------------------                BOOL bMicSyncFixHack = GlobalConfig->GetInt(TEXT("Audio"), TEXT("UseMicSyncFixHack"));                SendMessage(GetDlgItem(hwnd, IDC_MICSYNCFIX), BM_SETCHECK, bMicSyncFixHack ? BST_CHECKED : BST_UNCHECKED, 0);                //------------------------------------                int bufferTime = GlobalConfig->GetInt(TEXT("General"), TEXT("SceneBufferingTime"), 700);                int globalAudioTimeAdjust = GlobalConfig->GetInt(TEXT("Audio"), TEXT("GlobalAudioTimeAdjust"));                SendMessage(GetDlgItem(hwnd, IDC_AUDIOTIMEADJUST), UDM_SETRANGE32, -bufferTime, 5000);                SendMessage(GetDlgItem(hwnd, IDC_AUDIOTIMEADJUST), UDM_SETPOS32, 0, globalAudioTimeAdjust);                //------------------------------------                int lowLatencyFactor = AppConfig->GetInt(TEXT("Publish"), TEXT("LatencyFactor"), 20);                SetDlgItemInt(hwnd, IDC_LATENCYTUNE, lowLatencyFactor, TRUE);                int bLowLatencyAutoMethod = AppConfig->GetInt(TEXT("Publish"), TEXT("LowLatencyMethod"), 0);                SendMessage(GetDlgItem(hwnd, IDC_LATENCYMETHOD), BM_SETCHECK, bLowLatencyAutoMethod ? BST_CHECKED : BST_UNCHECKED, 0);                //------------------------------------                MIB_IPADDRTABLE tempTable;                DWORD dwSize = 0;                if (GetIpAddrTable (&tempTable, &dwSize, TRUE) == ERROR_INSUFFICIENT_BUFFER)                {                    PMIB_IPADDRTABLE ipTable;                    ipTable = (PMIB_IPADDRTABLE)Allocate(dwSize);                    if (GetIpAddrTable (ipTable, &dwSize, TRUE) == NO_ERROR)                    {                        DWORD i;                        hwndTemp = GetDlgItem(hwnd, IDC_BINDIP);                        SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)TEXT("Default"));                        for (i=0; i < ipTable->dwNumEntries; i++)                        {                            String strAddress;                            DWORD strLength = 32;                            // don't allow binding to localhost                            if ((ipTable->table[i].dwAddr & 0xFF) == 127)                                continue;                            strAddress.SetLength(strLength);                            SOCKADDR_IN IP;                            IP.sin_addr.S_un.S_addr = ipTable->table[i].dwAddr;                            IP.sin_family = AF_INET;                            IP.sin_port = 0;                            zero(&IP.sin_zero, sizeof(IP.sin_zero));                            WSAAddressToString ((LPSOCKADDR)&IP, sizeof(IP), NULL, strAddress.Array(), &strLength);                            SendMessage(hwndTemp, CB_ADDSTRING, 0, (LPARAM)strAddress.Array());
开发者ID:ChaosPower,项目名称:OBS,代码行数:67,


示例23: ssdpDiscoverDevices

/* ssdpDiscoverDevices() : * return a chained list of all devices found or NULL if * no devices was found. * It is up to the caller to free the chained list * delay is in millisecond (poll). * UDA v1.1 says : *   The TTL for the IP packet SHOULD default to 2 and *   SHOULD be configurable. */struct UPNPDev *ssdpDiscoverDevices(const char * const deviceTypes[],                    int delay, const char * multicastif,                    int localport,                    int ipv6, unsigned char ttl,                    int * error,                    int searchalltypes){	struct UPNPDev * tmp;	struct UPNPDev * devlist = 0;	unsigned int scope_id = 0;	int opt = 1;	static const char MSearchMsgFmt[] =	"M-SEARCH * HTTP/1.1/r/n"	"HOST: %s:" XSTR(SSDP_PORT) "/r/n"	"ST: %s/r/n"	"MAN: /"ssdp:discover/"/r/n"	"MX: %u/r/n"	"/r/n";	int deviceIndex;	char bufr[1536];	/* reception and emission buffer */	int sudp;	int n;	struct sockaddr_storage sockudp_r;	unsigned int mx;#ifdef NO_GETADDRINFO	struct sockaddr_storage sockudp_w;#else	int rv;	struct addrinfo hints, *servinfo, *p;#endif#ifdef _WIN32	MIB_IPFORWARDROW ip_forward;	unsigned long _ttl = (unsigned long)ttl;#endif	int linklocal = 1;	if(error)		*error = MINISSDPC_UNKNOWN_ERROR;	if(localport==UPNP_LOCAL_PORT_SAME)		localport = SSDP_PORT;#ifdef _WIN32	sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, IPPROTO_UDP);#else	sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, 0);#endif	if(sudp < 0)	{		if(error)			*error = MINISSDPC_SOCKET_ERROR;		return NULL;	}	/* reception */	memset(&sockudp_r, 0, sizeof(struct sockaddr_storage));	if(ipv6) {		struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_r;		p->sin6_family = AF_INET6;		if(localport > 0 && localport < 65536)			p->sin6_port = htons((unsigned short)localport);		p->sin6_addr = in6addr_any; /* in6addr_any is not available with MinGW32 3.4.2 */	} else {		struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_r;		p->sin_family = AF_INET;		if(localport > 0 && localport < 65536)			p->sin_port = htons((unsigned short)localport);		p->sin_addr.s_addr = INADDR_ANY;	}#ifdef _WIN32/* This code could help us to use the right Network interface for * SSDP multicast traffic *//* Get IP associated with the index given in the ip_forward struct * in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */	if(!ipv6	   && (GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR)) {		DWORD dwRetVal = 0;		PMIB_IPADDRTABLE pIPAddrTable;		DWORD dwSize = 0;#ifdef DEBUG		IN_ADDR IPAddr;#endif		int i;#ifdef DEBUG		printf("ifIndex=%lu nextHop=%lx /n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);#endif		pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));		if(pIPAddrTable) {			if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {				free(pIPAddrTable);				pIPAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize);			}//.........这里部分代码省略.........
开发者ID:Brunnis,项目名称:RetroArch,代码行数:101,


示例24: upnpDiscover

/* upnpDiscover() : * return a chained list of all devices found or NULL if * no devices was found. * It is up to the caller to free the chained list * delay is in millisecond (poll) */LIBSPEC struct UPNPDev *upnpDiscover(int delay, const char * multicastif,             const char * minissdpdsock, int sameport,             int ipv6,             int * error){	struct UPNPDev * tmp;	struct UPNPDev * devlist = 0;	unsigned int scope_id = 0;	int opt = 1;	static const char MSearchMsgFmt[] =	"M-SEARCH * HTTP/1.1/r/n"	"HOST: %s:" XSTR(PORT) "/r/n"	"ST: %s/r/n"	"MAN: /"ssdp:discover/"/r/n"	"MX: %u/r/n"	"/r/n";	static const char * const deviceList[] = {#if 0		"urn:schemas-upnp-org:device:InternetGatewayDevice:2",		"urn:schemas-upnp-org:service:WANIPConnection:2",#endif		"urn:schemas-upnp-org:device:InternetGatewayDevice:1",		"urn:schemas-upnp-org:service:WANIPConnection:1",		"urn:schemas-upnp-org:service:WANPPPConnection:1",		"upnp:rootdevice",		0	};	int deviceIndex = 0;	char bufr[1536];	/* reception and emission buffer */	int sudp;	int n;	struct sockaddr_storage sockudp_r;	unsigned int mx;#ifdef NO_GETADDRINFO	struct sockaddr_storage sockudp_w;#else	int rv;	struct addrinfo hints, *servinfo, *p;#endif#ifdef _WIN32	MIB_IPFORWARDROW ip_forward;#endif	int linklocal = 1;	if(error)		*error = UPNPDISCOVER_UNKNOWN_ERROR;	/* fallback to direct discovery */#ifdef _WIN32	sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, IPPROTO_UDP);#else	sudp = socket(ipv6 ? PF_INET6 : PF_INET, SOCK_DGRAM, 0);#endif	if(sudp < 0)	{		if(error)			*error = UPNPDISCOVER_SOCKET_ERROR;		PRINT_SOCKET_ERROR("socket");		return NULL;	}	/* reception */	memset(&sockudp_r, 0, sizeof(struct sockaddr_storage));	if(ipv6) {		struct sockaddr_in6 * p = (struct sockaddr_in6 *)&sockudp_r;		p->sin6_family = AF_INET6;		if(sameport)			p->sin6_port = htons(PORT);		p->sin6_addr = in6addr_any; /* in6addr_any is not available with MinGW32 3.4.2 */	} else {		struct sockaddr_in * p = (struct sockaddr_in *)&sockudp_r;		p->sin_family = AF_INET;		if(sameport)			p->sin_port = htons(PORT);		p->sin_addr.s_addr = INADDR_ANY;	}#ifdef _WIN32/* This code could help us to use the right Network interface for * SSDP multicast traffic *//* Get IP associated with the index given in the ip_forward struct * in order to give this ip to setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_IF) */	if(!ipv6	   && (GetBestRoute(inet_addr("223.255.255.255"), 0, &ip_forward) == NO_ERROR)) {		DWORD dwRetVal = 0;		PMIB_IPADDRTABLE pIPAddrTable;		DWORD dwSize = 0;#ifdef DEBUG		IN_ADDR IPAddr;#endif		int i;#ifdef DEBUG		printf("ifIndex=%lu nextHop=%lx /n", ip_forward.dwForwardIfIndex, ip_forward.dwForwardNextHop);#endif		pIPAddrTable = (MIB_IPADDRTABLE *) malloc(sizeof (MIB_IPADDRTABLE));		if (GetIpAddrTable(pIPAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) {			free(pIPAddrTable);//.........这里部分代码省略.........
开发者ID:djbarry004,项目名称:Ishiiruka,代码行数:101,


示例25: GetNumberOfInterfaces

long NetCollector::CollectFallback(NVDataItem *DataItems) {	USES_CONVERSION;	DWORD Status;	DWORD NumIfEntries;	Status = GetNumberOfInterfaces( &NumIfEntries);	if (Status != NO_ERROR)		return ERROR_SUCCESS;	PMIB_IFTABLE IfTable = NULL;	PMIB_IPADDRTABLE IPAddrTable = NULL;	unsigned long IfLen = 0;	unsigned long IpLen = 0;	Status = GetIfTable(IfTable, &IfLen, TRUE);	if (Status != ERROR_INSUFFICIENT_BUFFER)		return ERROR_SUCCESS;	Status = GetIpAddrTable(IPAddrTable, &IpLen, FALSE);	if (Status != ERROR_INSUFFICIENT_BUFFER)		return ERROR_SUCCESS;		IfTable = (PMIB_IFTABLE) new char[IfLen];	memset(IfTable, 0 , IfLen);	IPAddrTable = (PMIB_IPADDRTABLE) new char[IpLen];	memset(IPAddrTable, 0 , IpLen);	Status = GetIfTable(IfTable, &IfLen, TRUE);	if (Status != NO_ERROR) {		delete IfTable;		delete IPAddrTable;		return ERROR_SUCCESS;	}	Status = GetIpAddrTable(IPAddrTable, &IpLen, FALSE);	if (Status != NO_ERROR) {		delete IfTable;		delete IPAddrTable;		return ERROR_SUCCESS;	}	DWORD CurrIf;	char TransString[64];	char IPString[64];	PMIB_IFROW CurrEntry = NULL;	for (CurrIf = 0, CurrEntry = IfTable->table;		 CurrIf < IfTable->dwNumEntries; 		 CurrIf ++, CurrEntry ++) {		auto_ptr<NVDataItem> SubItem (new NVDataItem(NCI_TAG));		TransString[0] = '/0';		if (Status != NO_ERROR) {			delete IfTable;			return ERROR_SUCCESS;		}#if 0		if (CurrEntry.dwPhysAddrLen < 1)			continue;#endif		char * IfTypeName;		switch (CurrEntry->dwType) {		case MIB_IF_TYPE_ETHERNET:			IfTypeName = "Ethernet 802.3";			break;		case MIB_IF_TYPE_TOKENRING:			IfTypeName = "Token Ring 802.5";			break;		case MIB_IF_TYPE_FDDI:			IfTypeName = "Fiber Distributed Data Interface (FDDI)";			break;		case MIB_IF_TYPE_PPP:			IfTypeName = "PPP";			break;		case MIB_IF_TYPE_SLIP:			IfTypeName = "SLIP";			break;		default:			IfTypeName = "Unknown";//			continue;		}		SubItem->AddNVItem("InterfaceType", IfTypeName);				//if (wcslen(IfTable->Adapter[CurrIf].Name) > 0) {		//	SubItem->AddNVItem("SysName", W2A(IfTable->Adapter[CurrIf].Name));//.........这里部分代码省略.........
开发者ID:doctorjbeam,项目名称:Syslist,代码行数:101,


示例26: build_ifclist

int build_ifclist(int sock, int max, ip_ifc_info * list) {#ifdef _WIN32    int i;    int ind;    MIB_IPADDRTABLE * info;    ULONG out_buf_len;    DWORD ret_val;    out_buf_len = sizeof *info;    info = (MIB_IPADDRTABLE *)loc_alloc(out_buf_len);    ret_val = GetIpAddrTable(info, &out_buf_len, 0);    if (ret_val == ERROR_INSUFFICIENT_BUFFER) {        loc_free(info);        info = (MIB_IPADDRTABLE *)loc_alloc(out_buf_len);        ret_val = GetIpAddrTable(info, &out_buf_len, 0);    }    if (ret_val != NO_ERROR) {        trace(LOG_ALWAYS, "GetIpAddrTable() error: %d", ret_val);        loc_free(info);        return 0;    }    ind = 0;    for (i = 0; i < (int)info->dwNumEntries && ind < max; i++) {        list[ind].addr = info->table[i].dwAddr;        if (list[ind].addr == 0) continue;        list[ind].mask = info->table[i].dwMask;        ind++;    }    loc_free(info);#elif defined(__SYMBIAN32__)    int ind = 0;    ip_ifc_info* info = get_ip_ifc();    if (info) {        trace(LOG_ALWAYS,"The IP address is %d.%d.%d.%d",                (info->addr >> 24) & 0xff,                (info->addr >> 16) & 0xff,                (info->addr >> 8) & 0xff,                info->addr & 0xff                );        list[ind++] = *info;    }#else    int ind;    char * cp;    struct ifconf ifc;    char if_bbf[0x2000];    memset(&ifc, 0, sizeof ifc);    ifc.ifc_len = sizeof if_bbf;    ifc.ifc_buf = if_bbf;    if (ioctl(sock, SIOCGIFCONF, &ifc) < 0) {        trace(LOG_ALWAYS, "error: ioctl(SIOCGIFCONF) returned %d: %s", errno, errno_to_str(errno));        return 0;    }    ind = 0;    cp = (char *)ifc.ifc_req;    while (cp < (char *)ifc.ifc_req + ifc.ifc_len && ind < max) {        struct ifreq * ifreq_addr = (struct ifreq *)cp;        struct ifreq ifreq_mask = *ifreq_addr;        size_t size = sizeof(struct ifreq);        /* BSD systems allow sockaddrs to be longer than their sizeof */        if (SA_LEN(&ifreq_addr->ifr_addr) > sizeof(ifreq_addr->ifr_addr))            size += SA_LEN(&ifreq_addr->ifr_addr) - sizeof(ifreq_addr->ifr_addr);        cp += size;        if (ifreq_addr->ifr_addr.sa_family != AF_INET) continue;        if (ioctl(sock, SIOCGIFNETMASK, &ifreq_mask) < 0) {            trace(LOG_ALWAYS, "error: ioctl(SIOCGIFNETMASK) returned %d: %s", errno, errno_to_str(errno));            continue;        }        list[ind].addr = ((struct sockaddr_in *)&ifreq_addr->ifr_addr)->sin_addr.s_addr;        list[ind].mask = ((struct sockaddr_in *)&ifreq_mask.ifr_netmask)->sin_addr.s_addr;        ind++;    }#endif    return ind;}
开发者ID:wind-river-cdt,项目名称:tcf.agent,代码行数:76,


示例27: switch

//.........这里部分代码省略.........                    host->startListening(); // start listening again                    const char data[] = "aloha_stk/0";                    if (strcmp(data, (char*)(received_data)) == 0)                    {                        Log::info("ConnectToServer", "LAN Server found : %u:%u", sender.ip, sender.port);#ifndef WIN32                        // just check if the ip is ours : if so, then just use localhost (127.0.0.1)                        struct ifaddrs *ifap, *ifa;                        struct sockaddr_in *sa;                        getifaddrs (&ifap); // get the info                        for (ifa = ifap; ifa; ifa = ifa->ifa_next)                        {                            if (ifa->ifa_addr->sa_family==AF_INET)                            {                                sa = (struct sockaddr_in *) ifa->ifa_addr;                                if (ntohl(sa->sin_addr.s_addr) == sender.ip) // this interface is ours                                    sender.ip = 0x7f000001; // 127.0.0.1                            }                        }                        freeifaddrs(ifap);#else                        // Query the list of all IP addresses on the local host                        // First call to GetIpAddrTable with 0 bytes buffer                        // will return insufficient buffer error, and size                        // will contain the number of bytes needed for all                        // data. Repeat the process of querying the size                        // using GetIpAddrTable in a while loop since it                        // can happen that an interface comes online between                        // the previous call to GetIpAddrTable and the next                        // call.                        MIB_IPADDRTABLE *table = NULL;                        unsigned long size = 0;                        int error = GetIpAddrTable(table, &size, 0);                        // Also add a count to limit the while loop - in                        // case that something strange is going on.                        int count = 0;                        while(error==ERROR_INSUFFICIENT_BUFFER && count < 10)                        {                            delete[] table;   // deleting NULL is legal                            table =  (MIB_IPADDRTABLE*)new char[size];                            error = GetIpAddrTable(table, &size, 0);                            count ++;                        }   // while insufficient buffer                        for(unsigned int i=0; i<table->dwNumEntries; i++)                        {                            int ip = ntohl(table->table[i].dwAddr);                            if(sender.ip == ip) // this interface is ours                            {                                sender.ip = 0x7f000001; // 127.0.0.1                                break;                            }                        }                        delete[] table;#endif                        m_server_address = sender;                        m_state = CONNECTING;                    }                }                else                {                    m_state = CONNECTING;                    m_current_protocol_id = m_listener->requestStart(new PingProtocol(m_server_address, 2.0));                }            }
开发者ID:gupascal,项目名称:stk-code,代码行数:67,


示例28: NET_IF_LIST

int	NET_IF_LIST(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result){	DWORD		dwSize, dwRetVal, i, j;	char		*buf = NULL;	size_t		buf_alloc = 512, buf_offset = 0;	int		ret = SYSINFO_RET_FAIL;	/* variables used for GetIfTable and GetIfEntry */	MIB_IFTABLE	*pIfTable = NULL;	MIB_IFROW	pIfRow;	/* variables used for GetIpAddrTable */	MIB_IPADDRTABLE	*pIPAddrTable = NULL;	IN_ADDR		in_addr;	/* Allocate memory for our pointers. */	dwSize = sizeof(MIB_IPADDRTABLE);	pIPAddrTable = (MIB_IPADDRTABLE *)zbx_malloc(pIPAddrTable, sizeof(MIB_IPADDRTABLE));	/* Make an initial call to GetIpAddrTable to get the	   necessary size into the dwSize variable */	if (ERROR_INSUFFICIENT_BUFFER == GetIpAddrTable(pIPAddrTable, &dwSize, 0))		pIPAddrTable = (MIB_IPADDRTABLE *)zbx_realloc(pIPAddrTable, dwSize);	/* Make a second call to GetIpAddrTable to get the	   actual data we want */	if (NO_ERROR != (dwRetVal = GetIpAddrTable(pIPAddrTable, &dwSize, 0)))	{		zabbix_log(LOG_LEVEL_DEBUG, "GetIpAddrTable failed with error: %s", strerror_from_system(dwRetVal));		goto clean;	}	/* Allocate memory for our pointers. */	dwSize = sizeof(MIB_IFTABLE);	pIfTable = (MIB_IFTABLE *)zbx_malloc(pIfTable, dwSize);	/* Before calling GetIfEntry, we call GetIfTable to make	   sure there are entries to get and retrieve the interface index.	   Make an initial call to GetIfTable to get the necessary size into dwSize */	if (ERROR_INSUFFICIENT_BUFFER == GetIfTable(pIfTable, &dwSize, 0))		pIfTable = (MIB_IFTABLE *)zbx_realloc(pIfTable, dwSize);	/* Make a second call to GetIfTable to get the actual data we want. */	if (NO_ERROR != (dwRetVal = GetIfTable(pIfTable, &dwSize, 0)))	{		zabbix_log(LOG_LEVEL_DEBUG, "GetIfTable failed with error: %s", strerror_from_system(dwRetVal));		goto clean;	}	buf = (char *)zbx_malloc(buf, sizeof(char) * buf_alloc);	if (pIfTable->dwNumEntries > 0)	{		for (i = 0; i < (int)pIfTable->dwNumEntries; i++)		{			LPTSTR	wdescr;			LPSTR	utf8_descr;			pIfRow.dwIndex = pIfTable->table[i].dwIndex;			if (NO_ERROR != (dwRetVal = GetIfEntry(&pIfRow)))			{				zabbix_log(LOG_LEVEL_DEBUG, "GetIfEntry failed with error: %s",						strerror_from_system(dwRetVal));				continue;			}			zbx_snprintf_alloc(&buf, &buf_alloc, &buf_offset,					"%-25s", get_if_type_string(pIfRow.dwType));			zbx_snprintf_alloc(&buf, &buf_alloc, &buf_offset,					" %-8s", get_if_adminstatus_string(pIfRow.dwAdminStatus));			for (j = 0; j < pIPAddrTable->dwNumEntries; j++)				if (pIPAddrTable->table[j].dwIndex == pIfRow.dwIndex)				{					in_addr.S_un.S_addr = pIPAddrTable->table[j].dwAddr;					zbx_snprintf_alloc(&buf, &buf_alloc, &buf_offset,							" %-15s", inet_ntoa(in_addr));					break;				}			if (j == pIPAddrTable->dwNumEntries)				zbx_strcpy_alloc(&buf, &buf_alloc, &buf_offset, " -");			wdescr = zbx_acp_to_unicode(pIfRow.bDescr);			utf8_descr = zbx_unicode_to_utf8(wdescr);			zbx_snprintf_alloc(&buf, &buf_alloc, &buf_offset, " %s/n", utf8_descr);			zbx_free(utf8_descr);			zbx_free(wdescr);		}	}	SET_TEXT_RESULT(result, buf);	ret = SYSINFO_RET_OK;clean:	zbx_free(pIfTable);	zbx_free(pIPAddrTable);	return ret;}
开发者ID:aries4,项目名称:MIRACLE-ZBX-2.0.3-NoSQL,代码行数:99,


示例29: get_if_stats

/* * returns interface statistics by IP address or interface name */static int	get_if_stats(const char *if_name, MIB_IFROW *pIfRow){	DWORD		dwSize, dwRetVal, i, j;	int		ret = FAIL;	char		ip[16];	/* variables used for GetIfTable and GetIfEntry */	MIB_IFTABLE	*pIfTable = NULL;	/* variables used for GetIpAddrTable */	MIB_IPADDRTABLE	*pIPAddrTable = NULL;	IN_ADDR		in_addr;	/* Allocate memory for our pointers. */	dwSize = sizeof(MIB_IPADDRTABLE);	pIPAddrTable = (MIB_IPADDRTABLE *)zbx_malloc(pIPAddrTable, sizeof(MIB_IPADDRTABLE));	/* Make an initial call to GetIpAddrTable to get the	   necessary size into the dwSize variable */	if (ERROR_INSUFFICIENT_BUFFER == GetIpAddrTable(pIPAddrTable, &dwSize, 0))		pIPAddrTable = (MIB_IPADDRTABLE *)zbx_realloc(pIPAddrTable, dwSize);	/* Make a second call to GetIpAddrTable to get the	   actual data we want */	if (NO_ERROR != (dwRetVal = GetIpAddrTable(pIPAddrTable, &dwSize, 0)))	{		zabbix_log(LOG_LEVEL_DEBUG, "GetIpAddrTable failed with error: %s", strerror_from_system(dwRetVal));		goto clean;	}	/* Allocate memory for our pointers. */	dwSize = sizeof(MIB_IFTABLE);	pIfTable = (MIB_IFTABLE *)zbx_malloc(pIfTable, dwSize);	/* Before calling GetIfEntry, we call GetIfTable to make	   sure there are entries to get and retrieve the interface index.	   Make an initial call to GetIfTable to get the necessary size into dwSize */	if (ERROR_INSUFFICIENT_BUFFER == GetIfTable(pIfTable, &dwSize, 0))		pIfTable = (MIB_IFTABLE *)zbx_realloc(pIfTable, dwSize);	/* Make a second call to GetIfTable to get the actual data we want. */	if (NO_ERROR != (dwRetVal = GetIfTable(pIfTable, &dwSize, 0)))	{		zabbix_log(LOG_LEVEL_DEBUG, "GetIfTable failed with error: %s", strerror_from_system(dwRetVal));		goto clean;	}	for (i = 0; i < pIfTable->dwNumEntries; i++)	{		LPTSTR	wdescr;		LPSTR	utf8_descr;		pIfRow->dwIndex = pIfTable->table[i].dwIndex;		if (NO_ERROR != (dwRetVal = GetIfEntry(pIfRow)))		{			zabbix_log(LOG_LEVEL_DEBUG, "GetIfEntry failed with error: %s",					strerror_from_system(dwRetVal));			continue;		}		wdescr = zbx_acp_to_unicode(pIfRow->bDescr);		utf8_descr = zbx_unicode_to_utf8(wdescr);		if (0 == strcmp(if_name, utf8_descr))			ret = SUCCEED;		zbx_free(utf8_descr);		zbx_free(wdescr);		if (SUCCEED == ret)			break;		for (j = 0; j < pIPAddrTable->dwNumEntries; j++)		{			if (pIPAddrTable->table[j].dwIndex == pIfRow->dwIndex)			{				in_addr.S_un.S_addr = pIPAddrTable->table[j].dwAddr;				zbx_snprintf(ip, sizeof(ip), "%s", inet_ntoa(in_addr));				if (0 == strcmp(if_name, ip))				{					ret = SUCCEED;					break;				}			}		}		if (SUCCEED == ret)			break;	}clean:	zbx_free(pIfTable);	zbx_free(pIPAddrTable);	return ret;}
开发者ID:aries4,项目名称:MIRACLE-ZBX-2.0.3-NoSQL,代码行数:94,



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


C++ GetItemAt函数代码示例
C++ GetInternal函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。