#include <windows.h>
#include <lm.h>
#include <stdio.h>
#include <stdlib.h>
#pragma hdrstop



#define MAXLEN 256



int main( int argc, char *argv[] )
{
	SERVER_TRANSPORT_INFO_1 *buf, *cur;
	DWORD read, total, resumeh, rc, i;
	wchar_t server[MAXLEN];

	if ( argc != 2 )
	{
		puts( "usage: nste \\\\server" );
		return 1;
	}

	mbstowcs( server, argv[1], MAXLEN );

	resumeh = 0;
	do
	{
		buf = NULL;
		rc = NetServerTransportEnum( server, 1, (BYTE **) &buf,
			512, &read, &total, &resumeh );
		if ( rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS )
			break;

		printf( "\ngot %lu entries out of %lu remaining\n", read, total );

		for ( i = 0, cur = buf; i < read; ++ i, ++ cur )
		{
			// Note: the capital S in the format string will expect Unicode
			// strings, as this is a program written/compiled for ANSI.
			// The svti1_transportaddress member is usually the machine name,
			// but since it is regarded as an arbitray sequence of bytes,
			// it is NOT Unicode but rather ANSI.
			
			putchar( '\n' );
			printf( "Name:        %S\n",          cur->svti1_transportname );
			printf( "Address:     \"%.*s\"\n", cur->svti1_transportaddresslength, cur->svti1_transportaddress );
			printf( "Net address: %S\n",          cur->svti1_networkaddress );
			printf( "VC count:    %lu\n",         cur->svti1_numberofvcs );
			printf( "Domain:      %S\n",          cur->svti1_domain );
		}

		if ( buf != NULL )
			NetApiBufferFree( buf );

	} while ( rc == ERROR_MORE_DATA );

	if ( rc != ERROR_SUCCESS )
		printf( "NSTE() returned %lu\n", rc );

	return 0;
}
