This sample demonstrates how to convert a connection number to the corresponding login name with NWGetServerConnInfo()
#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
#if defined( __MWERKS__) && !defined( N_PLAT_NLM)
#define strupr(s) (_strupr(s),s)
#endif
int main( int argc, char* argv[]) {
char const* server_name;
#ifdef N_PLAT_NLM
char const* login_user_name;
char const* password;
#endif
NWRCODE rcode;
NWCCODE ccode;
NWCONN_HANDLE conn_handle;
int conn_number;
SERVER_AND_VCONSOLE_INFO vconsole_info;
NWFSE_LOGIN_NAME login_name;
char object_name[ 128];
login_name.loginName = ( unsigned char*) object_name;
login_name.loginNameLen = sizeof( object_name);
#ifdef N_PLAT_NLM
if ( argc != 5) {
printf( "Usage: %s <servername> <username> <password> <conn_number>\n", *argv);
return EXIT_FAILURE;
}
#else
if ( argc != 3) {
printf( "Usage: %s <servername> <conn_number>\n", *argv);
return EXIT_FAILURE;
}
#endif
ccode = NWCallsInit( NULL, NULL);
if ( ccode != 0) {
printf( "NWCallsInit failed, ccode = %x", ccode);
return EXIT_FAILURE;
}
server_name = strupr( *++argv);
#ifdef N_PLAT_NLM
login_user_name = strupr( *++argv);
password = strupr( *++argv);
#endif
conn_number = atoi( *++argv);
printf( "conn_number = %d\n", conn_number);
rcode = NWCCOpenConnByName( 0,
server_name,
NWCC_NAME_FORMAT_BIND,
NWCC_OPEN_LICENSED,
NWCC_TRAN_TYPE_WILD,
&conn_handle);
if ( rcode != 0) {
printf( "NWCCOpenConnByName failed, rcode = %x", rcode);
NWCallsTerm( NULL);
return EXIT_FAILURE;
}
#ifdef N_PLAT_NLM
ccode = NWLoginToFileServer( conn_handle, login_user_name, OT_USER, password);
if ( ccode != 0) {
printf( "NWLoginToFileServer failed, ccode = %x", ccode);
NWCCCloseConn( conn_handle);
NWCallsTerm( NULL);
return EXIT_FAILURE;
}
#endif
ccode = NWGetServerConnInfo( conn_handle, CONN_INFO_LOGIN_NAME_MASK, ( unsigned long) conn_number, &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;
}
© 2008 Novell, Inc. All Rights Reserved.