
Originally Posted by
darksoul_e
Thank you emiusa77!
So your advice is to use Qt for almost everything, but I should use the Symbian API for choosing the default IAP. This way, if I want to port my application to another platform I should change the part of the code that sets the Ad-hoc mode.
Am I right?
Thank you in advance!
(I cannot find the documentation \nokia_plugin\openc\Openc_new_api_guide.doc, what I have to write before the first stroke?)
I'm more comfortable with QT than Symbian that's why I'm operating at QT level. To set a default IAP you can do
it by hard coding the IAP name in the setdefaultif api, which is a C api that you can embed both in QT and Symbian code. So if your app is just QT you can still use that api. The api is part of OpenC/C++ from version 1.6 but it is not yet documented in the help and just in that doc file. Below is a cut and paste from the doc:
Code:
- setdefaultif(const struct ifreq *)
IMPORT_C int setdefaultif(const struct ifreq *);
Description
The setdefaultif function can be used to set (or remove) a default network interface (either IAP or SNAP) for the application. This default interface, if set, will be used by all the further socket related function calls (connect, send, write etc) and all the host resolver function calls (getaddrinfo, getnameinfo, gethostbyname, getaddrbyname etc).
If there is a default interface set using setdefaultif and if there is a separate interface set on a socket using the ioctl system call, network operations on that socket will not use the default one, but the socket specific interface.
To remove the default interace, pass NULL as the argument.
To set an IAP name as the default interface, the 'ifr_name' member of the 'ifreq' structure must be filled with the IAP name to be set. Unicode IAP names can also be set by converting them to UTF8 format before passing them to this API. See the example below:
#include <stdio.h>
#include <string.h>
#include <net/if.h>
int main()
{
struct ifreq ifReq;
int ret;
/* Set the default interface using IAP name */
strcpy( ifReq.ifr_name, "Example Interface Name" );
ret = setdefaultif( &ifReq );
if( ret == -1 )
printf( "Setting default interface failed with errno = %d", errno );
/* Perform network operations */
/* ... */
/* Remove the default interface */
ret = setdefaultif( NULL );
if( ret == -1 )
printf( "Removing default interface failed with errno = %d", errno );
return 0;
}
To set a SNAP id as the default interface, the 'ifr_name' member of the 'ifreq' structure must be an empty string. In this case, the 'snap_id' member of the 'ifr_ifru' union in the parameter should contain the SNAP id to be set. It is recommended to zero initialize the 'ifreq' structure in this case. See the example below.
int main()
{
struct ifreq ifReq;
int ret;
unsigned int snapId = /* Get the SNAP id to be set from the application settings */
/* Set the default interface using SNAP id */
/* memset the ifreq to make sure that the interface name is an empty string */
memset(&ifReq, 0, sizeof(struct ifreq));
ifReq.ifr_ifru.snap_id = snapId;
ret = setdefaultif( &ifReq );
if( ret == -1 )
printf( "Setting default interface failed with errno = %d", (*__errno()) );
/* Perform network operations */
/* ... */
/* Remove the default interface */
ret = setdefaultif( 0 );
if( ret == -1 )
printf( "Removing default interface failed with errno = %d", (*__errno()) );
return 0;
}
The setdefaultif is not guaranteed to be thread safe.
Parameters
const struct ifreqifreq *
Return value
int The setdefaultif returns 0 on success and -1 on failure. Specifically, if the interface is not found, -1 is returned and errno is set to ENOENT.