CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

如何判断一个SOCKET端口是可用的?

楼主yyz_xyz(众众)2002-05-30 10:57:35 在 VC/MFC / 基础类 提问

调用哪些WINSOCK的函数可以判断哪个端口是可用的,又或者如何向WINDOWS查询一个可用的端口? 问题点数:200、回复次数:8Top

1 楼Bind(宁静雪:找到你,绑定你!)(再战江湖)回复于 2002-05-30 11:05:36 得分 50

bind之后,WSAGetLastErrorTop

2 楼xuying()回复于 2002-05-30 11:05:55 得分 150

可能没有现成的函数。但可以用GetTcpTable实现:  
   
  GetTcpTable  
  The   GetTcpTable   function   retrieves   the   TCP   connection   table.  
   
  DWORD   GetTcpTable(  
      PMIB_TCPTABLE   pTcpTable,     //   buffer   for   the   connection   table  
      PDWORD   pdwSize,                       //   size   of   the   buffer  
      BOOL   bOrder                               //   sort   the   table?  
  );  
  Parameters  
  pTcpTable    
  [out]   Pointer   to   a   buffer   that   receives   the   TCP   connection   table   as   a   MIB_TCPTABLE   structure.    
  pdwSize    
  [in,   out]   On   input,   specifies   the   size   of   the   buffer   pointed   to   by   the   pTcpTable   parameter.    
  On   output,   if   the   buffer   is   not   large   enough   to   hold   the   returned   connection   table,   the   function   sets   this   parameter   equal   to   the   required   buffer   size.    
   
  bOrder    
  [in]   Specifies   whether   the   connection   table   should   be   sorted.   If   this   parameter   is   TRUE,   the   table   is   sorted   in   the   order   of:    
  Local   IP   address    
  Local   port    
  Remote   IP   address    
  Remote   port    
  Return   Values  
  If   the   function   succeeds,   the   return   value   is   NO_ERROR.  
   
  If   the   function   fails,   use   FormatMessage   to   obtain   the   message   string   for   the   returned   error.  
   
  Requirements    
      Windows   NT/2000   or   later:   Requires   Windows   NT   4.0   SP4   or   later.  
      Windows   95/98/Me:   Requires   Windows   98   or   later.  
      Header:   Declared   in   Iphlpapi.h.  
      Library:   Use   Iphlpapi.lib.  
   
  GetTcpTable可以得到所有已连接或者listen的端口号,相当于netstat。没有出现在里面的端口号就是可用的。Top

3 楼freelybird(阿愚)回复于 2002-05-30 11:30:20 得分 0

agreeTop

4 楼mrlp()回复于 2002-06-04 15:10:59 得分 0

请问上面说得函数和结构是哪个版本支持的?  
  我用的是vc6+msdn6  
  甚至找不到函数和结构的任何信息Top

5 楼snsins(初雪草)回复于 2002-06-04 15:31:59 得分 0

端口可以重用  
  不存在端口可用不可用的问题Top

6 楼snsins(初雪草)回复于 2002-06-04 15:33:31 得分 0

GetTcpTable函数信息可在Platform   SDK文档里找到Top

7 楼Yokishiro(狂狼啸月)回复于 2002-06-04 16:07:19 得分 0

在IP   Help   API里面  
  Top

8 楼ychener(贫血)回复于 2002-06-04 17:31:55 得分 0

Create One SOcket and Bind Port  
   
  看看函数返回以及 GetLastError就知道了Top

相关问题

  • 如何判断当前选择的端口是否可用
  • 使用完成端口怎么样判断一个已经连接上的socket的关闭
  • 使用完成端口怎么样判断一个已经连接上的socket的关闭
  • 如何获取机器中可用的端口号及端口名称?
  • 如果得到空闲的可用的端口
  • 如何查看自己哪些端口是可用的?
  • 如何列举所有可用的打印端口????
  • 如何判断属性可用
  • 如何判断http://www.xxx.com是否可用?
  • 如何判断E盘是否可用?

关键词

  • 端口
  • 函数
  • 可用
  • gettcptable
  • buffer
  • connection table
  • sorted
  • parameter
  • size
  • function

得分解答快速导航

  • 帖主:yyz_xyz
  • Bind
  • xuying

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo