PrevNextUpHome BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1
SFXInetAddress
Class for managing an IP address and a domain.
#include <SFXInetAddress.h.hpp>
class SFXInetAddress;
SFMTYPEDEFCLASS(SFXInetAddress)

Inheritance diagram

 Inheritance diagram of SFXInetAddressClass

Collaboration diagram

 Collaboration diagram of SFXInetAddressClass

Description

The SFXInetAddress class provides the Resolve function of converting a domain into an IP address. To manage a port number, use the SFXSocketAddress class.

How to use the SFXInetAddress class

  1. Set a domain in the constructor or SFXInetAddress::Set function.
  2. Resolve the domain using the SFXInetAddress::Resolve function, and register a callback function as an argument of this function.
  3. The registered callback function will be called after notified of the address resolution.

Example 475. Method to resolve a domain

class MyClass {
    SFXInetAddress _address;
    Void Function(Void);
    CALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback)
};

Void MyClass::Function(Void)
{
    SFCError error;

    // set domain
    if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) {
        // resolve domain( result will be notified to ResolveCallback function )
        error = _address.Resolve(CALLBACK_FUNCTION(ResolveCallback));
    }
    if (error != SFERR_NO_ERROR) {
        // handle error since ResolveCallback function will not be called
    }
    
}

// callback function called after notified of the address resolution
CALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error)
{
     SInt16 i;

     // get result
     TRACE("%s",_address.Get().GetCString());  // domain
     
      // repeat number of IP addresses
     for(i = 0 ; i < _address.GetCount() ; i++){
         // get result
         TRACE("%s",_address.GetIP(i).GetCString());  // IP address
     }
    
}

Reference

SFXSocketAddress | IP address, domain, port number

Member

Constructor/Destructor
SFXInetAddress( Void )
Constructor of SFXInetAddress class.
SFXInetAddress( SFXInetAddressConstRef param )
Constructor of SFXInetAddress class.
SFXInetAddress( SFXAnsiStringConstRef param )
Constructor of SFXInetAddress class.
SFXInetAddress( INAddr inaddr )
Constructor of SFXInetAddress class.
~SFXInetAddress( Void )
Destructor of SFXInetAddress class.
Public Functions
static
SFXInetAddress
AnyInetAddress( Void )
Convert into the Any Address of the SFXInetAddress class.
INAddr AsINAddr( SInt16 index = 0 )
Convert the IP address into the INAddr format.
Void Cancel( Void )
Cancel the resolution of IP address.
Void Clear( Void )
Make domain name empty.
static
SFXInetAddressConstRef
EmptyInstance( Void )
Get an empty address.
SFXAnsiStringConstRef Get( Void )
Get the domain.
SInt16 GetCount( Void )
Get the number of IP addresses.
SFXAnsiString GetIP( SInt16 index = 0 )
Get the IP address.
static
SFXInetAddress
LocalInetAddress( Void )
Return the local IP address.
static
SFXInetAddress
LoopbackInetAddress( Void )
Return the Loopback Address.
SFCError Resolve( CallbackSPP spp , VoidPtr reference )
Resolve domain name.
SFCError Set( SFXInetAddressConstRef param )
Set( INAddr inaddr )
Set( SFXAnsiStringConstRef param )
Set the IP address and domain.
SFXInetAddressRef operator=( SFXInetAddressConstRef param )
Assign a domain IP address.
Types
CallbackSPP
Prototype of the callback function.

SFXInetAddress::SFXInetAddress
Constructor of SFXInetAddress class.
[ public, explicit ]
SFXInetAddress(Void);
[ public ]
SFXInetAddress(
    SFXInetAddressConstRef param   // source SFXInetAddress
);
[ public, explicit ]
SFXInetAddress(
    SFXAnsiStringConstRef param   // domain character string
);
[ public, explicit ]
SFXInetAddress(
    INAddr inaddr   // IP Address
);

Description

If the argument is of the SFXAnsiString::Set function, the domain string takes the following format:

<protocol> :// <account>  @ <domain>  : <port>  / <path>  

Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.

The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(i.e. string "nnn.nnn.nnn.nnn" ).

Reference

SFXInetAddress::Set | SFXInetAddress::operator=


SFXInetAddress::~SFXInetAddress
Destructor of SFXInetAddress class.
[ public ]
~SFXInetAddress(Void);

SFXInetAddress::AnyInetAddress
Convert into the Any Address of the SFXInetAddress class.
[ public, static ]
SFXInetAddress AnyInetAddress(Void);

Return value

Return the Any Address (AEE_INADDR_ANY) of the SFXInetAddress class.

Reference

SFXInetAddress::LocalInetAddress | SFXInetAddress::LoopbackInetAddress


SFXInetAddress::AsINAddr
Convert the IP address into the INAddr format.
[ public, const ]
INAddr AsINAddr(
    SInt16 index = 0   // index
);

Description

Get the IP address resolved using the SFXInetAddress::Resolve function in the INAddr format.

Since the instance of SFXInetAddress class holds several IP addresses in general, get the IP address by specifying its index.

To get the number of IP addresses, use the SFXInetAddress::GetCount function.

Reference

SFXInetAddress::GetCount | SFXInetAddress::GetIP | SFXInetAddress::Resolve


SFXInetAddress::Cancel
Cancel the resolution of IP address.
[ public ]
Void Cancel(Void);

Description

To cancel the callback function registered by the SFXInetAddress::Resolve function before called, use the SFXInetAddress::Cancel function.

This function releases the instance of SFBNetMgr class that is used in the SFXInetAddress::Resolve function.

Reference

SFXInetAddress::Resolve


SFXInetAddress::Clear
Make domain name empty.
[ public ]
Void Clear(Void);

Reference

SFXInetAddress::Cancel


SFXInetAddress::EmptyInstance
Get an empty address.
[ public, static ]
SFXInetAddressConstRef EmptyInstance(Void);

Return value

Return an empty address of the SFXInetAddress class.


SFXInetAddress::Get
Get the domain.
[ public, const ]
SFXAnsiStringConstRef Get(Void);

SFXInetAddress::GetCount
Get the number of IP addresses.
[ public, const ]
SInt16 GetCount(Void);

Reference

SFXInetAddress::AsINAddr | SFXInetAddress::GetIP


SFXInetAddress::GetIP
Get the IP address.
[ public, const ]
SFXAnsiString GetIP(
    SInt16 index = 0   // index
);

Description

Get the IP address as a string (format: "nnn.nnn.nnn.nnn") resolved by the SFXInetAddress::Resolve function.

Since the instance of SFXInetAddress class holds several IP addresses, get an IP address by specifying its index.

To get the number of IP addresses held in the instance of SFXInetAddress class, use the SFXInetAddress::GetCount function.

Reference

SFXInetAddress::GetCount | SFXInetAddress::AsINAddr


SFXInetAddress::LocalInetAddress
Return the local IP address.
[ public, static ]
SFXInetAddress LocalInetAddress(Void);

Return value

Return the local IP address of the SFXInetAddress class.

Description

The SFBNetMgr::GetMyIPAddr function is called internally.

Reference

SFXInetAddress::AnyInetAddress SFXInetAddress::LoopbackInetAddress


SFXInetAddress::LoopbackInetAddress
Return the Loopback Address.
[ public, static ]
SFXInetAddress LoopbackInetAddress(Void);

Return value

Return the Loopback Address (AEE_BREW_LOOPBACK) of the SFXInetAddress class.

Description

The SFXInetAddress::LoopbackInetAddress function is available for BREW 2.1 or over.

Reference

SFXInetAddress::AnyInetAddress SFXInetAddress::LocalInetAddress


SFXInetAddress::Resolve
Resolve domain name.
[ public ]
SFCError Resolve(
    CallbackSPP spp     // callback function
    VoidPtr reference   // data passed to callback function
);

Return value

  • Success : SFERR_NO_ERROR
  • If the SFXInetAddress::Resolve function is called again while resolving an IP address : SFERR_INVALID_STATE
  • If the domain is not found : SFERR_INVALID_STATE
  • If failed to create the instance of SFBNetMgr class : SFERR_FAILED

Description

The callback function specified with the argument is called after domain name is resolved. The callback function will not be called when an error occurs in the SFXInetAddress::Resolve function.

Example

class MyClass {
    SFXInetAddress _address;
    Void Function(Void);
    CALLBACK_DECLARE_SFXINETADDRESS(ResolveCallback);
};

Void MyClass::Function(Void)
{
    SFCError error;

    // set domain
    if ((error = _address.Set("http://www.example.com/test"); == SFERR_NO_ERROR) {
        // resolve domain( result will be notified to ResolveCallback function )
        error = _address.Resolve(CALLBACK_FUNCTION(ResolveCallback));
    }
    if (error != SFERR_NO_ERROR) {
        // handle error since ResolveCallback function will not be called
    }
    
}

// callback function called after notified of the address resolution
CALLBACK_IMPLEMENT_SFXINETADDRESS(MyClass, ResolveCallback, error)
{
    SFXAnsiString ip;
    ip = _address.GetIP(0); // get result
}

Reference

SFXInetAddress::Cancel | SFXInetAddress::CallbackSPP


SFXInetAddress::Set
Set the IP address and domain.
[ public ]
SFCError Set(
    SFXInetAddressConstRef param   // source SFXInetAddress
);
[ public ]
SFCError Set(
    SFXAnsiStringConstRef param   // domain character string
);
[ public ]
SFCError Set(
    INAddr inaddr   // IP Address
);

Return value

  • Success : SFERR_NO_ERROR
  • If no IP address is specified : SFERR_INVALID_PARAM
  • If the IP address cannot be converted into the INAddr format : SFERR_FAILED
  • If insufficient memory : SFERR_NO_MEMORY

Description

The domain string has the following format.

<protocol> :// <account>  @ <domain>  : <port> / <path>  

Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.

The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(i.e. string "nnn.nnn.nnn.nnn" ).

The address resolution will be canceled if the SFXInetAddress::Set function is called while resolving.

Example

SFXInetAddress address;
address.Set("http://www.example.com:80/test");
address.Get(); // "www.example.com" 
SFXInetAddress address;
address.Set("127.0.0.1/test");
address.AsINAddr(); // return 127.0.0.1 in INAddr format

Reference

SFXInetAddress::operator= | SFXInetAddress::AsINAddr | SFXInetAddress::Resolve


SFXInetAddress::operator=
Assign a domain IP address.
[ public ]
SFXInetAddressRef operator=(
    SFXInetAddressConstRef param   // source SFXInetAddress
);

Description

A specific format is recognized when the string of SFXAnsiString class is assigned.

The domain string takes the following format:

<protocol> :// <account>  @ <domain>  : <port>  / <path>  

Only the <domain> part is taken out and set when the string with this format(it may be OK to lack some parts of the string) is given.

The IP address is automatically gotten by using the SFXInetAddress::AsINAddr function if the <domain> part is the IP address(i.e. string "nnn.nnn.nnn.nnn" ).

Reference

SFXInetAddress::Set


SFXInetAddress::CallbackSPP
Prototype of the callback function.
typedef Void(* SFXInetAddress::CallbackSPP)(SFCError error, VoidPtr reference)

Description

The SFXInetAddress::CallbackSPP function is the prototype for the callback function used in the SFXInetAddress class. The result of communication processing is notified to the callback function.

The error code is passed to the 1st argument, the parameter for the callback function is passed to the 2nd argument.

Reference

SFXInetAddress::Resolve