亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6105 | 回復(fù): 2
打印 上一主題 下一主題

緊急求助:怎樣用Windows API在Windows下枚舉IP地址 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-07-06 03:04 |只看該作者 |倒序瀏覽
0可用積分
在AIX/Solaris下有ioctl,不知在windows下怎樣做\r\n注意用gethostname()然后gethostbyname不行的,因為可能有超過一塊網(wǎng)卡,而gethostname+gethostbyname只能得到其中的一個

論壇徽章:
0
2 [報告]
發(fā)表于 2007-07-06 03:04 |只看該作者
【W(wǎng)insock編程】用WSAIoCtl列舉本機所有ip地址示例 \r\n******************************************************************************\\\r\n*  INTRFC.CPP\r\n*\r\n* This program demonstrates how to programmatically enumerate IP interface\r\n* information such as a system\'s IP Address, Subnet mask, and broadcast\r\n* address through the WSAIoctl() API using the SIO_GET_INTERFACE_LIST \r\n* option.  Additionally, this sample demonstrates how to interpret IP\r\n* status flags from each IP interface.  The flags are defined in the\r\n* Windows Sockets 2 Protocol-Specific Annex specification which can be\r\n* found in the January 98 MSDN Platform SDK.\r\n*\r\n*\r\n*       Copyright 1996 - 1998 Microsoft Corporation.\r\n*       All rights reserved.\r\n*       This source code is only intended as a supplement to\r\n*       Microsoft Development Tools and/or WinHelp documentation.\r\n*       See these sources for detailed information regarding the\r\n*       Microsoft samples programs.\r\n\\******************************************************************************/\r\n#define _WIN32_WINNT 0x0400\r\n#define WINVER 0x0400 \r\n#include <windows.h>\r\n#include <ws2tcpip.h>\r\n#include <stdio.h>\r\n\r\nvoid main(void)\r\n{\r\n WORD versionRequested;\r\n int wsError;\r\n WSADATA winsockData; \r\n SOCKET s;\r\n DWORD bytesReturned;\r\n char* pAddrString;\r\n SOCKADDR_IN* pAddrInet;\r\n u_long SetFlags;\r\n INTERFACE_INFO localAddr[10];  // Assume there will be no more than 10 IP interfaces \r\n int numLocalAddr; \r\n\r\n versionRequested = MAKEWORD(2, 2);\r\n\r\n wsError = WSAStartup(versionRequested, &;winsockData); \r\n if (wsError)\r\n { \r\n  fprintf (stderr, \"Startup failed\\n\");\r\n        return;\r\n }\r\n\r\n if((s = WSASocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 0, 0)) == INVALID_SOCKET)\r\n {\r\n  fprintf (stderr, \"Socket creation failed\\n\");\r\n  WSACleanup();\r\n       return;\r\n    }\r\n\r\n // Enumerate all IP interfaces\r\n fprintf(stderr, \"Scanning Interfaces . . .\\n\\n\");\r\n wsError = WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0, &;localAddr,\r\n                      sizeof(localAddr), &;bytesReturned, NULL, NULL);\r\n if (wsError == SOCKET_ERROR)\r\n {\r\n  fprintf(stderr, \"WSAIoctl fails with error %d\\n\", GetLastError());\r\n  closesocket(s);\r\n  WSACleanup();\r\n  return;\r\n }\r\n\r\n closesocket(s);\r\n\r\n // Display interface information\r\n numLocalAddr = (bytesReturned/sizeof(INTERFACE_INFO));\r\n for (int i=0; i<numLocalAddr; i++) \r\n {\r\n  pAddrInet = (SOCKADDR_IN*)&;localAddr[i].iiAddress;\r\n  pAddrString = inet_ntoa(pAddrInet->sin_addr);\r\n  if (pAddrString)\r\n   printf(\"IP: %s  \", pAddrString);\r\n\r\n  pAddrInet = (SOCKADDR_IN*)&;localAddr[i].iiNetmask;\r\n  pAddrString = inet_ntoa(pAddrInet->sin_addr);\r\n  if (pAddrString)\r\n   printf(\" SubnetMask: %s \", pAddrString);\r\n\r\n  pAddrInet = (SOCKADDR_IN*)&;localAddr[i].iiBroadcastAddress;\r\n  pAddrString = inet_ntoa(pAddrInet->sin_addr);\r\n  if (pAddrString)\r\n   printf(\" Bcast Addr: %s\\n\", pAddrString);\r\n\r\n  SetFlags = localAddr[i].iiFlags;\r\n  if (SetFlags &; IFF_UP)\r\n   printf(\"This interface is up\");\r\n  if (SetFlags &; IFF_BROADCAST)\r\n   printf(\", broadcasts are supported\");\r\n  if (SetFlags &; IFF_MULTICAST)\r\n   printf(\", and so are multicasts\");\r\n  if (SetFlags &; IFF_LOOPBACK)\r\n   printf(\". BTW, this is the loopback interface\");\r\n  if (SetFlags &; IFF_POINTTOPOINT)\r\n   printf(\". BTW, this is a point-to-point link\");\r\n  printf(\"\\n\\n\");\r\n }\r\n\r\n WSACleanup();\r\n}

論壇徽章:
0
3 [報告]
發(fā)表于 2009-10-21 23:12 |只看該作者
WSAIoctl()  簡述:控制一個套接口的模式。\r\n  #include <winsock2.h>\r\n  int WSAAPI WSAIoctl(SOCKET s, DWORD\r\n  dwIoControlCode, LPVOID lpvInBuffer, DWORD\r\n  cbInBuffer, LPVOID lpvOutBuffer, DWORD\r\n  cbOutBuffer, LPDWORD lpcbBytesReturned,\r\n  LPWSAOVERLAPPED lpOverlapped,\r\n  LPWSAOVERLAPPED_COMPLETION_ROUTINE\r\n  lpCompletionRoutine);\r\n  s:一個套接口的句柄。\r\n  dwIoControlCode:將進行的操作的控制代碼。\r\n  lpvInBuffer:輸入緩沖區(qū)的地址。\r\n  cbInBuffer:輸入緩沖區(qū)的大小。\r\n  lpvOutBuffer:輸出緩沖區(qū)的地址。\r\n  cbOutBuffer:輸出緩沖區(qū)的大小。\r\n  lpcbBytesReturned:輸出實際字節(jié)數(shù)的地址。\r\n  lpOverlapped:WSAOVERLAPPED結(jié)構(gòu)的地址。\r\n  lpCompletionRoutine:一個指向操作結(jié)束后調(diào)用的例程指針。\r\n  返回值:\r\n  調(diào)用成功后,WSAIoctl ()函數(shù)返回0。否則的話,將返回INVALID_SOCKET錯誤,應(yīng)用程序可通過WSAGetLastError()來獲取相應(yīng)的錯誤代碼。\r\n  錯誤代碼:\r\n  WSANOTINITIALISED                在調(diào)用本API之前應(yīng)成功調(diào)用WSAStartup()。\r\n  WSAENETDOWN                        網(wǎng)絡(luò)子系統(tǒng)失效。\r\n  WSAEINVAL                                cmd不是一個合法的命令;或者一個輸入?yún)?shù)非法;或者命令對于該種類型的套接口不適用。\r\n  WSAEINPROGRESS                在一個回調(diào)函數(shù)運行時調(diào)用了該函數(shù)。\r\n  WSAENOTSOCK                        描述字不是一個套接口。\r\n  WSAEOPNOTSUPP                指定的ioctl命令無法實現(xiàn),例如在SIO_SET_QOS或 SIO_SET_GROUP_QOS中指定的流描述無法實現(xiàn)。\r\n  WSA_IO_PENDING                一個重疊操作被成功啟動,過后將報告完成情況。\r\n  WSAEWOULDBLOCK                套接口標(biāo)志為非阻塞,且所需操作將產(chǎn)生阻塞。\r\n  另請參閱: socket(), ioctlsocket(), WSASocket(),setsockopt(), getsockopt().
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP