Novell Home

How to use NWCCGetPrimConnRef()

From Developer Community

This program gets your connection number for the primary connection obtained with NWCCGetPrimConnRef() and then converts it to your login name with NWGetServerConnInfo()

Sample Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __MWERKS__
#pragma ANSI_strict off
#endif
#include <nwcalls.h>
#include <nwclxcon.h>
#ifdef __MWERKS__
#pragma ANSI_strict reset
#endif

int main( void) {
	nuint32 conn_ref;
	NWCCConnInfo conn_info;
	NWCONN_HANDLE conn_handle;
	NWFSE_LOGIN_NAME login_name;
	char object_name[ 128];
	SERVER_AND_VCONSOLE_INFO vconsole_info;
	NWRCODE rcode;
	NWCCODE ccode;
	login_name.loginName = ( unsigned char*) object_name;
	login_name.loginNameLen = sizeof( object_name);
	ccode = NWCallsInit( NULL, NULL);
	if ( ccode != 0) {
		printf( "NWCallsInit failed, ccode = %x\n", ccode);
		return EXIT_FAILURE;
	}
	rcode = NWCCGetPrimConnRef( &conn_ref);
	if ( rcode != 0) {
		printf( "NWCCGetPrimConnRef failed, rcode = %x\n", rcode);
		NWCallsTerm( NULL);
		return EXIT_FAILURE;
	}
	rcode = NWCCGetAllConnRefInfo( conn_ref, NWCC_INFO_VERSION_1, &conn_info);
	if ( rcode != 0) {
		printf( "NWCCGetAllConnRefInfo failed, rcode = %x\n", rcode);
		NWCallsTerm( NULL);
		return EXIT_FAILURE;
	}
	printf( "conn_info.connNum = %d\n", conn_info.connNum);
        rcode = NWCCOpenConnByRef( conn_ref, NWCC_OPEN_LICENSED, NWCC_RESERVED, &conn_handle);
	if ( rcode != 0) {
		printf( "NWCCOpenConnByRef failed, rcode = %x\n", rcode);
		NWCallsTerm( NULL);
		return EXIT_FAILURE;
	}
	ccode = NWGetServerConnInfo( conn_handle, CONN_INFO_LOGIN_NAME_MASK, conn_info.connNum, &vconsole_info, NULL, NULL, NULL, &login_name, NULL, NULL, NULL, NULL, NULL);
	if ( ccode != 0) {
		printf( "NWGetServerConnInfo failed, ccode = %x", ccode);
		NWCCCloseConn( conn_handle);
		NWCallsTerm( NULL);
		return EXIT_FAILURE;
	}
	printf( "object_name = %.*s\n", login_name.loginNameLen, object_name);
	NWCCCloseConn( conn_handle);
	NWCallsTerm( NULL);
	return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.