EnumProtocols

Important The EnumProtocols function is a Microsoft-specific extension to the Windows Sockets 1.1 specification. This function is obsolete. For the convenience of Windows Sockets 1.1 developers, the reference material is below.

In Windows Sockets 2, this functionality is realized with the function WSAEnumProtocols.

The EnumProtocols function obtains information about a specified set of

network protocols that are active on a local host.

INT EnumProtocols(

LPINT lpiProtocols,
// pointer to array of protocol identifiers
LPVOID lpProtocolBuffer,
// pointer to buffer to receive protocol information
LPDWORD lpdwBufferLength
// pointer to variable that specifies the size of the receiving buffer
);

Parameters

lpiProtocols

Pointer to a null-terminated array of protocol identifiers. The EnumProtocols function obtains information about the protocols specified by this array.

If lpiProtocols is NULL, the function obtains information about all available protocols.

The following protocol identifier values are defined:

Value
Protocol
IPPROTO_TCP
TCP/IP, a connection/stream-oriented protocol
IPPROTO_UDP
User Datagram Protocol (UDP/IP), a connectionless datagram protocol
ISOPROTO_TP4
ISO connection-oriented transport protocol
NSPROTO_IPX
IPX
NSPROTO_SPX
SPX
NSPROTO_SPXII
SPX II

lpProtocolBuffer

Pointer to a buffer that the function fills with an array of PROTOCOL_INFO data structures.

lpdwBufferLength

Pointer to a variable that, on input, specifies the size, in bytes, of the buffer pointed to by lpProtocolBuffer.

On output, the function sets this variable to the minimum buffer size needed to retrieve all of the requested information. For the function to succeed, the buffer must be at least this size.

Return Values

If the function succeeds, the return value is the number of PROTOCOL_INFO data structures written to the buffer pointed to by lpProtocolBuffer.

If the function fails, the return value is SOCKET_ERROR ( pics/SOCK200090001.gif 1). To get extended error information, call GetLastError. GetLastError may return the following extended error code:

Value
Meaning
ERROR_INSUFFICIENT_BUFFER
The buffer pointed to by lpProtocolBuffer was too small to receive all of the relevant PROTOCOL_INFO structures. Call the function with a buffer at least as large as the value returned in *lpdwBufferLength.

Remarks

In the following sample code, the EnumProtocols function obtains information about all protocols that are available on a system. The code then examines each of the protocols in greater detail.

SOCKET

OpenConnection (

PTSTR ServiceName,

PGUID ServiceType,

BOOL Reliable,

BOOL MessageOriented,

BOOL StreamOriented,

BOOL Connectionless,

PINT ProtocolUsed

)

{

// local variables

INT protocols[MAX_PROTOCOLS+1];

BYTE buffer[2048];

DWORD bytesRequired;

INT err;

PPROTOCOL_INFO protocolInfo;

PCSADDR_INFO csaddrInfo;

INT protocolCount;

INT addressCount;

INT i;

DWORD protocolIndex;

SOCKET s;

// First look up the protocols installed on this machine.

//

bytesRequired = sizeof(buffer);

err = EnumProtocols( NULL, buffer, &bytesRequired );

if ( err <= 0 )

return INVALID_SOCKET;

// Walk through the available protocols and pick out the ones which

// support the desired characteristics.

//

protocolCount = err;

protocolInfo = (PPROTOCOL_INFO)buffer;

for ( i = 0, protocolIndex = 0;

i < protocolCount && protocolIndex < MAX_PROTOCOLS;

i++, protocolInfo++ ) {

// If connection-oriented support is requested, then check if

// supported by this protocol. We assume here that connection-

// oriented support implies fully reliable service.

//

if ( Reliable ) {

// Check to see if the protocol is reliable. It must

// guarantee both delivery of all data and the order in

// which the data arrives.

//

if ( (protocolInfo->dwServiceFlags &

XP_GUARANTEED_DELIVERY) == 0

||

(protocolInfo->dwServiceFlags &

XP_GUARANTEED_ORDER) == 0 ) {

continue;

}

// Check to see that the protocol matches the stream/message

// characteristics requested.

//

if ( StreamOriented &&

(protocolInfo->dwServiceFlags & XP_MESSAGE_ORIENTED)

!= 0 &&

(protocolInfo->dwServiceFlags & XP_PSEUDO_STREAM)

== 0 ) {

continue;

}

if ( MessageOriented &&

(protocolInfo->dwServiceFlags & XP_MESSAGE_ORIENTED)

== 0 ) {

continue;

}

}

else if ( Connectionless ) {

// Make sure that this is a connectionless protocol.

//

if ( (protocolInfo->dwServiceFlags & XP_CONNECTIONLESS)

!= 0 )

continue;

}

// This protocol fits all the criteria. Add it to the list of

// protocols in which we're interested.

//

protocols[protocolIndex++] = protocolInfo->iProtocol;

}

See Also

GetAddressByName
, PROTOCOL_INFO

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database