Skip to content

Latest commit

 

History

History
201 lines (165 loc) · 5.6 KB

nf-winsock-getservbyname.md

File metadata and controls

201 lines (165 loc) · 5.6 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winsock.getservbyname
getservbyname function (winsock.h)
The getservbyname function (winsock.h) retrieves service information corresponding to a service name and protocol.
_win32_getservbyname_2
getservbyname
getservbyname function [Winsock]
winsock.getservbyname_2
winsock/getservbyname
winsock\getservbyname_2.htm
WinSock
730fa372-f620-4d21-99b9-3e7b79932792
08/15/2022
_win32_getservbyname_2, getservbyname, getservbyname function [Winsock], winsock.getservbyname_2, winsock/getservbyname
winsock.h
Winsock2.h
Windows
Windows 8.1, Windows Vista [desktop apps \| UWP apps]
Windows Server 2003 [desktop apps \| UWP apps]
Ws2_32.lib
Ws2_32.dll
Windows
19H1
getservbyname
winsock/getservbyname
c++
APIRef
kbSyntax
DllExport
Ws2_32.dll
getservbyname

getservbyname function

-description

The getservbyname function retrieves service information corresponding to a service name and protocol.

-parameters

-param name [in]

A pointer to a null-terminated service name.

-param proto [in]

A pointer to a null-terminated protocol name. If this pointer is NULL, the getservbyname function returns the first service entry where name matches the s_name member of the servent structure or the s_aliases member of the servent structure. Otherwise, getservbyname matches both the name and the proto.

-returns

If no error occurs, getservbyname 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 code Meaning
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.
WSAEINTR
A blocking Windows Socket 1.1 call was canceled through WSACancelBlockingCall.

-remarks

The getservbyname function returns a pointer to the servent structure containing the name(s) and service number that match the string in the name parameter. All strings are null-terminated.

The pointer that is returned points to the servent structure 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, 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.

-see-also

WSAAsyncGetServByName

Winsock Functions

Winsock Reference

getservbyport