Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

getservbyport function

The getservbyport function retrieves service information corresponding to a port and protocol.

Syntax


struct servent* FAR getservbyport(
  _In_       int  port,
  _In_ const char *proto
);

Parameters

port [in]

Port for a service, in network byte order.

proto [in]

Optional pointer to a protocol name. If this is null, getservbyport returns the first service entry for which the port matches the s_port of the servent structure. Otherwise, getservbyport matches both the port and the proto parameters.

Return value

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

Error codeMeaning
WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAHOST_NOT_FOUND

Authoritative Answer Service not found.

WSATRY_AGAIN

A nonauthoritative 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.

WSAEFAULT

The proto parameter is not a valid part of the user address space.

WSAEINTR

A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.

 

Remarks

The getservbyport function returns a pointer to a servent structure as it does in the getservbyname function.

The servent structure is allocated by Windows Sockets. 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, so the application should copy any information it needs before issuing any other Windows Sockets function calls.

Windows Phone 8: This function is supported for Windows Phone Store apps on Windows Phone 8 and later.

Windows 8.1 and Windows Server 2012 R2: This function is supported for Windows Store apps on Windows 8.1, Windows Server 2012 R2, and later.

Requirements

Minimum supported client

Windows 8.1, Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2003 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8

Header

Winsock2.h

Library

Ws2_32.lib

DLL

Ws2_32.dll

See also

Winsock Reference
Winsock Functions
getservbyname
WSAAsyncGetServByPort

 

 

Show:
© 2017 Microsoft