Purpose
NetServerNameEnum enumerates the set of computernames by which a server is known by on the network.
Syntax
#include netcons.h> #include server.h>
NetServerNameEnum
Parameters
pszServerName(const UCHAR LSFAR*) input
Returns
ulrc (APIRET) returns for 32 bit
NetServerNameEnum or Net32ServerNameEnum returns one of the following values
124
Remarks
If you call this API with the buffer length parameter equal to zero, the API returns a value for total entries available. This technique is useful if you do not know the exact buffer size required.
The NetServerNameEnum API can obtain only level 0 data structures.
This API returns the list of server names being used by a server. This may include names in the process of being added or deleted, not just active server names.
The set of server names returned will always list the primary server name first, and if there are no other server names in use, the primary server name will be the only name returned in the return buffer.
This API can be called from OS/2 workstations. Administrative or server operator authority is required to call this API.
Related Functions
Example Code
This example adds a servername called Server18 , then enumerates the server names in use and finally removes the Server18 " servername.
#define PURE_32#define INCL_DOS #define INCL_DOSERRORS #include os2.h> #include stdio.h> #include stdlib.h> #include string.h> #include netcons.h> #include server.h> int main(VOID) { struct server_info_0 LSFAR * pBuffer; /* pointer to enum return info */ ULONG ulBufLen=4096; /* length in bytes of enum buffer */ ULONG ulLevel=0; /* enum return info level */ ULONG ulEntriesRead=0; /* total entries read from enum */ ULONG ulEntriesAvail=0; /* total entries available from enum */ CHAR achServer[CNLEN+1]; /* remote server name or '\0' */ CHAR achName[CNLEN+1]; /* server name to add and delete */ ULONG ulReturnCode=0; /* return code */ strcpy(achName,"Server18"); /* initialize servername to use */ achServer[0] = '\0'; /* initialize for local API call */ ulReturnCode = Net32ServerNameAdd(achServer,achName); if (ulReturnCode == NO_ERROR) { if ((pBuffer = malloc(ulBufLen)) != NULL) { ulReturnCode = Net32ServerNameEnum(achServer, ulLevel, (unsigned char *)pBuffer, ulBufLen, ulEntriesRead, ulEntriesAvail); if (ulReturnCode == NO_ERROR || ulReturnCode == ERROR_MORE_DATA) { printf("Total entries read == %u\n",ulEntriesRead); printf("Total entries available == %u\n",ulEntriesAvail); printf("Server names are \n"); while (ulEntriesRead) { printf("\t%s\n",pBuffer->sv0_name); /* print out name */ pBuffer++; /* advance to next entry */ ulEntriesRead--; /* dec entries displayed */ } /* endwhile */ } else { printf("Net32ServerNameEnum() error return code = %u.\n", ulReturnCode); Net32ServerNameDel(achServer,achName); return 1; } } else { printf("malloc() failed!\n"); return 1; } ulReturnCode = Net32ServerNameDel(achServer,achName); if (ulReturnCode != NO_ERROR) { printf("Net32ServerNameDel() error return code = %u.\n", ulReturnCode); return 1; } } else { printf("Net32ServerNameAdd() error return code = %u.\n", ulReturnCode); return 1; } return NO_ERROR; }