inet.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. inet.c
  9. Abstract:
  10. This module implements support for internet helper operations.
  11. Author:
  12. Evan Green 3-May-2013
  13. Environment:
  14. User Mode C Library
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include "libcp.h"
  20. #include <arpa/inet.h>
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // ------------------------------------------------------ Data Type Definitions
  26. //
  27. //
  28. // ----------------------------------------------- Internal Function Prototypes
  29. //
  30. //
  31. // -------------------------------------------------------------------- Globals
  32. //
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. LIBC_API
  37. uint32_t
  38. htonl (
  39. uint32_t HostValue
  40. )
  41. /*++
  42. Routine Description:
  43. This routine converts a 32-bit value from host order to network order.
  44. Arguments:
  45. HostValue - Supplies the integer to convert into network order.
  46. Return Value:
  47. Returns the given integer in network order.
  48. --*/
  49. {
  50. return RtlByteSwapUlong(HostValue);
  51. }
  52. LIBC_API
  53. uint32_t
  54. ntohl (
  55. uint32_t NetworkValue
  56. )
  57. /*++
  58. Routine Description:
  59. This routine converts a 32-bit value from network order to host order.
  60. Arguments:
  61. NetworkValue - Supplies the integer to convert into host order.
  62. Return Value:
  63. Returns the given integer in host order.
  64. --*/
  65. {
  66. return RtlByteSwapUlong(NetworkValue);
  67. }
  68. LIBC_API
  69. uint16_t
  70. htons (
  71. uint16_t HostValue
  72. )
  73. /*++
  74. Routine Description:
  75. This routine converts a 16-bit value from host order to network order.
  76. Arguments:
  77. HostValue - Supplies the integer to convert into network order.
  78. Return Value:
  79. Returns the given integer in network order.
  80. --*/
  81. {
  82. return RtlByteSwapUshort(HostValue);
  83. }
  84. LIBC_API
  85. uint16_t
  86. ntohs (
  87. uint16_t NetworkValue
  88. )
  89. /*++
  90. Routine Description:
  91. This routine converts a 16-bit value from network order to host order.
  92. Arguments:
  93. NetworkValue - Supplies the integer to convert into host order.
  94. Return Value:
  95. Returns the given integer in host order.
  96. --*/
  97. {
  98. return RtlByteSwapUshort(NetworkValue);
  99. }
  100. //
  101. // --------------------------------------------------------- Internal Functions
  102. //