The Windows Sockets getservbyport function retrieves service information corresponding to a port and protocol.
struct servent FAR * getservbyport (
int port,
const char FAR* proto
);
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.
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.
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. |
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. |
Windows NT: Yes
Windows: Yes
Windows CE: Unsupported.
Header: Declared in winsock2.h.
Import Library: Link with ws2_32.lib.
getservbyname, WSAAsyncGetServByPort