tomwalters@570: /* tomwalters@570: oscpack -- Open Sound Control packet manipulation library tomwalters@570: http://www.audiomulch.com/~rossb/oscpack tomwalters@570: tomwalters@570: Copyright (c) 2004-2005 Ross Bencina tomwalters@570: tomwalters@570: Permission is hereby granted, free of charge, to any person obtaining tomwalters@570: a copy of this software and associated documentation files tomwalters@570: (the "Software"), to deal in the Software without restriction, tomwalters@570: including without limitation the rights to use, copy, modify, merge, tomwalters@570: publish, distribute, sublicense, and/or sell copies of the Software, tomwalters@570: and to permit persons to whom the Software is furnished to do so, tomwalters@570: subject to the following conditions: tomwalters@570: tomwalters@570: The above copyright notice and this permission notice shall be tomwalters@570: included in all copies or substantial portions of the Software. tomwalters@570: tomwalters@570: Any person wishing to distribute modifications to the Software is tomwalters@570: requested to send the modifications to the original developer so that tomwalters@570: they can be incorporated into the canonical version. tomwalters@570: tomwalters@570: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, tomwalters@570: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF tomwalters@570: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. tomwalters@570: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR tomwalters@570: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF tomwalters@570: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION tomwalters@570: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tomwalters@570: */ tomwalters@570: #ifndef INCLUDED_IPENDPOINTNAME_H tomwalters@570: #define INCLUDED_IPENDPOINTNAME_H tomwalters@570: tomwalters@570: tomwalters@570: class IpEndpointName{ tomwalters@570: static unsigned long GetHostByName( const char *s ); tomwalters@570: public: tomwalters@570: static const unsigned long ANY_ADDRESS = 0xFFFFFFFF; tomwalters@570: static const int ANY_PORT = -1; tomwalters@570: tomwalters@570: IpEndpointName() tomwalters@570: : address( ANY_ADDRESS ), port( ANY_PORT ) {} tomwalters@570: IpEndpointName( int port_ ) tomwalters@570: : address( ANY_ADDRESS ), port( port_ ) {} tomwalters@570: IpEndpointName( unsigned long ipAddress_, int port_ ) tomwalters@570: : address( ipAddress_ ), port( port_ ) {} tomwalters@570: IpEndpointName( const char *addressName, int port_=ANY_PORT ) tomwalters@570: : address( GetHostByName( addressName ) ) tomwalters@570: , port( port_ ) {} tomwalters@570: IpEndpointName( int addressA, int addressB, int addressC, int addressD, int port_=ANY_PORT ) tomwalters@570: : address( ( (addressA << 24) | (addressB << 16) | (addressC << 8) | addressD ) ) tomwalters@570: , port( port_ ) {} tomwalters@570: tomwalters@570: // address and port are maintained in host byte order here tomwalters@570: unsigned long address; tomwalters@570: int port; tomwalters@570: tomwalters@570: enum { ADDRESS_STRING_LENGTH=17 }; tomwalters@570: void AddressAsString( char *s ) const; tomwalters@570: tomwalters@570: enum { ADDRESS_AND_PORT_STRING_LENGTH=23}; tomwalters@570: void AddressAndPortAsString( char *s ) const; tomwalters@570: }; tomwalters@570: tomwalters@570: inline bool operator==( const IpEndpointName& lhs, const IpEndpointName& rhs ) tomwalters@570: { tomwalters@570: return (lhs.address == rhs.address && lhs.port == rhs.port ); tomwalters@570: } tomwalters@570: tomwalters@570: inline bool operator!=( const IpEndpointName& lhs, const IpEndpointName& rhs ) tomwalters@570: { tomwalters@570: return !(lhs == rhs); tomwalters@570: } tomwalters@570: tomwalters@570: #endif /* INCLUDED_IPENDPOINTNAME_H */