/* * The Unix Channel * * by Michel Beaudouin-Lafon * * Copyright 1990-1997 * Laboratoire de Recherche en Informatique (LRI) * * Addresses * * $Id$ * $CurLog$ * Smart(ies) removed by Stephane Sire * Added buffered hostname to IvlInetAddress */ #include "Address.h" #include "error.h" #include #include #include #include #include /* all this is necessary for function Decode only. This should be investigated */ #include "UnixAddress.h" #include "InetAddress.h" #include "IrdaAddress.h" /*?class IvlAddress This class is a virtual base class: no objects of this class are ever created. It implements the Unix type \typ{^{struct sockaddr}}, used for creating sockets. Addresses are used mainly as arguments of constructors for the class \typ{IvlSocket} and its derived classes. All its member functions are virtual. These functions exist for all the derived classes but are only described here. An address can be valid or invalid, depending on the constructor being able to create the address or not. There are currently two derived classes, for Unix domain addresses and Internet domain addresses. Addresses are "ONE WAY" instances, once created they cannot be modified. This implies that instead of beeing changed, new ones are created with static member function \fun{Decode} for example when a socket is bound. ?*/ /*? Construct an invalid address. ?*/ IvlAddress :: IvlAddress () : Valid (false) { } /*?nodoc?*/ IvlAddress :: ~IvlAddress () { } #ifdef DOC // fake entries for inline functions /*? Return true if the address is valid. ?*/ bool IvlAddress :: IsValid () { } /*? Return one of \var{AF\_UNSPEC}, \var{AF\_UNIX} or \var{AF\_INET}. Other values may be defined if supported by the system. ?*/ int IvlAddress :: Family () { } /*?nextdoc?*/ int IvlAddress :: Length () { } /*? Return the address structure and its length. \typ{^{SockAddr}} is a typedef for \typ{^{struct sockaddr}}. ?*/ SockAddr* IvlAddress :: GetSockAddr () { } /*?nodoc?*/ char* IvlAddress :: StrRepr (char* buf) { } #endif /* DOC */ /*? This is a global function (static member of class \typ{IvlAddress}). It creates an object of a derived class of \typ{IvlAddress} from a generic address (thus is cannot be replaced by a constructor). A generic address is the following union of address structures (it is typically returned by system calls like \fun{recvfrom}): \begin{ccode} typedef union { struct sockaddr sa; // default struct sockaddr_un su; // Unix struct sockaddr_irda sir; // irda struct sockaddr_in si; // inet } GEN_ADDR; \end{ccode} ?*/ IvlAddress* IvlAddress :: Decode (GEN_ADDR* addr, int alen) { switch (addr->sa.sa_family) { #ifdef UNIX_SOCK case AF_UNIX : addr->su.sun_path [alen] = 0; return new IvlUnixAddress (addr->su.sun_path); #endif #ifdef IRDA_SOCK case AF_IRDA : return new IvlIrdaAddress (addr->sir.sir_name); #endif case AF_INET : return new IvlInetAddress (addr->si.sin_addr.s_addr, addr->si.sin_port); default : return 0; } }