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 #include "IpEndpointName.h" |
30 #include "IpEndpointName.h" |
31 |
31 |
32 #include <stdio.h> |
32 #include <stdio.h> |
33 |
33 |
34 #include "NetworkingUtils.h" |
34 #include "NetworkingUtils.h" |
35 |
35 |
36 |
36 |
37 unsigned long IpEndpointName::GetHostByName( const char *s ) |
37 unsigned long IpEndpointName::GetHostByName( const char *s ) |
38 { |
38 { |
39 return ::GetHostByName(s); |
39 return ::GetHostByName(s); |
40 } |
40 } |
41 |
41 |
42 |
42 |
43 void IpEndpointName::AddressAsString( char *s ) const |
43 void IpEndpointName::AddressAsString( char *s ) const |
44 { |
44 { |
45 if( address == ANY_ADDRESS ){ |
45 if( address == ANY_ADDRESS ){ |
46 sprintf( s, "<any>" ); |
46 sprintf( s, "<any>" ); |
47 }else{ |
47 }else{ |
48 sprintf( s, "%d.%d.%d.%d", |
48 sprintf( s, "%d.%d.%d.%d", |
49 (int)((address >> 24) & 0xFF), |
49 (int)((address >> 24) & 0xFF), |
50 (int)((address >> 16) & 0xFF), |
50 (int)((address >> 16) & 0xFF), |
51 (int)((address >> 8) & 0xFF), |
51 (int)((address >> 8) & 0xFF), |
52 (int)(address & 0xFF) ); |
52 (int)(address & 0xFF) ); |
53 } |
53 } |
54 } |
54 } |
55 |
55 |
56 |
56 |
57 void IpEndpointName::AddressAndPortAsString( char *s ) const |
57 void IpEndpointName::AddressAndPortAsString( char *s ) const |
58 { |
58 { |
59 if( port == ANY_PORT ){ |
59 if( port == ANY_PORT ){ |
60 if( address == ANY_ADDRESS ){ |
60 if( address == ANY_ADDRESS ){ |
61 sprintf( s, "<any>:<any>" ); |
61 sprintf( s, "<any>:<any>" ); |
62 }else{ |
62 }else{ |
63 sprintf( s, "%d.%d.%d.%d:<any>", |
63 sprintf( s, "%d.%d.%d.%d:<any>", |
64 (int)((address >> 24) & 0xFF), |
64 (int)((address >> 24) & 0xFF), |
65 (int)((address >> 16) & 0xFF), |
65 (int)((address >> 16) & 0xFF), |
66 (int)((address >> 8) & 0xFF), |
66 (int)((address >> 8) & 0xFF), |
67 (int)(address & 0xFF) ); |
67 (int)(address & 0xFF) ); |
68 } |
68 } |
69 }else{ |
69 }else{ |
70 if( address == ANY_ADDRESS ){ |
70 if( address == ANY_ADDRESS ){ |
71 sprintf( s, "<any>:%d", port ); |
71 sprintf( s, "<any>:%d", port ); |
72 }else{ |
72 }else{ |
73 sprintf( s, "%d.%d.%d.%d:%d", |
73 sprintf( s, "%d.%d.%d.%d:%d", |
74 (int)((address >> 24) & 0xFF), |
74 (int)((address >> 24) & 0xFF), |
75 (int)((address >> 16) & 0xFF), |
75 (int)((address >> 16) & 0xFF), |
76 (int)((address >> 8) & 0xFF), |
76 (int)((address >> 8) & 0xFF), |
77 (int)(address & 0xFF), |
77 (int)(address & 0xFF), |
78 (int)port ); |
78 (int)port ); |
79 } |
79 } |
80 } |
80 } |
81 } |
81 } |