PageRenderTime 129ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_Windows_Simulator/WinPCap/remote-ext.h

https://bitbucket.org/minux/freertos
C Header | 444 lines | 52 code | 73 blank | 319 comment | 0 complexity | d6d66935eda199ce2af672c167bbd1d0 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (c) 2002 - 2003
  3. * NetGroup, Politecnico di Torino (Italy)
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the Politecnico di Torino nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. */
  32. #ifndef __REMOTE_EXT_H__
  33. #define __REMOTE_EXT_H__
  34. #ifndef HAVE_REMOTE
  35. #error Please do not include this file directly. Just define HAVE_REMOTE and then include pcap.h
  36. #endif
  37. // Definition for Microsoft Visual Studio
  38. #if _MSC_VER > 1000
  39. #pragma once
  40. #endif
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. /*!
  45. \file remote-ext.h
  46. The goal of this file it to include most of the new definitions that should be
  47. placed into the pcap.h file.
  48. It includes all new definitions (structures and functions like pcap_open().
  49. Some of the functions are not really a remote feature, but, right now,
  50. they are placed here.
  51. */
  52. // All this stuff is public
  53. /*! \addtogroup remote_struct
  54. \{
  55. */
  56. /*!
  57. \brief Defines the maximum buffer size in which address, port, interface names are kept.
  58. In case the adapter name or such is larger than this value, it is truncated.
  59. This is not used by the user; however it must be aware that an hostname / interface
  60. name longer than this value will be truncated.
  61. */
  62. #define PCAP_BUF_SIZE 1024
  63. /*! \addtogroup remote_source_ID
  64. \{
  65. */
  66. /*!
  67. \brief Internal representation of the type of source in use (file,
  68. remote/local interface).
  69. This indicates a file, i.e. the user want to open a capture from a local file.
  70. */
  71. #define PCAP_SRC_FILE 2
  72. /*!
  73. \brief Internal representation of the type of source in use (file,
  74. remote/local interface).
  75. This indicates a local interface, i.e. the user want to open a capture from
  76. a local interface. This does not involve the RPCAP protocol.
  77. */
  78. #define PCAP_SRC_IFLOCAL 3
  79. /*!
  80. \brief Internal representation of the type of source in use (file,
  81. remote/local interface).
  82. This indicates a remote interface, i.e. the user want to open a capture from
  83. an interface on a remote host. This does involve the RPCAP protocol.
  84. */
  85. #define PCAP_SRC_IFREMOTE 4
  86. /*!
  87. \}
  88. */
  89. /*! \addtogroup remote_source_string
  90. The formats allowed by the pcap_open() are the following:
  91. - file://path_and_filename [opens a local file]
  92. - rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
  93. - rpcap://host/devicename [opens the selected device available on a remote host]
  94. - rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
  95. - adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
  96. - (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]
  97. The formats allowed by the pcap_findalldevs_ex() are the following:
  98. - file://folder/ [lists all the files in the given folder]
  99. - rpcap:// [lists all local adapters]
  100. - rpcap://host:port/ [lists the devices available on a remote host]
  101. Referring to the 'host' and 'port' paramters, they can be either numeric or literal. Since
  102. IPv6 is fully supported, these are the allowed formats:
  103. - host (literal): e.g. host.foo.bar
  104. - host (numeric IPv4): e.g. 10.11.12.13
  105. - host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
  106. - host (numeric IPv6): e.g. [1:2:3::4]
  107. - port: can be either numeric (e.g. '80') or literal (e.g. 'http')
  108. Here you find some allowed examples:
  109. - rpcap://host.foo.bar/devicename [everything literal, no port number]
  110. - rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
  111. - rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
  112. - rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
  113. - rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
  114. - rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
  115. - rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
  116. - rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
  117. \{
  118. */
  119. /*!
  120. \brief String that will be used to determine the type of source in use (file,
  121. remote/local interface).
  122. This string will be prepended to the interface name in order to create a string
  123. that contains all the information required to open the source.
  124. This string indicates that the user wants to open a capture from a local file.
  125. */
  126. #define PCAP_SRC_FILE_STRING "file://"
  127. /*!
  128. \brief String that will be used to determine the type of source in use (file,
  129. remote/local interface).
  130. This string will be prepended to the interface name in order to create a string
  131. that contains all the information required to open the source.
  132. This string indicates that the user wants to open a capture from a network interface.
  133. This string does not necessarily involve the use of the RPCAP protocol. If the
  134. interface required resides on the local host, the RPCAP protocol is not involved
  135. and the local functions are used.
  136. */
  137. #define PCAP_SRC_IF_STRING "rpcap://"
  138. /*!
  139. \}
  140. */
  141. /*!
  142. \addtogroup remote_open_flags
  143. \{
  144. */
  145. /*!
  146. \brief Defines if the adapter has to go in promiscuous mode.
  147. It is '1' if you have to open the adapter in promiscuous mode, '0' otherwise.
  148. Note that even if this parameter is false, the interface could well be in promiscuous
  149. mode for some other reason (for example because another capture process with
  150. promiscuous mode enabled is currently using that interface).
  151. On on Linux systems with 2.2 or later kernels (that have the "any" device), this
  152. flag does not work on the "any" device; if an argument of "any" is supplied,
  153. the 'promisc' flag is ignored.
  154. */
  155. #define PCAP_OPENFLAG_PROMISCUOUS 1
  156. /*!
  157. \brief Defines if the data trasfer (in case of a remote
  158. capture) has to be done with UDP protocol.
  159. If it is '1' if you want a UDP data connection, '0' if you want
  160. a TCP data connection; control connection is always TCP-based.
  161. A UDP connection is much lighter, but it does not guarantee that all
  162. the captured packets arrive to the client workstation. Moreover,
  163. it could be harmful in case of network congestion.
  164. This flag is meaningless if the source is not a remote interface.
  165. In that case, it is simply ignored.
  166. */
  167. #define PCAP_OPENFLAG_DATATX_UDP 2
  168. /*!
  169. \brief Defines if the remote probe will capture its own generated traffic.
  170. In case the remote probe uses the same interface to capture traffic and to send
  171. data back to the caller, the captured traffic includes the RPCAP traffic as well.
  172. If this flag is turned on, the RPCAP traffic is excluded from the capture, so that
  173. the trace returned back to the collector is does not include this traffic.
  174. */
  175. #define PCAP_OPENFLAG_NOCAPTURE_RPCAP 4
  176. /*!
  177. \brief Defines if the local adapter will capture its own generated traffic.
  178. This flag tells the underlying capture driver to drop the packets that were sent by itself.
  179. This is usefult when building applications like bridges, that should ignore the traffic
  180. they just sent.
  181. */
  182. #define PCAP_OPENFLAG_NOCAPTURE_LOCAL 8
  183. /*!
  184. \brief This flag configures the adapter for maximum responsiveness.
  185. In presence of a large value for nbytes, WinPcap waits for the arrival of several packets before
  186. copying the data to the user. This guarantees a low number of system calls, i.e. lower processor usage,
  187. i.e. better performance, which is good for applications like sniffers. If the user sets the
  188. PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will copy the packets as soon as the application
  189. is ready to receive them. This is suggested for real time applications (like, for example, a bridge)
  190. that need the best responsiveness.*/
  191. #define PCAP_OPENFLAG_MAX_RESPONSIVENESS 16
  192. /*!
  193. \}
  194. */
  195. /*!
  196. \addtogroup remote_samp_methods
  197. \{
  198. */
  199. /*!
  200. \brief No sampling has to be done on the current capture.
  201. In this case, no sampling algorithms are applied to the current capture.
  202. */
  203. #define PCAP_SAMP_NOSAMP 0
  204. /*!
  205. \brief It defines that only 1 out of N packets must be returned to the user.
  206. In this case, the 'value' field of the 'pcap_samp' structure indicates the
  207. number of packets (minus 1) that must be discarded before one packet got accepted.
  208. In other words, if 'value = 10', the first packet is returned to the caller, while
  209. the following 9 are discarded.
  210. */
  211. #define PCAP_SAMP_1_EVERY_N 1
  212. /*!
  213. \brief It defines that we have to return 1 packet every N milliseconds.
  214. In this case, the 'value' field of the 'pcap_samp' structure indicates the 'waiting
  215. time' in milliseconds before one packet got accepted.
  216. In other words, if 'value = 10', the first packet is returned to the caller; the next
  217. returned one will be the first packet that arrives when 10ms have elapsed.
  218. */
  219. #define PCAP_SAMP_FIRST_AFTER_N_MS 2
  220. /*!
  221. \}
  222. */
  223. /*!
  224. \addtogroup remote_auth_methods
  225. \{
  226. */
  227. /*!
  228. \brief It defines the NULL authentication.
  229. This value has to be used within the 'type' member of the pcap_rmtauth structure.
  230. The 'NULL' authentication has to be equal to 'zero', so that old applications
  231. can just put every field of struct pcap_rmtauth to zero, and it does work.
  232. */
  233. #define RPCAP_RMTAUTH_NULL 0
  234. /*!
  235. \brief It defines the username/password authentication.
  236. With this type of authentication, the RPCAP protocol will use the username/
  237. password provided to authenticate the user on the remote machine. If the
  238. authentication is successful (and the user has the right to open network devices)
  239. the RPCAP connection will continue; otherwise it will be dropped.
  240. This value has to be used within the 'type' member of the pcap_rmtauth structure.
  241. */
  242. #define RPCAP_RMTAUTH_PWD 1
  243. /*!
  244. \}
  245. */
  246. /*!
  247. \brief This structure keeps the information needed to autheticate
  248. the user on a remote machine.
  249. The remote machine can either grant or refuse the access according
  250. to the information provided.
  251. In case the NULL authentication is required, both 'username' and
  252. 'password' can be NULL pointers.
  253. This structure is meaningless if the source is not a remote interface;
  254. in that case, the functions which requires such a structure can accept
  255. a NULL pointer as well.
  256. */
  257. struct pcap_rmtauth
  258. {
  259. /*!
  260. \brief Type of the authentication required.
  261. In order to provide maximum flexibility, we can support different types
  262. of authentication based on the value of this 'type' variable. The currently
  263. supported authentication methods are defined into the
  264. \link remote_auth_methods Remote Authentication Methods Section\endlink.
  265. */
  266. int type;
  267. /*!
  268. \brief Zero-terminated string containing the username that has to be
  269. used on the remote machine for authentication.
  270. This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
  271. and it can be NULL.
  272. */
  273. char *username;
  274. /*!
  275. \brief Zero-terminated string containing the password that has to be
  276. used on the remote machine for authentication.
  277. This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
  278. and it can be NULL.
  279. */
  280. char *password;
  281. };
  282. /*!
  283. \brief This structure defines the information related to sampling.
  284. In case the sampling is requested, the capturing device should read
  285. only a subset of the packets coming from the source. The returned packets depend
  286. on the sampling parameters.
  287. \warning The sampling process is applied <strong>after</strong> the filtering process.
  288. In other words, packets are filtered first, then the sampling process selects a
  289. subset of the 'filtered' packets and it returns them to the caller.
  290. */
  291. struct pcap_samp
  292. {
  293. /*!
  294. Method used for sampling. Currently, the supported methods are listed in the
  295. \link remote_samp_methods Sampling Methods Section\endlink.
  296. */
  297. int method;
  298. /*!
  299. This value depends on the sampling method defined. For its meaning, please check
  300. at the \link remote_samp_methods Sampling Methods Section\endlink.
  301. */
  302. int value;
  303. };
  304. //! Maximum lenght of an host name (needed for the RPCAP active mode)
  305. #define RPCAP_HOSTLIST_SIZE 1024
  306. /*!
  307. \}
  308. */ // end of public documentation
  309. // Exported functions
  310. /** \name New WinPcap functions
  311. This section lists the new functions that are able to help considerably in writing
  312. WinPcap programs because of their easiness of use.
  313. */
  314. //\{
  315. pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
  316. int pcap_createsrcstr(char *source, int type, const char *host, const char *port, const char *name, char *errbuf);
  317. int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char *name, char *errbuf);
  318. int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
  319. struct pcap_samp *pcap_setsampling(pcap_t *p);
  320. //\}
  321. // End of new winpcap functions
  322. /** \name Remote Capture functions
  323. */
  324. //\{
  325. SOCKET pcap_remoteact_accept(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf);
  326. int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf);
  327. int pcap_remoteact_close(const char *host, char *errbuf);
  328. void pcap_remoteact_cleanup();
  329. //\}
  330. // End of remote capture functions
  331. #ifdef __cplusplus
  332. }
  333. #endif
  334. #endif