如何根据服务器名获取对应的服务端口号?

jackyzjh 2003-10-07 11:38:09
如题.
...全文
190 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiflower 2003-10-07
  • 打赏
  • 举报
回复
PortNo:=AClientSocket.LookupService('http');
我不懂电脑 2003-10-07
  • 打赏
  • 举报
回复
The Windows Sockets getsservbyname function gets service information corresponding to a service name and protocol.

struct servent FAR * getservbyname (

const char FAR * name,
const char FAR * proto
);


Parameters

name

[in] A pointer to a null terminated service name.

proto

[in] An optional pointer to a null terminated protocol name. If this pointer is NULL, getservbyname returns the first service entry for which the name matches the s_name or one of the s_aliases. Otherwise, getservbyname matches both the name and the proto.



Remarks

getservbyname returns a pointer to the following structure which contains the name(s) and service number which correspond to the given service name. All strings are null terminated.

struct servent {
char FAR * s_name;
char FAR * FAR * s_aliases;
short s_port;
char FAR * s_proto;
};


The members of this structure are:

Element Usage
s_name Official name of the service.
s_aliases A NULL-terminated array of alternate names.
s_port The port number at which the service can be contacted. Port numbers are returned in network byte order.
s_proto The name of the protocol to use when contacting the service.


The pointer which is returned points to a structure which is allocated by the Windows Sockets library. The application must never attempt to modify this structure or to free any of its components. Furthermore only one copy of this structure is allocated per thread, and so the application should copy any information which it needs before issuing any other Windows Sockets function calls.

Return Values

If no error occurs, getservbyname returns a pointer to the servent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSANOTINITIALISED A successful WSAStartup must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND Authoritative Answer Service not found.
WSATRY_AGAIN Non-Authoritative Service not found, or server failure.
WSANO_RECOVERY Nonrecoverable errors, the services database is not accessible.
WSANO_DATA Valid name, no data record of requested type.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEINTR The (blocking) call was canceled through WSACancelBlockingCall.
jackyzjh 2003-10-07
  • 打赏
  • 举报
回复
应该是根据服务名获取对应的服务端口号?
jackyzjh 2003-10-07
  • 打赏
  • 举报
回复
服务为本地服务(w2k中)
jackyzjh 2003-10-07
  • 打赏
  • 举报
回复
AClientSocket.LookupService('Apache2')
不行,我要得到Apache2或sql服务端口号.

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧