•OT_Classes/TAddr.cp

//  TAddrInet.cp - Macintosh OpenTransport network "address family independent" class object
// 
// Apple Macintosh Developer Technical Support
// Written by:  Vinne Moscaritolo
//
//  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
//
// You may incorporate this sample code into your applications without
// restriction, though the sample code has been provided "AS IS" and the
// responsibility for its operation is 100% yours.  However, what you are
// not permitted to do is to redistribute the source as "DSC Sample Code"
// after having made changes. If you're going to re-distribute the source,
// we require that you make it clear in the source that the code was
// descended from Apple Sample Code, but that you've made changes.
// 
 
#include "TAddr.h"
#include "TAddrInet.h"
 
 
// ---------------------------------------------------------------------------
//   TAddr::Factory( Type )
// ---------------------------------------------------------------------------
//  create an address of type
 
TAddr* TAddr::Factory(OTAddressType type)
{
    switch(type)
    {
        case AF_INET: 
            return new TAddrInet();
        
        default:
            return nil;
    }
    
};
 
 
// ---------------------------------------------------------------------------
//   TAddr::Factory( TNetbuf )
// ---------------------------------------------------------------------------
//  create an address from Netbuf
 
TAddr* TAddr::Factory(TNetbuf* n)
{
    OTAddress* addr = (OTAddress*) n->buf;
    
    switch(addr->fAddressType)
    {
        case AF_INET: 
            InetAddress* Iaddr = (InetAddress*) n->buf;
            return new TAddrInet(Iaddr->fHost,Iaddr->fPort);
        
        default:
            return nil;
    }
    
};
 
 
// ---------------------------------------------------------------------------
//   TAddr::TaddrToNetbuf( TNetbuf* )
// ---------------------------------------------------------------------------
//  convert an address to Netbuf
 
void  TAddr::ToNetbuf(TNetbuf* n)
{
    n->buf      =  (UInt8*) this->GetAddr();
    n->len      = this->GetSize();
    n->maxlen   = this->GetMaxSize();
}