Home   Index   Search   About
Ultimate Pack


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


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime without manual coding. Full C# source codes are available  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2011 Free Tech Secrets ;) greatis just4fun network just4fun