sock.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*++
  2. Copyright (c) 2014 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. sock.h
  9. Abstract:
  10. This header contains socket definitions for the debug client.
  11. Author:
  12. Evan Green 27-Aug-2014
  13. --*/
  14. //
  15. // ------------------------------------------------------------------- Includes
  16. //
  17. //
  18. // ---------------------------------------------------------------- Definitions
  19. //
  20. //
  21. // ------------------------------------------------------ Data Type Definitions
  22. //
  23. //
  24. // -------------------------------------------------------------------- Globals
  25. //
  26. //
  27. // -------------------------------------------------------- Function Prototypes
  28. //
  29. int
  30. DbgrSocketInitializeLibrary (
  31. void
  32. );
  33. /*++
  34. Routine Description:
  35. This routine initializes socket support in the application.
  36. Arguments:
  37. None.
  38. Return Value:
  39. 0 on success.
  40. Non-zero on failure.
  41. --*/
  42. void
  43. DbgrSocketDestroyLibrary (
  44. void
  45. );
  46. /*++
  47. Routine Description:
  48. This routine tears down socket support in the application.
  49. Arguments:
  50. None.
  51. Return Value:
  52. None.
  53. --*/
  54. int
  55. DbgrSocketCreateStreamSocket (
  56. void
  57. );
  58. /*++
  59. Routine Description:
  60. This routine creates an IPv4 TCP socket.
  61. Arguments:
  62. None.
  63. Return Value:
  64. Returns the socket on success.
  65. Returns a value less than zero on failure.
  66. --*/
  67. int
  68. DbgrSocketBind (
  69. int Socket,
  70. char *Host,
  71. int Port
  72. );
  73. /*++
  74. Routine Description:
  75. This routine binds the given socket to the given address and port.
  76. Arguments:
  77. Socket - Supplies the socket to bind.
  78. Host - Supplies a pointer to the host string. Supply NULL to use any
  79. address.
  80. Port - Supplies the port to bind on.
  81. Return Value:
  82. 0 on success.
  83. Non-zero on failure.
  84. --*/
  85. int
  86. DbgrSocketConnect (
  87. int Socket,
  88. char *Host,
  89. int Port
  90. );
  91. /*++
  92. Routine Description:
  93. This routine connects to a remote server.
  94. Arguments:
  95. Socket - Supplies the socket to connect.
  96. Host - Supplies a pointer to the host string to connect to.
  97. Port - Supplies the port to bind on.
  98. Return Value:
  99. 0 on success.
  100. Non-zero on failure.
  101. --*/
  102. int
  103. DbgrSocketListen (
  104. int Socket
  105. );
  106. /*++
  107. Routine Description:
  108. This routine starts a server socket listening for connections.
  109. Arguments:
  110. Socket - Supplies the socket to listen on.
  111. Return Value:
  112. 0 on success.
  113. Non-zero on failure.
  114. --*/
  115. int
  116. DbgrSocketAccept (
  117. int Socket,
  118. char **Host,
  119. int *Port
  120. );
  121. /*++
  122. Routine Description:
  123. This routine accepts a new incoming connection from the given listening
  124. socket.
  125. Arguments:
  126. Socket - Supplies the socket to accept an incoming connection from.
  127. Host - Supplies an optional pointer where a string describing the host will
  128. be returned on success. The caller is responsible for freeing this
  129. string.
  130. Port - Supplies an optional pointer where the port number will be returned
  131. on success.
  132. Return Value:
  133. Returns the newly connected client socket on success.
  134. Returns a negative value on failure.
  135. --*/
  136. int
  137. DbgrSocketGetName (
  138. int Socket,
  139. char **Host,
  140. int *Port
  141. );
  142. /*++
  143. Routine Description:
  144. This routine gets the current local host and port for the given socket.
  145. Arguments:
  146. Socket - Supplies the socket to query.
  147. Host - Supplies an optional pointer where a string describing the host will
  148. be returned on success. The caller is responsible for freeing this
  149. string.
  150. Port - Supplies an optional pointer where the port number will be returned
  151. on success.
  152. Return Value:
  153. 0 on success.
  154. Returns a non-zero value on failure.
  155. --*/
  156. int
  157. DbgrSocketShutdown (
  158. int Socket
  159. );
  160. /*++
  161. Routine Description:
  162. This routine shuts down a socket. It shuts down both the read and write
  163. sides of the connection.
  164. Arguments:
  165. Socket - Supplies the socket to shut down.
  166. Return Value:
  167. 0 on success.
  168. Non-zero on failure.
  169. --*/
  170. void
  171. DbgrSocketClose (
  172. int Socket
  173. );
  174. /*++
  175. Routine Description:
  176. This routine closes a socket.
  177. Arguments:
  178. Socket - Supplies the socket to destroy.
  179. Return Value:
  180. None.
  181. --*/
  182. int
  183. DbgrSocketSend (
  184. int Socket,
  185. const void *Data,
  186. int Length
  187. );
  188. /*++
  189. Routine Description:
  190. This routine sends data out of a connected socket.
  191. Arguments:
  192. Socket - Supplies the file descriptor of the socket to send data out of.
  193. Data - Supplies the buffer of data to send.
  194. Length - Supplies the length of the data buffer, in bytes.
  195. Return Value:
  196. Returns the number of bytes sent on success.
  197. -1 on error, and the errno variable will be set to contain more information.
  198. --*/
  199. int
  200. DbgrSocketReceive (
  201. int Socket,
  202. void *Buffer,
  203. int Length
  204. );
  205. /*++
  206. Routine Description:
  207. This routine receives data from a connected socket.
  208. Arguments:
  209. Socket - Supplies the file descriptor of the socket to receive data from.
  210. Buffer - Supplies a pointer to a buffer where the received data will be
  211. returned.
  212. Length - Supplies the length of the data buffer, in bytes.
  213. Return Value:
  214. Returns the number of bytes received on success.
  215. -1 on error, and the errno variable will be set to contain more information.
  216. --*/
  217. int
  218. DbgrSocketPeek (
  219. int Socket,
  220. void *Buffer,
  221. int Length
  222. );
  223. /*++
  224. Routine Description:
  225. This routine peeks at data from a received socket, but does not remove it
  226. from the queue.
  227. Arguments:
  228. Socket - Supplies the file descriptor of the socket to receive data from.
  229. Buffer - Supplies a pointer to a buffer where the peeked data will be
  230. returned.
  231. Length - Supplies the length of the data buffer, in bytes.
  232. Return Value:
  233. Returns the number of bytes received on success.
  234. -1 on error, and the errno variable will be set to contain more information.
  235. --*/