testexecmgmt/ucc/Source/mncontroller/CSMncontroller.cpp
changeset 0 3da2a79470a7
equal deleted inserted replaced
-1:000000000000 0:3da2a79470a7
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   
       
    15 * This file was autogenerated by rpcgen, but should be modified by the developer.
       
    16 * Make sure you don't use the -component_mod flag in future or this file will be overwritten.
       
    17 * Wed Oct 01 09:46:52 2003
       
    18 * System Includes
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include <stdio.h>
       
    26 #include <signal.h>
       
    27 #ifndef WIN32
       
    28 #include <unistd.h>
       
    29 #include <net/if.h>
       
    30 #include <sys/ioctl.h>
       
    31 #include <sys/socket.h>
       
    32 #include <netinet/in.h>
       
    33 #include <arpa/inet.h>
       
    34 #endif
       
    35 
       
    36 /****************************************************************************************
       
    37  * 
       
    38  * Local Includes
       
    39  * 
       
    40  ***************************************************************************************/
       
    41 #include "CSvcMncontroller.h"
       
    42 #include "CSMncontroller.h"
       
    43 #include "standard_unix.h"
       
    44 #include "strncpynt.h"
       
    45 
       
    46 
       
    47 /****************************************************************************************
       
    48  * 
       
    49  * Definitions
       
    50  * 
       
    51  ***************************************************************************************/
       
    52 #define TEMPLATE_CONFIG_FILE			"dynmnd.template.conf"
       
    53 #define MOBILE_AGENT_COMMAND_LINE		"./dynmnd --fg --debug --config "
       
    54 #define MAXCOMMANDLINELENGTH			(31 + 256 + 1)
       
    55 #define MAXFOREIGNAGENTCOUNT			32
       
    56 #define MAXINTERFACECONFIGENTRY			(IFNAMSIZ + 128)
       
    57 
       
    58 
       
    59 /****************************************************************************************
       
    60  * 
       
    61  * Implementation
       
    62  * 
       
    63  ***************************************************************************************/
       
    64 CSMncontroller::CSMncontroller()
       
    65 {
       
    66 	iDynamicsCallTimeout = -1;
       
    67 	iAgentProcess = NULL;
       
    68 }
       
    69 
       
    70 CSMncontroller::~CSMncontroller()
       
    71 {
       
    72 	assert( iAgentProcess == NULL );
       
    73 }
       
    74 
       
    75 int CSMncontroller::GetKey()
       
    76 {
       
    77 	return iKey;
       
    78 }
       
    79 
       
    80 void CSMncontroller::SetKey( int aKey )
       
    81 {
       
    82 	iKey = aKey;
       
    83 }
       
    84 
       
    85 
       
    86 /****************************************************************************************
       
    87  * 
       
    88  * PUBLIC FUNCTION: cstr_createagent
       
    89  * 
       
    90  ***************************************************************************************/
       
    91 TResult CSMncontroller::cstr_createagent( void )
       
    92 {
       
    93 	TResult rv;
       
    94 	int errcode;
       
    95 	TDCFError terr;
       
    96 
       
    97 	// initialise the return value
       
    98 	rv.iServiceResult = ERR_NONE;
       
    99 	rv.iSubComponentResult = 0;
       
   100 	rv.iData0 = 0;
       
   101 	rv.iData1 = 0;
       
   102 
       
   103 	// create a local copy of the configuration file
       
   104 	terr = iDynamicsConfigFile.SetReferenceFile( TEMPLATE_CONFIG_FILE );
       
   105 	if( terr != DCE_NONE ) {
       
   106 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   107 		rv.iSubComponentResult = (int)terr;
       
   108 		return rv;
       
   109 	}
       
   110 	terr = iDynamicsConfigFile.CreateLocalCopy( &errcode );
       
   111 	if( terr != DCE_NONE ) {
       
   112 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   113 		rv.iSubComponentResult = (int)terr;
       
   114 		return rv;
       
   115 	}
       
   116 
       
   117 	// done - success
       
   118 	return rv;
       
   119 }
       
   120 
       
   121 
       
   122 /****************************************************************************************
       
   123  * 
       
   124  * PUBLIC FUNCTION: dstr_removeagent
       
   125  * 
       
   126  ***************************************************************************************/
       
   127 int CSMncontroller::dstr_removeagent( int aArgs, int *aDeleteInstance )
       
   128 {
       
   129 	int rv = ERR_NONE, errcode;
       
   130 	TDCFError terr;
       
   131 
       
   132 	// make sure that the proces isn't running
       
   133 	if( iAgentProcess != NULL ) {
       
   134 		*aDeleteInstance = 0;
       
   135 		rv = ERR_INVALIDSTATE;
       
   136 		return rv;
       
   137 	}
       
   138 
       
   139 	// clean up the config file
       
   140 	terr = iDynamicsConfigFile.RemoveLocalCopy( &errcode );
       
   141 	if( terr != DCE_NONE ) {
       
   142 		rv = ERR_CONFIG_FILE_ERROR;
       
   143 		return rv;
       
   144 	}
       
   145 
       
   146 	// done - success
       
   147 	return rv;
       
   148 }
       
   149 
       
   150 
       
   151 /****************************************************************************************
       
   152  * 
       
   153  * PUBLIC FUNCTION: startmobileagent
       
   154  * 
       
   155  ***************************************************************************************/
       
   156 TResult CSMncontroller::startmobileagent( int aArgs )
       
   157 {
       
   158 	TResult rv;
       
   159 	int errcode;
       
   160 	TCAProcessError perr;
       
   161 	char command_line_str[MAXCOMMANDLINELENGTH];
       
   162 
       
   163 	// initialise the return value
       
   164 	rv.iServiceResult = ERR_NONE;
       
   165 	rv.iSubComponentResult = 0;
       
   166 	rv.iData0 = 0;
       
   167 	rv.iData1 = 0;
       
   168 
       
   169 	// check that there is currently no process
       
   170 	if( iAgentProcess != NULL ) {
       
   171 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   172 		return rv;
       
   173 	}
       
   174 
       
   175 	// create the new process object
       
   176 	iAgentProcess = new CAProcess();
       
   177 	assert( iAgentProcess != NULL );
       
   178 
       
   179 	// construct the command line
       
   180 	snprintf( command_line_str, MAXCOMMANDLINELENGTH, "%s%s", MOBILE_AGENT_COMMAND_LINE, iDynamicsConfigFile.GetLocalFilename() );
       
   181 
       
   182 	// start the actual process
       
   183 	perr = iAgentProcess->StartProcess( command_line_str, &errcode, false, false, false ); 
       
   184 	if( perr != CAE_NONE ) {
       
   185 		rv.iServiceResult = ERR_START_PROCESS_ERROR;
       
   186 		rv.iSubComponentResult = (int)perr;
       
   187 		delete iAgentProcess;
       
   188 		iAgentProcess = NULL;
       
   189 		return rv;
       
   190 	}
       
   191 
       
   192 	// done - success
       
   193 	rv.iServiceResult = ERR_NONE;
       
   194 	return rv;
       
   195 }
       
   196 
       
   197 
       
   198 /****************************************************************************************
       
   199  * 
       
   200  * PUBLIC FUNCTION: stopmobileagent
       
   201  * 
       
   202  ***************************************************************************************/
       
   203 TResult CSMncontroller::stopmobileagent( int aArgs )
       
   204 {
       
   205 	TResult rv;
       
   206 	TCAProcessError perr;
       
   207 	TProcessStatus pstatus;
       
   208 
       
   209 	// initialise the return value
       
   210 	rv.iServiceResult = ERR_NONE;
       
   211 	rv.iSubComponentResult = 0;
       
   212 	rv.iData0 = 0;
       
   213 	rv.iData1 = 0;
       
   214 
       
   215 	// if the process isn't started then invalid state
       
   216 	if( iAgentProcess == NULL ) {
       
   217 	  rv.iServiceResult = ERR_INVALIDSTATE;
       
   218 	  return rv;
       
   219 	}
       
   220 
       
   221 	// if the process isn't running then it has died outside the scope of this controller, clean up the state, return an error since
       
   222 	// this is noteworthy and should be either expected or not happen.
       
   223 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   224 	assert( perr == CAE_NONE );
       
   225 	if( pstatus != PS_STARTED ) {
       
   226 	  assert( (pstatus == PS_STOPPED) || (pstatus == PS_ABANDONNED) );
       
   227 	  delete iAgentProcess;
       
   228 	  iAgentProcess = NULL;
       
   229 	  rv.iServiceResult = ERR_PROCESS_TERMINATED_OUTSIDE_SCOPE;
       
   230 	  return rv;
       
   231 	}
       
   232 
       
   233 	// request the process to stop
       
   234 	perr = iAgentProcess->RequestStop( SIGTERM );
       
   235 	if( perr != CAE_NONE ) {
       
   236 	  rv.iServiceResult = ERR_STOP_PROCESS_ERROR;
       
   237 	  rv.iSubComponentResult = (int)perr;
       
   238 	  return rv;
       
   239 	}
       
   240 
       
   241 	// wait for the process to stop
       
   242 	perr = iAgentProcess->WaitForProcessToTerminate( -1 );
       
   243 	if( perr != CAE_NONE ) {
       
   244 	  rv.iServiceResult = ERR_WAIT_PROCESS_ERROR;
       
   245 	  rv.iSubComponentResult = (int)perr;
       
   246 	  return rv;
       
   247 	}
       
   248 
       
   249 	// remove the process
       
   250 	delete iAgentProcess;
       
   251 	iAgentProcess = NULL;
       
   252 
       
   253 	// done - success
       
   254 	return rv;
       
   255 }
       
   256 
       
   257 
       
   258 /****************************************************************************************
       
   259  * 
       
   260  * PUBLIC FUNCTION: getmobileagentstatus
       
   261  * 
       
   262  ***************************************************************************************/
       
   263 TResult CSMncontroller::getmobileagentstatus( int aArgs )
       
   264 {
       
   265 	TResult rv;
       
   266 	TCAProcessError perr;
       
   267 	TProcessStatus pstatus;
       
   268 
       
   269 	// init the rv - note that we include the result even though it is always ERR_NONE
       
   270 	// here because the stub may return an error
       
   271 	memset( &rv, 0, sizeof(rv) );
       
   272 	rv.iServiceResult = ERR_NONE;
       
   273 
       
   274 	// if the process doesn't exist then we return PS_INVALID
       
   275 	if( iAgentProcess == NULL ) {
       
   276 		rv.iData0 = PS_INVALID;
       
   277 		return rv;
       
   278 	}
       
   279 
       
   280 	// otherwise just return whatever iAgentProcess->GetProcessStatus() returns
       
   281 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   282 	assert( perr == CAE_NONE );
       
   283 	rv.iData0 = (int)pstatus;
       
   284 	return rv;
       
   285 }
       
   286 
       
   287 
       
   288 /****************************************************************************************
       
   289  * 
       
   290  * PUBLIC FUNCTION: setsingleoption
       
   291  * 
       
   292  ***************************************************************************************/
       
   293 TResult CSMncontroller::setsingleoption( TOptionDesc aArgs )
       
   294 {
       
   295 	TResult rv;
       
   296 	int errcode;
       
   297 	TDCFError cerr;
       
   298 
       
   299 	// initialise the return value
       
   300 	rv.iServiceResult = ERR_NONE;
       
   301 	rv.iSubComponentResult = 0;
       
   302 	rv.iData0 = 0;
       
   303 	rv.iData1 = 0;
       
   304 
       
   305 	// make sure that the process isn't running
       
   306 	if( iAgentProcess != NULL ) {
       
   307 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   308 		return rv;
       
   309 	}
       
   310 
       
   311 	// modify the config file
       
   312 	cerr = iDynamicsConfigFile.SetSingleOption( aArgs.iOptionToken, aArgs.iOptionValue, &errcode );
       
   313 	if( cerr != DCE_NONE ) {
       
   314 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   315 		rv.iSubComponentResult = (int)cerr;
       
   316 		rv.iData0 = errcode;
       
   317 		return rv;
       
   318 	}
       
   319 
       
   320 	// return success
       
   321 	rv.iServiceResult = ERR_NONE;
       
   322 	return rv;
       
   323 }
       
   324 
       
   325 
       
   326 /****************************************************************************************
       
   327  * 
       
   328  * PUBLIC FUNCTION: removesingleoption
       
   329  * 
       
   330  ***************************************************************************************/
       
   331 TResult CSMncontroller::removesingleoption( TOptionDesc aArgs )
       
   332 {
       
   333 	TResult rv;
       
   334 	int errcode;
       
   335 	TDCFError cerr;
       
   336 
       
   337 	// initialise the return value
       
   338 	rv.iServiceResult = ERR_NONE;
       
   339 	rv.iSubComponentResult = 0;
       
   340 	rv.iData0 = 0;
       
   341 	rv.iData1 = 0;
       
   342 
       
   343 	// make sure that the process isn't running
       
   344 	if( iAgentProcess != NULL ) {
       
   345 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   346 		return rv;
       
   347 	}
       
   348 
       
   349 	// modify the config file
       
   350 	cerr = iDynamicsConfigFile.RemoveSingleOption( aArgs.iOptionToken, &errcode );
       
   351 	if( cerr != DCE_NONE ) {
       
   352 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   353 		rv.iSubComponentResult = (int)cerr;
       
   354 		rv.iData0 = errcode;
       
   355 		return rv;
       
   356 	}
       
   357 
       
   358 	// return success
       
   359 	rv.iServiceResult = ERR_NONE;
       
   360 	return rv;
       
   361 }
       
   362 
       
   363 
       
   364 /****************************************************************************************
       
   365  * 
       
   366  * PUBLIC FUNCTION: addlistoption
       
   367  * 
       
   368  ***************************************************************************************/
       
   369 TResult CSMncontroller::addlistoption( TOptionDesc aArgs )
       
   370 {
       
   371 	TResult rv;
       
   372 	int errcode;
       
   373 	TDCFError cerr;
       
   374 
       
   375 	// initialise the return value
       
   376 	rv.iServiceResult = ERR_NONE;
       
   377 	rv.iSubComponentResult = 0;
       
   378 	rv.iData0 = 0;
       
   379 	rv.iData1 = 0;
       
   380 
       
   381 	// make sure that the process isn't running
       
   382 	if( iAgentProcess != NULL ) {
       
   383 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   384 		return rv;
       
   385 	}
       
   386 
       
   387 	// modify the config file
       
   388 	cerr = iDynamicsConfigFile.AddListOption( aArgs.iOptionBlockStart, aArgs.iOptionBlockEnd, aArgs.iOptionValue, &errcode );
       
   389 	if( cerr != DCE_NONE ) {
       
   390 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   391 		rv.iSubComponentResult = (int)cerr;
       
   392 		rv.iData0 = errcode;
       
   393 		return rv;
       
   394 	}
       
   395 
       
   396 	// return success
       
   397 	rv.iServiceResult = ERR_NONE;
       
   398 	return rv;
       
   399 }
       
   400 
       
   401 
       
   402 /****************************************************************************************
       
   403  * 
       
   404  * PUBLIC FUNCTION: removelistoption
       
   405  * 
       
   406  ***************************************************************************************/
       
   407 TResult CSMncontroller::removelistoption( TOptionDesc aArgs )
       
   408 {
       
   409 	TResult rv;
       
   410 	int errcode;
       
   411 	TDCFError cerr;
       
   412 
       
   413 	// initialise the return value
       
   414 	rv.iServiceResult = ERR_NONE;
       
   415 	rv.iSubComponentResult = 0;
       
   416 	rv.iData0 = 0;
       
   417 	rv.iData1 = 0;
       
   418 
       
   419 	// make sure that the process isn't running
       
   420 	if( iAgentProcess != NULL ) {
       
   421 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   422 		return rv;
       
   423 	}
       
   424 
       
   425 	// modify the config file
       
   426 	cerr = iDynamicsConfigFile.RemoveListOption( aArgs.iOptionBlockStart, aArgs.iOptionBlockEnd, aArgs.iOptionToken, &errcode );
       
   427 	if( cerr != DCE_NONE ) {
       
   428 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   429 		rv.iSubComponentResult = (int)cerr;
       
   430 		rv.iData0 = errcode;
       
   431 		return rv;
       
   432 	}
       
   433 
       
   434 	// return success
       
   435 	rv.iServiceResult = ERR_NONE;
       
   436 	return rv;
       
   437 }
       
   438 
       
   439 
       
   440 /****************************************************************************************
       
   441  * 
       
   442  * PUBLIC FUNCTION: getcareofaddress
       
   443  * 
       
   444  ***************************************************************************************/
       
   445 TResult CSMncontroller::sethomeaddress( THomeAddressDesc aArgs )
       
   446 {
       
   447 	TResult rv;
       
   448 	char dynamics_config[MAXINTERFACECONFIGENTRY];
       
   449 	struct in_addr home_address, home_network_address, home_agent_address;
       
   450 	TDCFError terr;
       
   451 	int errcode;
       
   452 
       
   453 	// initialise the return value
       
   454 	rv.iServiceResult = ERR_NONE;
       
   455 	rv.iSubComponentResult = 0;
       
   456 	rv.iData0 = 0;
       
   457 	rv.iData1 = 0;
       
   458 
       
   459 	// make sure that the process isn't running
       
   460 	if( iAgentProcess != NULL ) {
       
   461 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   462 		return rv;
       
   463 	}
       
   464 
       
   465 	// validate the arguments
       
   466 	if( aArgs.iHomeAddress == -1 ) {
       
   467 	  rv.iServiceResult = ERR_INVALIDARG;
       
   468 	  rv.iData0 = 2;
       
   469 	  return rv;
       
   470 	}
       
   471 	if( (aArgs.iHomeAddressPrefix < 1) || (aArgs.iHomeAddressPrefix > 31) ) {
       
   472 		rv.iServiceResult = ERR_INVALIDARG;
       
   473 		rv.iData0 = 3;
       
   474 		return rv;
       
   475 	}
       
   476 	if( aArgs.iHomeAgentAddress == -1 ) {
       
   477 	  rv.iServiceResult = ERR_INVALIDARG;
       
   478 	  rv.iData0 = 4;
       
   479 	  return rv;
       
   480 	}
       
   481 
       
   482 	// if the home address specified is zero, then we take this as meaning that the user
       
   483 	// wants to reset the interface back to it's original (PPP configured) address. This
       
   484 	// doesn't effect the entries in the configuration file at all
       
   485 	if( aArgs.iHomeAddress == 0 ) {
       
   486 	  return rv;
       
   487 	}
       
   488 
       
   489 	// set the home address on the interface
       
   490 	rv = SetInterfaceAddress( aArgs.iInterfaceName, aArgs.iHomeAddress );
       
   491 	if( rv.iServiceResult != ERR_NONE ) {
       
   492 	  return rv;
       
   493 	}
       
   494 
       
   495 	// set the home address in the dynamics config file
       
   496 	home_address.ADDRESS_INTEGER = aArgs.iHomeAddress;
       
   497 	snprintf( dynamics_config, MAXINTERFACECONFIGENTRY, "MNHomeIPAddress %s", inet_ntoa(home_address) );
       
   498 	terr = iDynamicsConfigFile.SetSingleOption( "MNHomeIPAddress", dynamics_config, &errcode );
       
   499 	if( terr != DCE_NONE ) {
       
   500 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   501 		rv.iSubComponentResult = (int)terr;
       
   502 		rv.iData0 = errcode;
       
   503 		return rv;
       
   504 	}
       
   505 
       
   506 	// set the home network prefix in the dynamics config file
       
   507 	home_network_address = GetNetworkAddressFromHostAddress( aArgs.iHomeAddress, aArgs.iHomeAddressPrefix );
       
   508 	snprintf( dynamics_config, MAXINTERFACECONFIGENTRY, "HomeNetPrefix %s/%d", inet_ntoa(home_network_address), aArgs.iHomeAddressPrefix );
       
   509 	terr = iDynamicsConfigFile.SetSingleOption( "HomeNetPrefix", dynamics_config, &errcode );
       
   510 	if( terr != DCE_NONE ) {
       
   511 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   512 		rv.iSubComponentResult = (int)terr;
       
   513 		rv.iData0 = errcode;
       
   514 		return rv;
       
   515 	}
       
   516 
       
   517 	// set the home agent address 
       
   518 	home_agent_address.ADDRESS_INTEGER = aArgs.iHomeAgentAddress;
       
   519 	snprintf( dynamics_config, MAXINTERFACECONFIGENTRY, "HAIPAddress %s", inet_ntoa(home_agent_address) );
       
   520 	fprintf( stderr, "DEBUG: setting option '%s'\n", dynamics_config );
       
   521 	terr = iDynamicsConfigFile.SetSingleOption( "HAIPAddress", dynamics_config, &errcode );
       
   522 	if( terr != DCE_NONE ) {
       
   523 		rv.iServiceResult = ERR_CONFIG_FILE_ERROR;
       
   524 		rv.iSubComponentResult = (int)terr;
       
   525 		rv.iData0 = errcode;
       
   526 		return rv;
       
   527 	}
       
   528 
       
   529 	// done
       
   530 	return rv;
       
   531 }
       
   532 
       
   533 
       
   534 /****************************************************************************************
       
   535  * 
       
   536  * PUBLIC FUNCTION: getcareofaddress
       
   537  * 
       
   538  ***************************************************************************************/
       
   539 TResult CSMncontroller::getcareofaddress( int aArgs )
       
   540 {
       
   541 	TResult rv;
       
   542 	struct in_addr addr = { 0 };
       
   543 	TDynamicsCallInfo cres;
       
   544 	TCAProcessError perr;
       
   545 	TProcessStatus pstatus;
       
   546 
       
   547 	// initialise the return value
       
   548 	rv.iServiceResult = ERR_NONE;
       
   549 	rv.iSubComponentResult = 0;
       
   550 	rv.iData0 = 0;
       
   551 	rv.iData1 = 0;
       
   552 
       
   553 	// check that the agent was running
       
   554 	if( iAgentProcess == NULL ) {
       
   555 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   556 		return rv;
       
   557 	}
       
   558 
       
   559 	// check that the agent is still runnning
       
   560 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   561 	assert( perr == CAE_NONE );
       
   562 	if( pstatus != PS_STARTED ) {
       
   563 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   564 		return rv;
       
   565 	}
       
   566 
       
   567 	// use the dynamics command wrapper to make the call
       
   568 	cres = iDynamicsCommand.MobileNodeAgentGetCareofAddress( &addr );
       
   569 	
       
   570 	// if the call failed then set the TResult correctly
       
   571 	if( cres.iResult != DC_SUCCESS ) {
       
   572 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   573 		rv.iSubComponentResult = cres.iResult;
       
   574 		rv.iData0 = cres.iErrorCode;
       
   575 		rv.iData1 = cres.iErrorDetail;
       
   576 		return rv;
       
   577 	}
       
   578 
       
   579 	// otherwise pack up the successful return info
       
   580 	rv.iServiceResult = ERR_NONE;
       
   581 	rv.iData0 = addr.ADDRESS_INTEGER;
       
   582 	return rv;
       
   583 }
       
   584 
       
   585 
       
   586 /****************************************************************************************
       
   587  * 
       
   588  * PUBLIC FUNCTION: getstatus
       
   589  * 
       
   590  ***************************************************************************************/
       
   591 TMobileNodeStatus CSMncontroller::getstatus( int aArgs )
       
   592 {
       
   593 	TMobileNodeStatus rv;
       
   594 	TCAProcessError perr;
       
   595 	TProcessStatus pstatus;
       
   596 	TDynamicsCallInfo cres;
       
   597 	TMobileNodeAgentStatusInfo mobile_node_status;
       
   598 
       
   599 	// init the return value
       
   600 	memset( &rv, 0, sizeof(rv) );
       
   601 	rv.iCallResult.iServiceResult = ERR_NONE;
       
   602 
       
   603 	// check that the agent was running
       
   604 	if( iAgentProcess == NULL ) {
       
   605 		rv.iCallResult.iServiceResult = ERR_INVALIDSTATE;
       
   606 		return rv;
       
   607 	}
       
   608 
       
   609 	// check that the agent is still runnning
       
   610 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   611 	assert( perr == CAE_NONE );
       
   612 	if( pstatus != PS_STARTED ) {
       
   613 		rv.iCallResult.iServiceResult = ERR_INVALIDSTATE;
       
   614 		return rv;
       
   615 	}
       
   616 
       
   617 	// make the call
       
   618 	cres = iDynamicsCommand.MobileNodeAgentGetStatus( &mobile_node_status );
       
   619 	if( cres.iResult != DC_SUCCESS ) {
       
   620 		rv.iCallResult.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   621 		rv.iCallResult.iSubComponentResult = cres.iResult;
       
   622 		rv.iCallResult.iData0 = cres.iErrorCode;
       
   623 		rv.iCallResult.iData1 = cres.iErrorDetail;
       
   624 		return rv;
       
   625 	}
       
   626 
       
   627 	// copy the data from mobile_node_status to the rv
       
   628 	rv.iColocatedAddress = mobile_node_status.iColocatedAddress;
       
   629 	rv.iConnected = mobile_node_status.iConnected;
       
   630 	rv.iForeignAgentAddress = mobile_node_status.iForeignAgentAddress;
       
   631 	rv.iHomeAddress = mobile_node_status.iHomeAddress;
       
   632 	rv.iHomeAgentAddress = mobile_node_status.iHomeAgentAddress;
       
   633 	memcpy( rv.iInfoText, mobile_node_status.iInfoText, X_MAXINFOLEN );
       
   634 	memcpy( rv.iLastErrorString, mobile_node_status.iLastErrorString, X_MAXERRORSTRING );
       
   635 	rv.iLifetimeRemaining = mobile_node_status.iLifetimeRemaining;
       
   636 	rv.iLocalAddress = mobile_node_status.iLocalAddress;
       
   637 	rv.iReplyCode = mobile_node_status.iReplyCode;
       
   638 	rv.iSecondsSinceLastReply = mobile_node_status.iSecondsSinceLastReply;
       
   639 	rv.iSecondsSinceLastRequest = mobile_node_status.iTunnelMode;
       
   640 	rv.iTunnelUp = mobile_node_status.iTunnelUp;
       
   641 	return rv;
       
   642 }
       
   643 
       
   644 
       
   645 /****************************************************************************************
       
   646  * 
       
   647  * PUBLIC FUNCTION: connect
       
   648  * 
       
   649  ***************************************************************************************/
       
   650 TResult CSMncontroller::connect( TTunnelingModeDesc aArgs )
       
   651 {
       
   652 	TResult rv;
       
   653 	TDynamicsCallInfo cres;
       
   654 	TCAProcessError perr;
       
   655 	TProcessStatus pstatus;
       
   656 
       
   657 	// initialise the return value
       
   658 	rv.iServiceResult = ERR_NONE;
       
   659 	rv.iSubComponentResult = 0;
       
   660 	rv.iData0 = 0;
       
   661 	rv.iData1 = 0;
       
   662 
       
   663 	// check that the agent was running
       
   664 	if( iAgentProcess == NULL ) {
       
   665 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   666 		return rv;
       
   667 	}
       
   668 
       
   669 	// check that the agent is still runnning
       
   670 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   671 	assert( perr == CAE_NONE );
       
   672 	if( pstatus != PS_STARTED ) {
       
   673 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   674 		return rv;
       
   675 	}
       
   676 
       
   677 	// call the wrapper
       
   678 	cres = iDynamicsCommand.MobileNodeAgentConnect();
       
   679 	if( cres.iResult != DC_SUCCESS ) {
       
   680 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   681 		rv.iSubComponentResult = cres.iResult;
       
   682 		rv.iData0 = cres.iErrorCode;
       
   683 		rv.iData1 = cres.iErrorDetail;
       
   684 		return rv;
       
   685 	}
       
   686 
       
   687 	// success
       
   688 	return rv;
       
   689 }
       
   690 
       
   691 
       
   692 /****************************************************************************************
       
   693  * 
       
   694  * PUBLIC FUNCTION: disconnect
       
   695  * 
       
   696  ***************************************************************************************/
       
   697 TResult CSMncontroller::disconnect( int aArgs )
       
   698 {
       
   699 	TResult rv;
       
   700 	TDynamicsCallInfo cres;
       
   701 	TCAProcessError perr;
       
   702 	TProcessStatus pstatus;
       
   703 
       
   704 	// initialise the return value
       
   705 	rv.iServiceResult = ERR_NONE;
       
   706 	rv.iSubComponentResult = 0;
       
   707 	rv.iData0 = 0;
       
   708 	rv.iData1 = 0;
       
   709 
       
   710 	// check that the agent was running
       
   711 	if( iAgentProcess == NULL ) {
       
   712 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   713 		return rv;
       
   714 	}
       
   715 
       
   716 	// check that the agent is still runnning
       
   717 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   718 	assert( perr == CAE_NONE );
       
   719 	if( pstatus != PS_STARTED ) {
       
   720 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   721 		return rv;
       
   722 	}
       
   723 
       
   724 	// call the wrapper
       
   725 	cres = iDynamicsCommand.MobileNodeAgentDisconnect();
       
   726 	if( cres.iResult != DC_SUCCESS ) {
       
   727 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   728 		rv.iSubComponentResult = cres.iResult;
       
   729 		rv.iData0 = cres.iErrorCode;
       
   730 		rv.iData1 = cres.iErrorDetail;
       
   731 		return rv;
       
   732 	}
       
   733 
       
   734 	// success
       
   735 	return rv;
       
   736 }
       
   737 
       
   738 
       
   739 /****************************************************************************************
       
   740  * 
       
   741  * PUBLIC FUNCTION: confirm
       
   742  * 
       
   743  ***************************************************************************************/
       
   744 TResult CSMncontroller::confirm( int aArgs )
       
   745 {
       
   746 	TResult rv;
       
   747 	TDynamicsCallInfo cres;
       
   748 	TCAProcessError perr;
       
   749 	TProcessStatus pstatus;
       
   750 
       
   751 	// initialise the return value
       
   752 	rv.iServiceResult = ERR_NONE;
       
   753 	rv.iSubComponentResult = 0;
       
   754 	rv.iData0 = 0;
       
   755 	rv.iData1 = 0;
       
   756 
       
   757 	// check that the agent was running
       
   758 	if( iAgentProcess == NULL ) {
       
   759 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   760 		return rv;
       
   761 	}
       
   762 
       
   763 	// check that the agent is still runnning
       
   764 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   765 	assert( perr == CAE_NONE );
       
   766 	if( pstatus != PS_STARTED ) {
       
   767 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   768 		return rv;
       
   769 	}
       
   770 
       
   771 	// call the wrapper
       
   772 	cres = iDynamicsCommand.MobileNodeAgentConfirm();
       
   773 	if( cres.iResult != DC_SUCCESS ) {
       
   774 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   775 		rv.iSubComponentResult = cres.iResult;
       
   776 		rv.iData0 = cres.iErrorCode;
       
   777 		rv.iData1 = cres.iErrorDetail;
       
   778 		return rv;
       
   779 	}
       
   780 
       
   781 	// success
       
   782 	return rv;
       
   783 }
       
   784 
       
   785 
       
   786 /****************************************************************************************
       
   787  * 
       
   788  * PUBLIC FUNCTION: rescaninterfaces
       
   789  * 
       
   790  ***************************************************************************************/
       
   791 TResult CSMncontroller::rescaninterfaces( int aArgs )
       
   792 {
       
   793 	TResult rv;
       
   794 	TDynamicsCallInfo cres;
       
   795 	TCAProcessError perr;
       
   796 	TProcessStatus pstatus;
       
   797 
       
   798 	// initialise the return value
       
   799 	rv.iServiceResult = ERR_NONE;
       
   800 	rv.iSubComponentResult = 0;
       
   801 	rv.iData0 = 0;
       
   802 	rv.iData1 = 0;
       
   803 
       
   804 	// check that the agent was running
       
   805 	if( iAgentProcess == NULL ) {
       
   806 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   807 		return rv;
       
   808 	}
       
   809 
       
   810 	// check that the agent is still runnning
       
   811 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   812 	assert( perr == CAE_NONE );
       
   813 	if( pstatus != PS_STARTED ) {
       
   814 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   815 		return rv;
       
   816 	}
       
   817 
       
   818 	// call the wrapper
       
   819 	cres = iDynamicsCommand.MobileNodeAgentRescan();
       
   820 	if( cres.iResult != DC_SUCCESS ) {
       
   821 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   822 		rv.iSubComponentResult = cres.iResult;
       
   823 		rv.iData0 = cres.iErrorCode;
       
   824 		rv.iData1 = cres.iErrorDetail;
       
   825 		return rv;
       
   826 	}
       
   827 
       
   828 	// success
       
   829 	return rv;
       
   830 }
       
   831 
       
   832 
       
   833 /****************************************************************************************
       
   834  *
       
   835  * PUBLIC FUNCTION: setfapolicy - aPolicyDesc is a bitfield with each bit representing
       
   836  * a particular policy that should be turned on or off. The values for each
       
   837  * policy are in the interface file (.x). We try and set the policy for each
       
   838  * bit regardless of whether some calls fail. The result is the OR of all the
       
   839  * results (i.e. if one fails the op fails). To get more info about which
       
   840  * succeeded you can just call getpolicy.
       
   841  *
       
   842  ***************************************************************************************/
       
   843 TResult CSMncontroller::setfapolicy( TPolicyRequest aArgs )
       
   844 {
       
   845 	TResult rv;
       
   846 	TDynamicsCallInfo cres;
       
   847 	TCAProcessError perr;
       
   848 	TProcessStatus pstatus;
       
   849 
       
   850 	// initialise the return value
       
   851 	rv.iServiceResult = ERR_NONE;
       
   852 	rv.iSubComponentResult = 0;
       
   853 	rv.iData0 = 0;
       
   854 	rv.iData1 = 0;
       
   855 
       
   856 	// check that the agent was running
       
   857 	if( iAgentProcess == NULL ) {
       
   858 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   859 		return rv;
       
   860 	}
       
   861 
       
   862 	// check that the agent is still runnning
       
   863 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   864 	assert( perr == CAE_NONE );
       
   865 	if( pstatus != PS_STARTED ) {
       
   866 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   867 		return rv;
       
   868 	}
       
   869 
       
   870 	// call the wrapper
       
   871 	cres = iDynamicsCommand.MobileNodeAgentSetPolicy( aArgs.iPolicy );
       
   872 	if( cres.iResult != DC_SUCCESS ) {
       
   873 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   874 		rv.iSubComponentResult = cres.iResult;
       
   875 		rv.iData0 = cres.iErrorCode;
       
   876 		rv.iData1 = cres.iErrorDetail;
       
   877 		return rv;
       
   878 	}
       
   879 
       
   880 	// success
       
   881 	return rv;
       
   882 }
       
   883 
       
   884 
       
   885 /****************************************************************************************
       
   886  * 
       
   887  * PUBLIC FUNCTION: getfapolicy
       
   888  * 
       
   889  ***************************************************************************************/
       
   890 TResult CSMncontroller::getfapolicy( int aArgs )
       
   891 {
       
   892 	TResult rv;
       
   893 	TDynamicsCallInfo cres;
       
   894 	int policy_vector;
       
   895 	TCAProcessError perr;
       
   896 	TProcessStatus pstatus;
       
   897 
       
   898 	// initialise the return value
       
   899 	rv.iServiceResult = ERR_NONE;
       
   900 	rv.iSubComponentResult = 0;
       
   901 	rv.iData0 = 0;
       
   902 	rv.iData1 = 0;
       
   903 
       
   904 	// check that the agent was running
       
   905 	if( iAgentProcess == NULL ) {
       
   906 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   907 		return rv;
       
   908 	}
       
   909 
       
   910 	// check that the agent is still runnning
       
   911 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   912 	assert( perr == CAE_NONE );
       
   913 	if( pstatus != PS_STARTED ) {
       
   914 		rv.iServiceResult = ERR_INVALIDSTATE;
       
   915 		return rv;
       
   916 	}
       
   917 
       
   918 	// call the wrapper
       
   919 	cres = iDynamicsCommand.MobileNodeAgentGetPolicy( &policy_vector );
       
   920 	if( cres.iResult != DC_SUCCESS ) {
       
   921 		rv.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
   922 		rv.iSubComponentResult = cres.iResult;
       
   923 		rv.iData0 = cres.iErrorCode;
       
   924 		rv.iData1 = cres.iErrorDetail;
       
   925 		return rv;
       
   926 	}
       
   927 
       
   928 	// success
       
   929 	rv.iServiceResult = ERR_NONE;
       
   930 	rv.iData0 = policy_vector;
       
   931 	return rv;
       
   932 }
       
   933 
       
   934 
       
   935 /****************************************************************************************
       
   936  * 
       
   937  * PUBLIC FUNCTION: listforeignagents
       
   938  * 
       
   939  ***************************************************************************************/
       
   940 TForeignAgentList CSMncontroller::listforeignagents( int aArgs )
       
   941 {
       
   942 	TDynamicsCallInfo cres;
       
   943 	TCAProcessError perr;
       
   944 	TProcessStatus pstatus;
       
   945 	int foreign_agent_count = MAXFOREIGNAGENTCOUNT, i;
       
   946 	TMobileNodeForeignAgentInfo foreign_agent_list[MAXFOREIGNAGENTCOUNT];
       
   947 	TForeignAgentList rv = { 0, NULL };
       
   948 
       
   949 	// check that the agent was running
       
   950 	if( iAgentProcess == NULL ) {
       
   951 		return rv;
       
   952 	}
       
   953 
       
   954 	// check that the agent is still runnning
       
   955 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
   956 	assert( perr == CAE_NONE );
       
   957 	if( pstatus != PS_STARTED ) {
       
   958 		return rv;
       
   959 	}
       
   960 
       
   961 	// call the dynamics wrapper
       
   962 	cres = iDynamicsCommand.MobileNodeAgentGetForeignAgentList( &foreign_agent_count, foreign_agent_list);
       
   963 	if( cres.iResult != DC_SUCCESS ) {
       
   964 		return rv;
       
   965 	}
       
   966 
       
   967 	// allocate the memory 
       
   968 	rv.TForeignAgentList_len = foreign_agent_count;
       
   969 	rv.TForeignAgentList_val = (TForeignAgentInfo*)calloc( foreign_agent_count, sizeof(TForeignAgentInfo) );
       
   970 	assert( rv.TForeignAgentList_val != NULL );
       
   971 
       
   972 	// copy the entries - all entries default to 0 due to calloc()
       
   973 	for( i = 0; i < foreign_agent_count; i++ ) {
       
   974 		(rv.TForeignAgentList_val)[i].iCallResult.iServiceResult = ERR_NONE;
       
   975 		(rv.TForeignAgentList_val)[i].iForeignAgentAddress = (foreign_agent_list[i]).iForeignAgentAddress;
       
   976 		(rv.TForeignAgentList_val)[i].iInterfaceIndex = (foreign_agent_list[i]).iInterfaceIndex;
       
   977 		(rv.TForeignAgentList_val)[i].iInUse = (foreign_agent_list[i]).iInUse;
       
   978 		(rv.TForeignAgentList_val)[i].iLastAdvertisement = (foreign_agent_list[i]).iLastAdvertisement;
       
   979 		(rv.TForeignAgentList_val)[i].iPriority = (foreign_agent_list[i]).iPriority;
       
   980 		memcpy( (rv.TForeignAgentList_val)[i].iInterfaceName, (foreign_agent_list[i]).iInterfaceName, X_MAXINTERFACENAMELEN );
       
   981 		memcpy( (rv.TForeignAgentList_val)[i].iNAI, (foreign_agent_list[i]).iNAI, X_MAXNAILEN );
       
   982 	}
       
   983 
       
   984 	// done - success
       
   985 	return rv;
       
   986 }
       
   987 
       
   988 
       
   989 /****************************************************************************************
       
   990  * 
       
   991  * PUBLIC FUNCTION: getforeignagentinfo
       
   992  * 
       
   993  ***************************************************************************************/
       
   994 TForeignAgentInfo CSMncontroller::getforeignagentinfo( TForeignAgentInfoRequest aArgs )
       
   995 {
       
   996 	TDynamicsCallInfo cres;
       
   997 	TCAProcessError perr;
       
   998 	TProcessStatus pstatus;
       
   999 	TMobileNodeForeignAgentInfo foreign_agent_info;
       
  1000 	TForeignAgentInfo rv;
       
  1001 
       
  1002 	// init the result
       
  1003 	memset( &rv, 0, sizeof(rv) );
       
  1004 	rv.iCallResult.iServiceResult = ERR_NONE;
       
  1005 
       
  1006 	// check that the agent was running
       
  1007 	if( iAgentProcess == NULL ) {
       
  1008 		rv.iCallResult.iServiceResult = ERR_INVALIDSTATE;
       
  1009 		return rv;
       
  1010 	}
       
  1011 
       
  1012 	// check that the agent is still runnning
       
  1013 	perr = iAgentProcess->GetProcessStatus( &pstatus );
       
  1014 	assert( perr == CAE_NONE );
       
  1015 	if( pstatus != PS_STARTED ) {
       
  1016 		rv.iCallResult.iServiceResult = ERR_INVALIDSTATE;
       
  1017 		return rv;
       
  1018 	}
       
  1019 
       
  1020 	// call the dynamics wrapper
       
  1021 	cres = iDynamicsCommand.MobileNodeAgentGetForeignAgentInfo( aArgs.iForeignAgentID, &foreign_agent_info );
       
  1022 	if( cres.iResult != DC_SUCCESS ) {
       
  1023 		rv.iCallResult.iServiceResult = ERR_DYNAMICS_CALL_FAILED;
       
  1024 		rv.iCallResult.iSubComponentResult = cres.iResult;
       
  1025 		rv.iCallResult.iData0 = cres.iErrorCode;
       
  1026 		rv.iCallResult.iData1 = cres.iErrorDetail;
       
  1027 		return rv;
       
  1028 	}
       
  1029 
       
  1030 	// set the result
       
  1031 	rv.iForeignAgentAddress = foreign_agent_info.iForeignAgentAddress;
       
  1032 	rv.iInterfaceIndex = foreign_agent_info.iInterfaceIndex;
       
  1033 	rv.iInUse = foreign_agent_info.iInUse;
       
  1034 	rv.iLastAdvertisement = foreign_agent_info.iLastAdvertisement;
       
  1035 	rv.iPriority = foreign_agent_info.iPriority;
       
  1036 	memcpy( rv.iInterfaceName, foreign_agent_info.iInterfaceName, X_MAXINTERFACENAMELEN );
       
  1037 	memcpy( rv.iNAI, foreign_agent_info.iNAI, X_MAXNAILEN );
       
  1038 
       
  1039 	// done - success
       
  1040 	return rv;
       
  1041 }
       
  1042 
       
  1043 
       
  1044 /****************************************************************************************
       
  1045  * 
       
  1046  * PUBLIC FUNCTION: settimeout
       
  1047  * 
       
  1048  ***************************************************************************************/
       
  1049 void CSMncontroller::settimeout( TTimeoutRequest aArgs )
       
  1050 {
       
  1051 	iDynamicsCallTimeout = aArgs.iTimeout;
       
  1052 	iDynamicsCommand.SetTimeout( aArgs.iTimeout );
       
  1053 }
       
  1054 
       
  1055 
       
  1056 /****************************************************************************************
       
  1057  * 
       
  1058  * PRIVATE FUNCTION: SetInterfaceAddress
       
  1059  * 
       
  1060  ***************************************************************************************/
       
  1061 TResult CSMncontroller::SetInterfaceAddress( char *aInterfaceName, int aAddress )
       
  1062 {
       
  1063 	TResult rv;
       
  1064 	int sockfd, err;
       
  1065 	struct ifreq ifr;
       
  1066 	struct sockaddr_in destination_address, *saddr;
       
  1067 
       
  1068 	// check parameters
       
  1069 	assert( aInterfaceName );
       
  1070 
       
  1071 	// init the response
       
  1072 	rv.iServiceResult = ERR_NONE;
       
  1073 	rv.iSubComponentResult = 0;
       
  1074 	rv.iData0 = 0;
       
  1075 	rv.iData1 = 0;
       
  1076 
       
  1077 	// create a socket to make ioctl calls on
       
  1078 	sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
       
  1079 	if( sockfd <= 0 ) {
       
  1080 		rv.iServiceResult = ERR_SET_INTERFACE_ADDRESS_ERROR;
       
  1081 		rv.iSubComponentResult = SIE_SOCKET_FAILED;
       
  1082 		rv.iData0 = errno;
       
  1083 		return rv;
       
  1084 	}	
       
  1085 
       
  1086 	// setup the request
       
  1087 	STRNCPY_NULL_TERMINATE( ifr.ifr_name, aInterfaceName, IFNAMSIZ );
       
  1088 
       
  1089 	// get the current pointopoint address
       
  1090 	err = ioctl( sockfd, SIOCGIFDSTADDR, &ifr );
       
  1091 	if( err == -1 ) {
       
  1092 		rv.iServiceResult = ERR_SET_INTERFACE_ADDRESS_ERROR;
       
  1093 		rv.iSubComponentResult = SIE_IOCTL_GET_DESTINATION_ADDRESS_FAILED;
       
  1094 		rv.iData0 = errno;
       
  1095 		return rv;
       
  1096 	}
       
  1097 	destination_address = (*((struct sockaddr_in*)(&(ifr.ifr_dstaddr))));
       
  1098 
       
  1099 	// set the interface address
       
  1100 	saddr = (struct sockaddr_in*)(&(ifr.ifr_addr));
       
  1101 	saddr->sin_family = AF_INET;
       
  1102 	saddr->sin_port = 0;
       
  1103 	saddr->sin_addr.ADDRESS_INTEGER = aAddress;
       
  1104 	err = ioctl( sockfd, SIOCSIFADDR, &ifr );
       
  1105 	if( err == -1 ) {
       
  1106 		rv.iServiceResult = ERR_SET_INTERFACE_ADDRESS_ERROR;
       
  1107 		rv.iSubComponentResult = SIE_IOCTL_SET_ADDRESS_FAILED;
       
  1108 		rv.iData0 = errno;
       
  1109 		return rv;
       
  1110 	}
       
  1111   
       
  1112 	// setting the interface address seems to also set the the pointopoint (destination) 
       
  1113 	// address to the same thing, so set it back to what it was or routing won't work
       
  1114 	saddr = (struct sockaddr_in*)(&(ifr.ifr_dstaddr));
       
  1115 	*saddr = destination_address; 
       
  1116 	err = ioctl( sockfd, SIOCSIFDSTADDR, &ifr );
       
  1117 	if( err == -1 ) {
       
  1118 		rv.iServiceResult = ERR_SET_INTERFACE_ADDRESS_ERROR;
       
  1119 		rv.iSubComponentResult = SIE_IOCTL_SET_DESTINATION_ADDRESS_FAILED;
       
  1120 		rv.iData0 = errno;
       
  1121 		return rv;
       
  1122 	}
       
  1123 
       
  1124 	// done
       
  1125 	return rv;
       
  1126 }
       
  1127 
       
  1128 
       
  1129 /****************************************************************************************
       
  1130  * 
       
  1131  * PRIVATE FUNCTION: GetNetworkAddressFromHostAddress
       
  1132  * 
       
  1133  ***************************************************************************************/
       
  1134 struct in_addr CSMncontroller::GetNetworkAddressFromHostAddress( int aAddress, int aNetmask )
       
  1135 {
       
  1136 	struct in_addr rv;
       
  1137 	int netmask, i;
       
  1138 
       
  1139 	// create the netmask
       
  1140 	for( netmask = 0, i = 0; i < aNetmask; i++ ) {
       
  1141 	    netmask |= 1<<(31-i);
       
  1142 	}
       
  1143 
       
  1144 	// get the 
       
  1145 	rv.ADDRESS_INTEGER = ntohl( aAddress );
       
  1146 	rv.ADDRESS_INTEGER &= netmask;
       
  1147 	rv.ADDRESS_INTEGER = htonl( rv.ADDRESS_INTEGER );
       
  1148 
       
  1149 	// done
       
  1150 	return rv;
       
  1151 }