1 /* |
1 /* |
2 oscpack -- Open Sound Control packet manipulation library |
2 oscpack -- Open Sound Control packet manipulation library |
3 http://www.audiomulch.com/~rossb/oscpack |
3 http://www.audiomulch.com/~rossb/oscpack |
4 |
4 |
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com> |
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com> |
6 |
6 |
7 Permission is hereby granted, free of charge, to any person obtaining |
7 Permission is hereby granted, free of charge, to any person obtaining |
8 a copy of this software and associated documentation files |
8 a copy of this software and associated documentation files |
9 (the "Software"), to deal in the Software without restriction, |
9 (the "Software"), to deal in the Software without restriction, |
10 including without limitation the rights to use, copy, modify, merge, |
10 including without limitation the rights to use, copy, modify, merge, |
11 publish, distribute, sublicense, and/or sell copies of the Software, |
11 publish, distribute, sublicense, and/or sell copies of the Software, |
12 and to permit persons to whom the Software is furnished to do so, |
12 and to permit persons to whom the Software is furnished to do so, |
13 subject to the following conditions: |
13 subject to the following conditions: |
14 |
14 |
15 The above copyright notice and this permission notice shall be |
15 The above copyright notice and this permission notice shall be |
16 included in all copies or substantial portions of the Software. |
16 included in all copies or substantial portions of the Software. |
17 |
17 |
18 Any person wishing to distribute modifications to the Software is |
18 Any person wishing to distribute modifications to the Software is |
19 requested to send the modifications to the original developer so that |
19 requested to send the modifications to the original developer so that |
20 they can be incorporated into the canonical version. |
20 they can be incorporated into the canonical version. |
21 |
21 |
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
29 */ |
29 */ |
30 #ifndef INCLUDED_IPENDPOINTNAME_H |
30 #ifndef INCLUDED_IPENDPOINTNAME_H |
31 #define INCLUDED_IPENDPOINTNAME_H |
31 #define INCLUDED_IPENDPOINTNAME_H |
32 |
32 |
33 |
33 |
36 public: |
36 public: |
37 static const unsigned long ANY_ADDRESS = 0xFFFFFFFF; |
37 static const unsigned long ANY_ADDRESS = 0xFFFFFFFF; |
38 static const int ANY_PORT = -1; |
38 static const int ANY_PORT = -1; |
39 |
39 |
40 IpEndpointName() |
40 IpEndpointName() |
41 : address( ANY_ADDRESS ), port( ANY_PORT ) {} |
41 : address( ANY_ADDRESS ), port( ANY_PORT ) {} |
42 IpEndpointName( int port_ ) |
42 IpEndpointName( int port_ ) |
43 : address( ANY_ADDRESS ), port( port_ ) {} |
43 : address( ANY_ADDRESS ), port( port_ ) {} |
44 IpEndpointName( unsigned long ipAddress_, int port_ ) |
44 IpEndpointName( unsigned long ipAddress_, int port_ ) |
45 : address( ipAddress_ ), port( port_ ) {} |
45 : address( ipAddress_ ), port( port_ ) {} |
46 IpEndpointName( const char *addressName, int port_=ANY_PORT ) |
46 IpEndpointName( const char *addressName, int port_=ANY_PORT ) |
47 : address( GetHostByName( addressName ) ) |
47 : address( GetHostByName( addressName ) ) |
48 , port( port_ ) {} |
48 , port( port_ ) {} |
49 IpEndpointName( int addressA, int addressB, int addressC, int addressD, int port_=ANY_PORT ) |
49 IpEndpointName( int addressA, int addressB, int addressC, int addressD, int port_=ANY_PORT ) |
50 : address( ( (addressA << 24) | (addressB << 16) | (addressC << 8) | addressD ) ) |
50 : address( ( (addressA << 24) | (addressB << 16) | (addressC << 8) | addressD ) ) |
51 , port( port_ ) {} |
51 , port( port_ ) {} |
52 |
52 |
53 // address and port are maintained in host byte order here |
53 // address and port are maintained in host byte order here |
54 unsigned long address; |
54 unsigned long address; |
55 int port; |
55 int port; |
56 |
56 |
57 enum { ADDRESS_STRING_LENGTH=17 }; |
57 enum { ADDRESS_STRING_LENGTH=17 }; |
58 void AddressAsString( char *s ) const; |
58 void AddressAsString( char *s ) const; |
59 |
59 |
60 enum { ADDRESS_AND_PORT_STRING_LENGTH=23}; |
60 enum { ADDRESS_AND_PORT_STRING_LENGTH=23}; |
61 void AddressAndPortAsString( char *s ) const; |
61 void AddressAndPortAsString( char *s ) const; |
62 }; |
62 }; |
63 |
63 |
64 inline bool operator==( const IpEndpointName& lhs, const IpEndpointName& rhs ) |
64 inline bool operator==( const IpEndpointName& lhs, const IpEndpointName& rhs ) |
65 { |
65 { |
66 return (lhs.address == rhs.address && lhs.port == rhs.port ); |
66 return (lhs.address == rhs.address && lhs.port == rhs.port ); |
67 } |
67 } |
68 |
68 |
69 inline bool operator!=( const IpEndpointName& lhs, const IpEndpointName& rhs ) |
69 inline bool operator!=( const IpEndpointName& lhs, const IpEndpointName& rhs ) |
70 { |
70 { |
71 return !(lhs == rhs); |
71 return !(lhs == rhs); |
72 } |
72 } |
73 |
73 |
74 #endif /* INCLUDED_IPENDPOINTNAME_H */ |
74 #endif /* INCLUDED_IPENDPOINTNAME_H */ |