#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <netdb.h>
#include <opcua_proxystub.h>
#include <opcua_trace.h>
#include "democlient.h"
int GetFQHostname( char *szHostname, int len )
{
struct hostent *pEnt = 0;
int ret = gethostname( szHostname, len );
if ( ret != 0 ) return ret;
pEnt = gethostbyname( szHostname );
if ( pEnt == 0 ) return -1;
OpcUa_StrlCpyA( szHostname, pEnt->h_name, len );
szHostname[len - 1] = 0;
return 0;
}
void PrintUsage(const char *szAppName)
{
printf( "Usage: %s [-h] [-v] [-c <config file>] [-u <URL>]\n", szAppName );
printf( " -h: Shows this help\n" );
printf( " -v: Shows detailed version information\n" );
printf( " -c: Sets the configuration file to use (default=client_settings.conf)\n" );
printf( " -u: Sets the URL to use (default is to use the URLs from the configuration file)\n" );
}
int main( int argc, char *argv[] )
{
int ret = EXIT_SUCCESS;
int opt;
char szConfigurationFile[UABASE_PATH_MAX] = "client_settings.conf";
char szHostname[256] = "";
char szUrl[256] = "";
while ( ( opt = getopt( argc, argv, "hvc:u:" ) ) != -1 )
{
switch ( opt )
{
case 'h':
PrintUsage( argv[0] );
exit( EXIT_SUCCESS );
break;
case 'v':
PrintVersionInfo();
exit( EXIT_SUCCESS );
break;
case 'c':
OpcUa_StrlCpyA( szConfigurationFile, optarg, sizeof(szConfigurationFile) );
break;
case 'u':
OpcUa_StrlCpyA( szUrl, optarg, sizeof(szUrl) );
break;
default:
PrintUsage( argv[0] );
exit( EXIT_FAILURE );
}
}
ret = InitializeOpcUaStack();
if ( ret != 0 ) return ret;
if (OpcUa_IsNotGood(uStatus))
{
printf( "Could not open configuration file '%s'\n", szConfigurationFile);
CleanupOpcUaStack();
exit( EXIT_FAILURE );
}
GetFQHostname(szHostname, sizeof(szHostname));
#if OPCUA_SUPPORT_PKI && UABASE_USE_FILESYSTEM
SetupPKIInfrastructure(&g_settings, szHostname);
#endif
uStatus = ClientMain(&g_settings, szHostname, szUrl);
if (OpcUa_IsBad(uStatus)) {ret = EXIT_FAILURE;}
CleanupOpcUaStack();
return ret;
}