You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.7KB

  1. /*
  2. oscpack -- Open Sound Control (OSC) packet manipulation library
  3. http://www.rossbencina.com/code/oscpack
  4. Copyright (c) 2004-2013 Ross Bencina <rossb@audiomulch.com>
  5. Permission is hereby granted, free of charge, to any person obtaining
  6. a copy of this software and associated documentation files
  7. (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge,
  9. publish, distribute, sublicense, and/or sell copies of the Software,
  10. and to permit persons to whom the Software is furnished to do so,
  11. subject to the following conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
  18. ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  19. CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  20. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. /*
  23. The text above constitutes the entire oscpack license; however,
  24. the oscpack developer(s) also make the following non-binding requests:
  25. Any person wishing to distribute modifications to the Software is
  26. requested to send the modifications to the original developer so that
  27. they can be incorporated into the canonical version. It is also
  28. requested that these non-binding requests be included whenever the
  29. above license is reproduced.
  30. */
  31. #include "IpEndpointName.h"
  32. #include <cstdio>
  33. #include "NetworkingUtils.h"
  34. unsigned long IpEndpointName::GetHostByName( const char *s )
  35. {
  36. return ::GetHostByName(s);
  37. }
  38. void IpEndpointName::AddressAsString( char *s ) const
  39. {
  40. if( address == ANY_ADDRESS ){
  41. std::sprintf( s, "<any>" );
  42. }else{
  43. std::sprintf( s, "%d.%d.%d.%d",
  44. (int)((address >> 24) & 0xFF),
  45. (int)((address >> 16) & 0xFF),
  46. (int)((address >> 8) & 0xFF),
  47. (int)(address & 0xFF) );
  48. }
  49. }
  50. void IpEndpointName::AddressAndPortAsString( char *s ) const
  51. {
  52. if( port == ANY_PORT ){
  53. if( address == ANY_ADDRESS ){
  54. std::sprintf( s, "<any>:<any>" );
  55. }else{
  56. std::sprintf( s, "%d.%d.%d.%d:<any>",
  57. (int)((address >> 24) & 0xFF),
  58. (int)((address >> 16) & 0xFF),
  59. (int)((address >> 8) & 0xFF),
  60. (int)(address & 0xFF) );
  61. }
  62. }else{
  63. if( address == ANY_ADDRESS ){
  64. std::sprintf( s, "<any>:%d", port );
  65. }else{
  66. std::sprintf( s, "%d.%d.%d.%d:%d",
  67. (int)((address >> 24) & 0xFF),
  68. (int)((address >> 16) & 0xFF),
  69. (int)((address >> 8) & 0xFF),
  70. (int)(address & 0xFF),
  71. (int)port );
  72. }
  73. }
  74. }