socks5.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /* socks5.h -- generated by Trunnel v1.5.2.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_SOCKS5_H
  6. #define TRUNNEL_SOCKS5_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #define CMD_CONNECT 1
  10. #define CMD_BIND 2
  11. #define CMD_UDP_ASSOCIATE 3
  12. #define CMD_RESOLVE 240
  13. #define CMD_RESOLVE_PTR 241
  14. #define ATYPE_IPV4 1
  15. #define ATYPE_IPV6 4
  16. #define ATYPE_DOMAINNAME 3
  17. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_DOMAINNAME)
  18. struct domainname_st {
  19. uint8_t len;
  20. trunnel_string_t name;
  21. uint8_t trunnel_error_code_;
  22. };
  23. #endif
  24. typedef struct domainname_st domainname_t;
  25. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS4_CLIENT_REQUEST)
  26. struct socks4_client_request_st {
  27. uint8_t version;
  28. uint8_t command;
  29. uint16_t port;
  30. uint32_t addr;
  31. char *username;
  32. char *socks4a_addr_hostname;
  33. uint8_t trunnel_error_code_;
  34. };
  35. #endif
  36. typedef struct socks4_client_request_st socks4_client_request_t;
  37. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS4_SERVER_REPLY)
  38. struct socks4_server_reply_st {
  39. uint8_t version;
  40. uint8_t status;
  41. uint16_t port;
  42. uint32_t addr;
  43. uint8_t trunnel_error_code_;
  44. };
  45. #endif
  46. typedef struct socks4_server_reply_st socks4_server_reply_t;
  47. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_CLIENT_USERPASS_AUTH)
  48. struct socks5_client_userpass_auth_st {
  49. uint8_t version;
  50. uint8_t username_len;
  51. trunnel_string_t username;
  52. uint8_t passwd_len;
  53. trunnel_string_t passwd;
  54. uint8_t trunnel_error_code_;
  55. };
  56. #endif
  57. typedef struct socks5_client_userpass_auth_st socks5_client_userpass_auth_t;
  58. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_CLIENT_VERSION)
  59. struct socks5_client_version_st {
  60. uint8_t version;
  61. uint8_t n_methods;
  62. TRUNNEL_DYNARRAY_HEAD(, uint8_t) methods;
  63. uint8_t trunnel_error_code_;
  64. };
  65. #endif
  66. typedef struct socks5_client_version_st socks5_client_version_t;
  67. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_SERVER_METHOD)
  68. struct socks5_server_method_st {
  69. uint8_t version;
  70. uint8_t method;
  71. uint8_t trunnel_error_code_;
  72. };
  73. #endif
  74. typedef struct socks5_server_method_st socks5_server_method_t;
  75. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_SERVER_USERPASS_AUTH)
  76. struct socks5_server_userpass_auth_st {
  77. uint8_t version;
  78. uint8_t status;
  79. uint8_t trunnel_error_code_;
  80. };
  81. #endif
  82. typedef struct socks5_server_userpass_auth_st socks5_server_userpass_auth_t;
  83. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_CLIENT_REQUEST)
  84. struct socks5_client_request_st {
  85. uint8_t version;
  86. uint8_t command;
  87. uint8_t reserved;
  88. uint8_t atype;
  89. uint32_t dest_addr_ipv4;
  90. uint8_t dest_addr_ipv6[16];
  91. struct domainname_st *dest_addr_domainname;
  92. uint16_t dest_port;
  93. uint8_t trunnel_error_code_;
  94. };
  95. #endif
  96. typedef struct socks5_client_request_st socks5_client_request_t;
  97. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_SOCKS5_SERVER_REPLY)
  98. struct socks5_server_reply_st {
  99. uint8_t version;
  100. uint8_t reply;
  101. uint8_t reserved;
  102. uint8_t atype;
  103. uint32_t bind_addr_ipv4;
  104. uint8_t bind_addr_ipv6[16];
  105. struct domainname_st *bind_addr_domainname;
  106. uint16_t bind_port;
  107. uint8_t trunnel_error_code_;
  108. };
  109. #endif
  110. typedef struct socks5_server_reply_st socks5_server_reply_t;
  111. /** Return a newly allocated domainname with all elements set to zero.
  112. */
  113. domainname_t *domainname_new(void);
  114. /** Release all storage held by the domainname in 'victim'. (Do
  115. * nothing if 'victim' is NULL.)
  116. */
  117. void domainname_free(domainname_t *victim);
  118. /** Try to parse a domainname from the buffer in 'input', using up to
  119. * 'len_in' bytes from the input buffer. On success, return the number
  120. * of bytes consumed and set *output to the newly allocated
  121. * domainname_t. On failure, return -2 if the input appears truncated,
  122. * and -1 if the input is otherwise invalid.
  123. */
  124. ssize_t domainname_parse(domainname_t **output, const uint8_t *input, const size_t len_in);
  125. /** Return the number of bytes we expect to need to encode the
  126. * domainname in 'obj'. On failure, return a negative value. Note that
  127. * this value may be an overestimate, and can even be an underestimate
  128. * for certain unencodeable objects.
  129. */
  130. ssize_t domainname_encoded_len(const domainname_t *obj);
  131. /** Try to encode the domainname from 'input' into the buffer at
  132. * 'output', using up to 'avail' bytes of the output buffer. On
  133. * success, return the number of bytes used. On failure, return -2 if
  134. * the buffer was not long enough, and -1 if the input was invalid.
  135. */
  136. ssize_t domainname_encode(uint8_t *output, size_t avail, const domainname_t *input);
  137. /** Check whether the internal state of the domainname in 'obj' is
  138. * consistent. Return NULL if it is, and a short message if it is not.
  139. */
  140. const char *domainname_check(const domainname_t *obj);
  141. /** Clear any errors that were set on the object 'obj' by its setter
  142. * functions. Return true iff errors were cleared.
  143. */
  144. int domainname_clear_errors(domainname_t *obj);
  145. /** Return the value of the len field of the domainname_t in 'inp'
  146. */
  147. uint8_t domainname_get_len(const domainname_t *inp);
  148. /** Set the value of the len field of the domainname_t in 'inp' to
  149. * 'val'. Return 0 on success; return -1 and set the error code on
  150. * 'inp' on failure.
  151. */
  152. int domainname_set_len(domainname_t *inp, uint8_t val);
  153. /** Return the length of the dynamic array holding the name field of
  154. * the domainname_t in 'inp'.
  155. */
  156. size_t domainname_getlen_name(const domainname_t *inp);
  157. /** Return the element at position 'idx' of the dynamic array field
  158. * name of the domainname_t in 'inp'.
  159. */
  160. char domainname_get_name(domainname_t *inp, size_t idx);
  161. /** As domainname_get_name, but take and return a const pointer
  162. */
  163. char domainname_getconst_name(const domainname_t *inp, size_t idx);
  164. /** Change the element at position 'idx' of the dynamic array field
  165. * name of the domainname_t in 'inp', so that it will hold the value
  166. * 'elt'.
  167. */
  168. int domainname_set_name(domainname_t *inp, size_t idx, char elt);
  169. /** Append a new element 'elt' to the dynamic array field name of the
  170. * domainname_t in 'inp'.
  171. */
  172. int domainname_add_name(domainname_t *inp, char elt);
  173. /** Return a pointer to the variable-length array field name of 'inp'.
  174. */
  175. char * domainname_getarray_name(domainname_t *inp);
  176. /** As domainname_get_name, but take and return a const pointer
  177. */
  178. const char * domainname_getconstarray_name(const domainname_t *inp);
  179. /** Change the length of the variable-length array field name of 'inp'
  180. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  181. * -1 and set the error code on 'inp' on failure.
  182. */
  183. int domainname_setlen_name(domainname_t *inp, size_t newlen);
  184. /** Return the value of the name field of a domainname_t as a NUL-
  185. * terminated string.
  186. */
  187. const char * domainname_getstr_name(domainname_t *inp);
  188. /** Set the value of the name field of a domainname_t to a given
  189. * string of length 'len'. Return 0 on success; return -1 and set the
  190. * error code on 'inp' on failure.
  191. */
  192. int domainname_setstr0_name(domainname_t *inp, const char *val, size_t len);
  193. /** Set the value of the name field of a domainname_t to a given NUL-
  194. * terminated string. Return 0 on success; return -1 and set the error
  195. * code on 'inp' on failure.
  196. */
  197. int domainname_setstr_name(domainname_t *inp, const char *val);
  198. /** Return a newly allocated socks4_client_request with all elements
  199. * set to zero.
  200. */
  201. socks4_client_request_t *socks4_client_request_new(void);
  202. /** Release all storage held by the socks4_client_request in 'victim'.
  203. * (Do nothing if 'victim' is NULL.)
  204. */
  205. void socks4_client_request_free(socks4_client_request_t *victim);
  206. /** Try to parse a socks4_client_request from the buffer in 'input',
  207. * using up to 'len_in' bytes from the input buffer. On success,
  208. * return the number of bytes consumed and set *output to the newly
  209. * allocated socks4_client_request_t. On failure, return -2 if the
  210. * input appears truncated, and -1 if the input is otherwise invalid.
  211. */
  212. ssize_t socks4_client_request_parse(socks4_client_request_t **output, const uint8_t *input, const size_t len_in);
  213. /** Return the number of bytes we expect to need to encode the
  214. * socks4_client_request in 'obj'. On failure, return a negative
  215. * value. Note that this value may be an overestimate, and can even be
  216. * an underestimate for certain unencodeable objects.
  217. */
  218. ssize_t socks4_client_request_encoded_len(const socks4_client_request_t *obj);
  219. /** Try to encode the socks4_client_request from 'input' into the
  220. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  221. * On success, return the number of bytes used. On failure, return -2
  222. * if the buffer was not long enough, and -1 if the input was invalid.
  223. */
  224. ssize_t socks4_client_request_encode(uint8_t *output, size_t avail, const socks4_client_request_t *input);
  225. /** Check whether the internal state of the socks4_client_request in
  226. * 'obj' is consistent. Return NULL if it is, and a short message if
  227. * it is not.
  228. */
  229. const char *socks4_client_request_check(const socks4_client_request_t *obj);
  230. /** Clear any errors that were set on the object 'obj' by its setter
  231. * functions. Return true iff errors were cleared.
  232. */
  233. int socks4_client_request_clear_errors(socks4_client_request_t *obj);
  234. /** Return the value of the version field of the
  235. * socks4_client_request_t in 'inp'
  236. */
  237. uint8_t socks4_client_request_get_version(const socks4_client_request_t *inp);
  238. /** Set the value of the version field of the socks4_client_request_t
  239. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  240. * code on 'inp' on failure.
  241. */
  242. int socks4_client_request_set_version(socks4_client_request_t *inp, uint8_t val);
  243. /** Return the value of the command field of the
  244. * socks4_client_request_t in 'inp'
  245. */
  246. uint8_t socks4_client_request_get_command(const socks4_client_request_t *inp);
  247. /** Set the value of the command field of the socks4_client_request_t
  248. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  249. * code on 'inp' on failure.
  250. */
  251. int socks4_client_request_set_command(socks4_client_request_t *inp, uint8_t val);
  252. /** Return the value of the port field of the socks4_client_request_t
  253. * in 'inp'
  254. */
  255. uint16_t socks4_client_request_get_port(const socks4_client_request_t *inp);
  256. /** Set the value of the port field of the socks4_client_request_t in
  257. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  258. * code on 'inp' on failure.
  259. */
  260. int socks4_client_request_set_port(socks4_client_request_t *inp, uint16_t val);
  261. /** Return the value of the addr field of the socks4_client_request_t
  262. * in 'inp'
  263. */
  264. uint32_t socks4_client_request_get_addr(const socks4_client_request_t *inp);
  265. /** Set the value of the addr field of the socks4_client_request_t in
  266. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  267. * code on 'inp' on failure.
  268. */
  269. int socks4_client_request_set_addr(socks4_client_request_t *inp, uint32_t val);
  270. /** Return the value of the username field of the
  271. * socks4_client_request_t in 'inp'
  272. */
  273. const char * socks4_client_request_get_username(const socks4_client_request_t *inp);
  274. /** Set the value of the username field of the socks4_client_request_t
  275. * in 'inp' to 'val'. Free the old value if any. Does not steal the
  276. * reference to 'val'.Return 0 on success; return -1 and set the error
  277. * code on 'inp' on failure.
  278. */
  279. int socks4_client_request_set_username(socks4_client_request_t *inp, const char *val);
  280. /** Return the value of the socks4a_addr_hostname field of the
  281. * socks4_client_request_t in 'inp'
  282. */
  283. const char * socks4_client_request_get_socks4a_addr_hostname(const socks4_client_request_t *inp);
  284. /** Set the value of the socks4a_addr_hostname field of the
  285. * socks4_client_request_t in 'inp' to 'val'. Free the old value if
  286. * any. Does not steal the reference to 'val'.Return 0 on success;
  287. * return -1 and set the error code on 'inp' on failure.
  288. */
  289. int socks4_client_request_set_socks4a_addr_hostname(socks4_client_request_t *inp, const char *val);
  290. /** Return a newly allocated socks4_server_reply with all elements set
  291. * to zero.
  292. */
  293. socks4_server_reply_t *socks4_server_reply_new(void);
  294. /** Release all storage held by the socks4_server_reply in 'victim'.
  295. * (Do nothing if 'victim' is NULL.)
  296. */
  297. void socks4_server_reply_free(socks4_server_reply_t *victim);
  298. /** Try to parse a socks4_server_reply from the buffer in 'input',
  299. * using up to 'len_in' bytes from the input buffer. On success,
  300. * return the number of bytes consumed and set *output to the newly
  301. * allocated socks4_server_reply_t. On failure, return -2 if the input
  302. * appears truncated, and -1 if the input is otherwise invalid.
  303. */
  304. ssize_t socks4_server_reply_parse(socks4_server_reply_t **output, const uint8_t *input, const size_t len_in);
  305. /** Return the number of bytes we expect to need to encode the
  306. * socks4_server_reply in 'obj'. On failure, return a negative value.
  307. * Note that this value may be an overestimate, and can even be an
  308. * underestimate for certain unencodeable objects.
  309. */
  310. ssize_t socks4_server_reply_encoded_len(const socks4_server_reply_t *obj);
  311. /** Try to encode the socks4_server_reply from 'input' into the buffer
  312. * at 'output', using up to 'avail' bytes of the output buffer. On
  313. * success, return the number of bytes used. On failure, return -2 if
  314. * the buffer was not long enough, and -1 if the input was invalid.
  315. */
  316. ssize_t socks4_server_reply_encode(uint8_t *output, size_t avail, const socks4_server_reply_t *input);
  317. /** Check whether the internal state of the socks4_server_reply in
  318. * 'obj' is consistent. Return NULL if it is, and a short message if
  319. * it is not.
  320. */
  321. const char *socks4_server_reply_check(const socks4_server_reply_t *obj);
  322. /** Clear any errors that were set on the object 'obj' by its setter
  323. * functions. Return true iff errors were cleared.
  324. */
  325. int socks4_server_reply_clear_errors(socks4_server_reply_t *obj);
  326. /** Return the value of the version field of the socks4_server_reply_t
  327. * in 'inp'
  328. */
  329. uint8_t socks4_server_reply_get_version(const socks4_server_reply_t *inp);
  330. /** Set the value of the version field of the socks4_server_reply_t in
  331. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  332. * code on 'inp' on failure.
  333. */
  334. int socks4_server_reply_set_version(socks4_server_reply_t *inp, uint8_t val);
  335. /** Return the value of the status field of the socks4_server_reply_t
  336. * in 'inp'
  337. */
  338. uint8_t socks4_server_reply_get_status(const socks4_server_reply_t *inp);
  339. /** Set the value of the status field of the socks4_server_reply_t in
  340. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  341. * code on 'inp' on failure.
  342. */
  343. int socks4_server_reply_set_status(socks4_server_reply_t *inp, uint8_t val);
  344. /** Return the value of the port field of the socks4_server_reply_t in
  345. * 'inp'
  346. */
  347. uint16_t socks4_server_reply_get_port(const socks4_server_reply_t *inp);
  348. /** Set the value of the port field of the socks4_server_reply_t in
  349. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  350. * code on 'inp' on failure.
  351. */
  352. int socks4_server_reply_set_port(socks4_server_reply_t *inp, uint16_t val);
  353. /** Return the value of the addr field of the socks4_server_reply_t in
  354. * 'inp'
  355. */
  356. uint32_t socks4_server_reply_get_addr(const socks4_server_reply_t *inp);
  357. /** Set the value of the addr field of the socks4_server_reply_t in
  358. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  359. * code on 'inp' on failure.
  360. */
  361. int socks4_server_reply_set_addr(socks4_server_reply_t *inp, uint32_t val);
  362. /** Return a newly allocated socks5_client_userpass_auth with all
  363. * elements set to zero.
  364. */
  365. socks5_client_userpass_auth_t *socks5_client_userpass_auth_new(void);
  366. /** Release all storage held by the socks5_client_userpass_auth in
  367. * 'victim'. (Do nothing if 'victim' is NULL.)
  368. */
  369. void socks5_client_userpass_auth_free(socks5_client_userpass_auth_t *victim);
  370. /** Try to parse a socks5_client_userpass_auth from the buffer in
  371. * 'input', using up to 'len_in' bytes from the input buffer. On
  372. * success, return the number of bytes consumed and set *output to the
  373. * newly allocated socks5_client_userpass_auth_t. On failure, return
  374. * -2 if the input appears truncated, and -1 if the input is otherwise
  375. * invalid.
  376. */
  377. ssize_t socks5_client_userpass_auth_parse(socks5_client_userpass_auth_t **output, const uint8_t *input, const size_t len_in);
  378. /** Return the number of bytes we expect to need to encode the
  379. * socks5_client_userpass_auth in 'obj'. On failure, return a negative
  380. * value. Note that this value may be an overestimate, and can even be
  381. * an underestimate for certain unencodeable objects.
  382. */
  383. ssize_t socks5_client_userpass_auth_encoded_len(const socks5_client_userpass_auth_t *obj);
  384. /** Try to encode the socks5_client_userpass_auth from 'input' into
  385. * the buffer at 'output', using up to 'avail' bytes of the output
  386. * buffer. On success, return the number of bytes used. On failure,
  387. * return -2 if the buffer was not long enough, and -1 if the input
  388. * was invalid.
  389. */
  390. ssize_t socks5_client_userpass_auth_encode(uint8_t *output, size_t avail, const socks5_client_userpass_auth_t *input);
  391. /** Check whether the internal state of the
  392. * socks5_client_userpass_auth in 'obj' is consistent. Return NULL if
  393. * it is, and a short message if it is not.
  394. */
  395. const char *socks5_client_userpass_auth_check(const socks5_client_userpass_auth_t *obj);
  396. /** Clear any errors that were set on the object 'obj' by its setter
  397. * functions. Return true iff errors were cleared.
  398. */
  399. int socks5_client_userpass_auth_clear_errors(socks5_client_userpass_auth_t *obj);
  400. /** Return the value of the version field of the
  401. * socks5_client_userpass_auth_t in 'inp'
  402. */
  403. uint8_t socks5_client_userpass_auth_get_version(const socks5_client_userpass_auth_t *inp);
  404. /** Set the value of the version field of the
  405. * socks5_client_userpass_auth_t in 'inp' to 'val'. Return 0 on
  406. * success; return -1 and set the error code on 'inp' on failure.
  407. */
  408. int socks5_client_userpass_auth_set_version(socks5_client_userpass_auth_t *inp, uint8_t val);
  409. /** Return the value of the username_len field of the
  410. * socks5_client_userpass_auth_t in 'inp'
  411. */
  412. uint8_t socks5_client_userpass_auth_get_username_len(const socks5_client_userpass_auth_t *inp);
  413. /** Set the value of the username_len field of the
  414. * socks5_client_userpass_auth_t in 'inp' to 'val'. Return 0 on
  415. * success; return -1 and set the error code on 'inp' on failure.
  416. */
  417. int socks5_client_userpass_auth_set_username_len(socks5_client_userpass_auth_t *inp, uint8_t val);
  418. /** Return the length of the dynamic array holding the username field
  419. * of the socks5_client_userpass_auth_t in 'inp'.
  420. */
  421. size_t socks5_client_userpass_auth_getlen_username(const socks5_client_userpass_auth_t *inp);
  422. /** Return the element at position 'idx' of the dynamic array field
  423. * username of the socks5_client_userpass_auth_t in 'inp'.
  424. */
  425. char socks5_client_userpass_auth_get_username(socks5_client_userpass_auth_t *inp, size_t idx);
  426. /** As socks5_client_userpass_auth_get_username, but take and return a
  427. * const pointer
  428. */
  429. char socks5_client_userpass_auth_getconst_username(const socks5_client_userpass_auth_t *inp, size_t idx);
  430. /** Change the element at position 'idx' of the dynamic array field
  431. * username of the socks5_client_userpass_auth_t in 'inp', so that it
  432. * will hold the value 'elt'.
  433. */
  434. int socks5_client_userpass_auth_set_username(socks5_client_userpass_auth_t *inp, size_t idx, char elt);
  435. /** Append a new element 'elt' to the dynamic array field username of
  436. * the socks5_client_userpass_auth_t in 'inp'.
  437. */
  438. int socks5_client_userpass_auth_add_username(socks5_client_userpass_auth_t *inp, char elt);
  439. /** Return a pointer to the variable-length array field username of
  440. * 'inp'.
  441. */
  442. char * socks5_client_userpass_auth_getarray_username(socks5_client_userpass_auth_t *inp);
  443. /** As socks5_client_userpass_auth_get_username, but take and return a
  444. * const pointer
  445. */
  446. const char * socks5_client_userpass_auth_getconstarray_username(const socks5_client_userpass_auth_t *inp);
  447. /** Change the length of the variable-length array field username of
  448. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  449. * return -1 and set the error code on 'inp' on failure.
  450. */
  451. int socks5_client_userpass_auth_setlen_username(socks5_client_userpass_auth_t *inp, size_t newlen);
  452. /** Return the value of the username field of a
  453. * socks5_client_userpass_auth_t as a NUL-terminated string.
  454. */
  455. const char * socks5_client_userpass_auth_getstr_username(socks5_client_userpass_auth_t *inp);
  456. /** Set the value of the username field of a
  457. * socks5_client_userpass_auth_t to a given string of length 'len'.
  458. * Return 0 on success; return -1 and set the error code on 'inp' on
  459. * failure.
  460. */
  461. int socks5_client_userpass_auth_setstr0_username(socks5_client_userpass_auth_t *inp, const char *val, size_t len);
  462. /** Set the value of the username field of a
  463. * socks5_client_userpass_auth_t to a given NUL-terminated string.
  464. * Return 0 on success; return -1 and set the error code on 'inp' on
  465. * failure.
  466. */
  467. int socks5_client_userpass_auth_setstr_username(socks5_client_userpass_auth_t *inp, const char *val);
  468. /** Return the value of the passwd_len field of the
  469. * socks5_client_userpass_auth_t in 'inp'
  470. */
  471. uint8_t socks5_client_userpass_auth_get_passwd_len(const socks5_client_userpass_auth_t *inp);
  472. /** Set the value of the passwd_len field of the
  473. * socks5_client_userpass_auth_t in 'inp' to 'val'. Return 0 on
  474. * success; return -1 and set the error code on 'inp' on failure.
  475. */
  476. int socks5_client_userpass_auth_set_passwd_len(socks5_client_userpass_auth_t *inp, uint8_t val);
  477. /** Return the length of the dynamic array holding the passwd field of
  478. * the socks5_client_userpass_auth_t in 'inp'.
  479. */
  480. size_t socks5_client_userpass_auth_getlen_passwd(const socks5_client_userpass_auth_t *inp);
  481. /** Return the element at position 'idx' of the dynamic array field
  482. * passwd of the socks5_client_userpass_auth_t in 'inp'.
  483. */
  484. char socks5_client_userpass_auth_get_passwd(socks5_client_userpass_auth_t *inp, size_t idx);
  485. /** As socks5_client_userpass_auth_get_passwd, but take and return a
  486. * const pointer
  487. */
  488. char socks5_client_userpass_auth_getconst_passwd(const socks5_client_userpass_auth_t *inp, size_t idx);
  489. /** Change the element at position 'idx' of the dynamic array field
  490. * passwd of the socks5_client_userpass_auth_t in 'inp', so that it
  491. * will hold the value 'elt'.
  492. */
  493. int socks5_client_userpass_auth_set_passwd(socks5_client_userpass_auth_t *inp, size_t idx, char elt);
  494. /** Append a new element 'elt' to the dynamic array field passwd of
  495. * the socks5_client_userpass_auth_t in 'inp'.
  496. */
  497. int socks5_client_userpass_auth_add_passwd(socks5_client_userpass_auth_t *inp, char elt);
  498. /** Return a pointer to the variable-length array field passwd of
  499. * 'inp'.
  500. */
  501. char * socks5_client_userpass_auth_getarray_passwd(socks5_client_userpass_auth_t *inp);
  502. /** As socks5_client_userpass_auth_get_passwd, but take and return a
  503. * const pointer
  504. */
  505. const char * socks5_client_userpass_auth_getconstarray_passwd(const socks5_client_userpass_auth_t *inp);
  506. /** Change the length of the variable-length array field passwd of
  507. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  508. * return -1 and set the error code on 'inp' on failure.
  509. */
  510. int socks5_client_userpass_auth_setlen_passwd(socks5_client_userpass_auth_t *inp, size_t newlen);
  511. /** Return the value of the passwd field of a
  512. * socks5_client_userpass_auth_t as a NUL-terminated string.
  513. */
  514. const char * socks5_client_userpass_auth_getstr_passwd(socks5_client_userpass_auth_t *inp);
  515. /** Set the value of the passwd field of a
  516. * socks5_client_userpass_auth_t to a given string of length 'len'.
  517. * Return 0 on success; return -1 and set the error code on 'inp' on
  518. * failure.
  519. */
  520. int socks5_client_userpass_auth_setstr0_passwd(socks5_client_userpass_auth_t *inp, const char *val, size_t len);
  521. /** Set the value of the passwd field of a
  522. * socks5_client_userpass_auth_t to a given NUL-terminated string.
  523. * Return 0 on success; return -1 and set the error code on 'inp' on
  524. * failure.
  525. */
  526. int socks5_client_userpass_auth_setstr_passwd(socks5_client_userpass_auth_t *inp, const char *val);
  527. /** Return a newly allocated socks5_client_version with all elements
  528. * set to zero.
  529. */
  530. socks5_client_version_t *socks5_client_version_new(void);
  531. /** Release all storage held by the socks5_client_version in 'victim'.
  532. * (Do nothing if 'victim' is NULL.)
  533. */
  534. void socks5_client_version_free(socks5_client_version_t *victim);
  535. /** Try to parse a socks5_client_version from the buffer in 'input',
  536. * using up to 'len_in' bytes from the input buffer. On success,
  537. * return the number of bytes consumed and set *output to the newly
  538. * allocated socks5_client_version_t. On failure, return -2 if the
  539. * input appears truncated, and -1 if the input is otherwise invalid.
  540. */
  541. ssize_t socks5_client_version_parse(socks5_client_version_t **output, const uint8_t *input, const size_t len_in);
  542. /** Return the number of bytes we expect to need to encode the
  543. * socks5_client_version in 'obj'. On failure, return a negative
  544. * value. Note that this value may be an overestimate, and can even be
  545. * an underestimate for certain unencodeable objects.
  546. */
  547. ssize_t socks5_client_version_encoded_len(const socks5_client_version_t *obj);
  548. /** Try to encode the socks5_client_version from 'input' into the
  549. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  550. * On success, return the number of bytes used. On failure, return -2
  551. * if the buffer was not long enough, and -1 if the input was invalid.
  552. */
  553. ssize_t socks5_client_version_encode(uint8_t *output, size_t avail, const socks5_client_version_t *input);
  554. /** Check whether the internal state of the socks5_client_version in
  555. * 'obj' is consistent. Return NULL if it is, and a short message if
  556. * it is not.
  557. */
  558. const char *socks5_client_version_check(const socks5_client_version_t *obj);
  559. /** Clear any errors that were set on the object 'obj' by its setter
  560. * functions. Return true iff errors were cleared.
  561. */
  562. int socks5_client_version_clear_errors(socks5_client_version_t *obj);
  563. /** Return the value of the version field of the
  564. * socks5_client_version_t in 'inp'
  565. */
  566. uint8_t socks5_client_version_get_version(const socks5_client_version_t *inp);
  567. /** Set the value of the version field of the socks5_client_version_t
  568. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  569. * code on 'inp' on failure.
  570. */
  571. int socks5_client_version_set_version(socks5_client_version_t *inp, uint8_t val);
  572. /** Return the value of the n_methods field of the
  573. * socks5_client_version_t in 'inp'
  574. */
  575. uint8_t socks5_client_version_get_n_methods(const socks5_client_version_t *inp);
  576. /** Set the value of the n_methods field of the
  577. * socks5_client_version_t in 'inp' to 'val'. Return 0 on success;
  578. * return -1 and set the error code on 'inp' on failure.
  579. */
  580. int socks5_client_version_set_n_methods(socks5_client_version_t *inp, uint8_t val);
  581. /** Return the length of the dynamic array holding the methods field
  582. * of the socks5_client_version_t in 'inp'.
  583. */
  584. size_t socks5_client_version_getlen_methods(const socks5_client_version_t *inp);
  585. /** Return the element at position 'idx' of the dynamic array field
  586. * methods of the socks5_client_version_t in 'inp'.
  587. */
  588. uint8_t socks5_client_version_get_methods(socks5_client_version_t *inp, size_t idx);
  589. /** As socks5_client_version_get_methods, but take and return a const
  590. * pointer
  591. */
  592. uint8_t socks5_client_version_getconst_methods(const socks5_client_version_t *inp, size_t idx);
  593. /** Change the element at position 'idx' of the dynamic array field
  594. * methods of the socks5_client_version_t in 'inp', so that it will
  595. * hold the value 'elt'.
  596. */
  597. int socks5_client_version_set_methods(socks5_client_version_t *inp, size_t idx, uint8_t elt);
  598. /** Append a new element 'elt' to the dynamic array field methods of
  599. * the socks5_client_version_t in 'inp'.
  600. */
  601. int socks5_client_version_add_methods(socks5_client_version_t *inp, uint8_t elt);
  602. /** Return a pointer to the variable-length array field methods of
  603. * 'inp'.
  604. */
  605. uint8_t * socks5_client_version_getarray_methods(socks5_client_version_t *inp);
  606. /** As socks5_client_version_get_methods, but take and return a const
  607. * pointer
  608. */
  609. const uint8_t * socks5_client_version_getconstarray_methods(const socks5_client_version_t *inp);
  610. /** Change the length of the variable-length array field methods of
  611. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  612. * return -1 and set the error code on 'inp' on failure.
  613. */
  614. int socks5_client_version_setlen_methods(socks5_client_version_t *inp, size_t newlen);
  615. /** Return a newly allocated socks5_server_method with all elements
  616. * set to zero.
  617. */
  618. socks5_server_method_t *socks5_server_method_new(void);
  619. /** Release all storage held by the socks5_server_method in 'victim'.
  620. * (Do nothing if 'victim' is NULL.)
  621. */
  622. void socks5_server_method_free(socks5_server_method_t *victim);
  623. /** Try to parse a socks5_server_method from the buffer in 'input',
  624. * using up to 'len_in' bytes from the input buffer. On success,
  625. * return the number of bytes consumed and set *output to the newly
  626. * allocated socks5_server_method_t. On failure, return -2 if the
  627. * input appears truncated, and -1 if the input is otherwise invalid.
  628. */
  629. ssize_t socks5_server_method_parse(socks5_server_method_t **output, const uint8_t *input, const size_t len_in);
  630. /** Return the number of bytes we expect to need to encode the
  631. * socks5_server_method in 'obj'. On failure, return a negative value.
  632. * Note that this value may be an overestimate, and can even be an
  633. * underestimate for certain unencodeable objects.
  634. */
  635. ssize_t socks5_server_method_encoded_len(const socks5_server_method_t *obj);
  636. /** Try to encode the socks5_server_method from 'input' into the
  637. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  638. * On success, return the number of bytes used. On failure, return -2
  639. * if the buffer was not long enough, and -1 if the input was invalid.
  640. */
  641. ssize_t socks5_server_method_encode(uint8_t *output, size_t avail, const socks5_server_method_t *input);
  642. /** Check whether the internal state of the socks5_server_method in
  643. * 'obj' is consistent. Return NULL if it is, and a short message if
  644. * it is not.
  645. */
  646. const char *socks5_server_method_check(const socks5_server_method_t *obj);
  647. /** Clear any errors that were set on the object 'obj' by its setter
  648. * functions. Return true iff errors were cleared.
  649. */
  650. int socks5_server_method_clear_errors(socks5_server_method_t *obj);
  651. /** Return the value of the version field of the
  652. * socks5_server_method_t in 'inp'
  653. */
  654. uint8_t socks5_server_method_get_version(const socks5_server_method_t *inp);
  655. /** Set the value of the version field of the socks5_server_method_t
  656. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  657. * code on 'inp' on failure.
  658. */
  659. int socks5_server_method_set_version(socks5_server_method_t *inp, uint8_t val);
  660. /** Return the value of the method field of the socks5_server_method_t
  661. * in 'inp'
  662. */
  663. uint8_t socks5_server_method_get_method(const socks5_server_method_t *inp);
  664. /** Set the value of the method field of the socks5_server_method_t in
  665. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  666. * code on 'inp' on failure.
  667. */
  668. int socks5_server_method_set_method(socks5_server_method_t *inp, uint8_t val);
  669. /** Return a newly allocated socks5_server_userpass_auth with all
  670. * elements set to zero.
  671. */
  672. socks5_server_userpass_auth_t *socks5_server_userpass_auth_new(void);
  673. /** Release all storage held by the socks5_server_userpass_auth in
  674. * 'victim'. (Do nothing if 'victim' is NULL.)
  675. */
  676. void socks5_server_userpass_auth_free(socks5_server_userpass_auth_t *victim);
  677. /** Try to parse a socks5_server_userpass_auth from the buffer in
  678. * 'input', using up to 'len_in' bytes from the input buffer. On
  679. * success, return the number of bytes consumed and set *output to the
  680. * newly allocated socks5_server_userpass_auth_t. On failure, return
  681. * -2 if the input appears truncated, and -1 if the input is otherwise
  682. * invalid.
  683. */
  684. ssize_t socks5_server_userpass_auth_parse(socks5_server_userpass_auth_t **output, const uint8_t *input, const size_t len_in);
  685. /** Return the number of bytes we expect to need to encode the
  686. * socks5_server_userpass_auth in 'obj'. On failure, return a negative
  687. * value. Note that this value may be an overestimate, and can even be
  688. * an underestimate for certain unencodeable objects.
  689. */
  690. ssize_t socks5_server_userpass_auth_encoded_len(const socks5_server_userpass_auth_t *obj);
  691. /** Try to encode the socks5_server_userpass_auth from 'input' into
  692. * the buffer at 'output', using up to 'avail' bytes of the output
  693. * buffer. On success, return the number of bytes used. On failure,
  694. * return -2 if the buffer was not long enough, and -1 if the input
  695. * was invalid.
  696. */
  697. ssize_t socks5_server_userpass_auth_encode(uint8_t *output, size_t avail, const socks5_server_userpass_auth_t *input);
  698. /** Check whether the internal state of the
  699. * socks5_server_userpass_auth in 'obj' is consistent. Return NULL if
  700. * it is, and a short message if it is not.
  701. */
  702. const char *socks5_server_userpass_auth_check(const socks5_server_userpass_auth_t *obj);
  703. /** Clear any errors that were set on the object 'obj' by its setter
  704. * functions. Return true iff errors were cleared.
  705. */
  706. int socks5_server_userpass_auth_clear_errors(socks5_server_userpass_auth_t *obj);
  707. /** Return the value of the version field of the
  708. * socks5_server_userpass_auth_t in 'inp'
  709. */
  710. uint8_t socks5_server_userpass_auth_get_version(const socks5_server_userpass_auth_t *inp);
  711. /** Set the value of the version field of the
  712. * socks5_server_userpass_auth_t in 'inp' to 'val'. Return 0 on
  713. * success; return -1 and set the error code on 'inp' on failure.
  714. */
  715. int socks5_server_userpass_auth_set_version(socks5_server_userpass_auth_t *inp, uint8_t val);
  716. /** Return the value of the status field of the
  717. * socks5_server_userpass_auth_t in 'inp'
  718. */
  719. uint8_t socks5_server_userpass_auth_get_status(const socks5_server_userpass_auth_t *inp);
  720. /** Set the value of the status field of the
  721. * socks5_server_userpass_auth_t in 'inp' to 'val'. Return 0 on
  722. * success; return -1 and set the error code on 'inp' on failure.
  723. */
  724. int socks5_server_userpass_auth_set_status(socks5_server_userpass_auth_t *inp, uint8_t val);
  725. /** Return a newly allocated socks5_client_request with all elements
  726. * set to zero.
  727. */
  728. socks5_client_request_t *socks5_client_request_new(void);
  729. /** Release all storage held by the socks5_client_request in 'victim'.
  730. * (Do nothing if 'victim' is NULL.)
  731. */
  732. void socks5_client_request_free(socks5_client_request_t *victim);
  733. /** Try to parse a socks5_client_request from the buffer in 'input',
  734. * using up to 'len_in' bytes from the input buffer. On success,
  735. * return the number of bytes consumed and set *output to the newly
  736. * allocated socks5_client_request_t. On failure, return -2 if the
  737. * input appears truncated, and -1 if the input is otherwise invalid.
  738. */
  739. ssize_t socks5_client_request_parse(socks5_client_request_t **output, const uint8_t *input, const size_t len_in);
  740. /** Return the number of bytes we expect to need to encode the
  741. * socks5_client_request in 'obj'. On failure, return a negative
  742. * value. Note that this value may be an overestimate, and can even be
  743. * an underestimate for certain unencodeable objects.
  744. */
  745. ssize_t socks5_client_request_encoded_len(const socks5_client_request_t *obj);
  746. /** Try to encode the socks5_client_request from 'input' into the
  747. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  748. * On success, return the number of bytes used. On failure, return -2
  749. * if the buffer was not long enough, and -1 if the input was invalid.
  750. */
  751. ssize_t socks5_client_request_encode(uint8_t *output, size_t avail, const socks5_client_request_t *input);
  752. /** Check whether the internal state of the socks5_client_request in
  753. * 'obj' is consistent. Return NULL if it is, and a short message if
  754. * it is not.
  755. */
  756. const char *socks5_client_request_check(const socks5_client_request_t *obj);
  757. /** Clear any errors that were set on the object 'obj' by its setter
  758. * functions. Return true iff errors were cleared.
  759. */
  760. int socks5_client_request_clear_errors(socks5_client_request_t *obj);
  761. /** Return the value of the version field of the
  762. * socks5_client_request_t in 'inp'
  763. */
  764. uint8_t socks5_client_request_get_version(const socks5_client_request_t *inp);
  765. /** Set the value of the version field of the socks5_client_request_t
  766. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  767. * code on 'inp' on failure.
  768. */
  769. int socks5_client_request_set_version(socks5_client_request_t *inp, uint8_t val);
  770. /** Return the value of the command field of the
  771. * socks5_client_request_t in 'inp'
  772. */
  773. uint8_t socks5_client_request_get_command(const socks5_client_request_t *inp);
  774. /** Set the value of the command field of the socks5_client_request_t
  775. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  776. * code on 'inp' on failure.
  777. */
  778. int socks5_client_request_set_command(socks5_client_request_t *inp, uint8_t val);
  779. /** Return the value of the reserved field of the
  780. * socks5_client_request_t in 'inp'
  781. */
  782. uint8_t socks5_client_request_get_reserved(const socks5_client_request_t *inp);
  783. /** Set the value of the reserved field of the socks5_client_request_t
  784. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  785. * code on 'inp' on failure.
  786. */
  787. int socks5_client_request_set_reserved(socks5_client_request_t *inp, uint8_t val);
  788. /** Return the value of the atype field of the socks5_client_request_t
  789. * in 'inp'
  790. */
  791. uint8_t socks5_client_request_get_atype(const socks5_client_request_t *inp);
  792. /** Set the value of the atype field of the socks5_client_request_t in
  793. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  794. * code on 'inp' on failure.
  795. */
  796. int socks5_client_request_set_atype(socks5_client_request_t *inp, uint8_t val);
  797. /** Return the value of the dest_addr_ipv4 field of the
  798. * socks5_client_request_t in 'inp'
  799. */
  800. uint32_t socks5_client_request_get_dest_addr_ipv4(const socks5_client_request_t *inp);
  801. /** Set the value of the dest_addr_ipv4 field of the
  802. * socks5_client_request_t in 'inp' to 'val'. Return 0 on success;
  803. * return -1 and set the error code on 'inp' on failure.
  804. */
  805. int socks5_client_request_set_dest_addr_ipv4(socks5_client_request_t *inp, uint32_t val);
  806. /** Return the (constant) length of the array holding the
  807. * dest_addr_ipv6 field of the socks5_client_request_t in 'inp'.
  808. */
  809. size_t socks5_client_request_getlen_dest_addr_ipv6(const socks5_client_request_t *inp);
  810. /** Return the element at position 'idx' of the fixed array field
  811. * dest_addr_ipv6 of the socks5_client_request_t in 'inp'.
  812. */
  813. uint8_t socks5_client_request_get_dest_addr_ipv6(socks5_client_request_t *inp, size_t idx);
  814. /** As socks5_client_request_get_dest_addr_ipv6, but take and return a
  815. * const pointer
  816. */
  817. uint8_t socks5_client_request_getconst_dest_addr_ipv6(const socks5_client_request_t *inp, size_t idx);
  818. /** Change the element at position 'idx' of the fixed array field
  819. * dest_addr_ipv6 of the socks5_client_request_t in 'inp', so that it
  820. * will hold the value 'elt'.
  821. */
  822. int socks5_client_request_set_dest_addr_ipv6(socks5_client_request_t *inp, size_t idx, uint8_t elt);
  823. /** Return a pointer to the 16-element array field dest_addr_ipv6 of
  824. * 'inp'.
  825. */
  826. uint8_t * socks5_client_request_getarray_dest_addr_ipv6(socks5_client_request_t *inp);
  827. /** As socks5_client_request_get_dest_addr_ipv6, but take and return a
  828. * const pointer
  829. */
  830. const uint8_t * socks5_client_request_getconstarray_dest_addr_ipv6(const socks5_client_request_t *inp);
  831. /** Return the value of the dest_addr_domainname field of the
  832. * socks5_client_request_t in 'inp'
  833. */
  834. struct domainname_st * socks5_client_request_get_dest_addr_domainname(socks5_client_request_t *inp);
  835. /** As socks5_client_request_get_dest_addr_domainname, but take and
  836. * return a const pointer
  837. */
  838. const struct domainname_st * socks5_client_request_getconst_dest_addr_domainname(const socks5_client_request_t *inp);
  839. /** Set the value of the dest_addr_domainname field of the
  840. * socks5_client_request_t in 'inp' to 'val'. Free the old value if
  841. * any. Steals the referenceto 'val'.Return 0 on success; return -1
  842. * and set the error code on 'inp' on failure.
  843. */
  844. int socks5_client_request_set_dest_addr_domainname(socks5_client_request_t *inp, struct domainname_st *val);
  845. /** As socks5_client_request_set_dest_addr_domainname, but does not
  846. * free the previous value.
  847. */
  848. int socks5_client_request_set0_dest_addr_domainname(socks5_client_request_t *inp, struct domainname_st *val);
  849. /** Return the value of the dest_port field of the
  850. * socks5_client_request_t in 'inp'
  851. */
  852. uint16_t socks5_client_request_get_dest_port(const socks5_client_request_t *inp);
  853. /** Set the value of the dest_port field of the
  854. * socks5_client_request_t in 'inp' to 'val'. Return 0 on success;
  855. * return -1 and set the error code on 'inp' on failure.
  856. */
  857. int socks5_client_request_set_dest_port(socks5_client_request_t *inp, uint16_t val);
  858. /** Return a newly allocated socks5_server_reply with all elements set
  859. * to zero.
  860. */
  861. socks5_server_reply_t *socks5_server_reply_new(void);
  862. /** Release all storage held by the socks5_server_reply in 'victim'.
  863. * (Do nothing if 'victim' is NULL.)
  864. */
  865. void socks5_server_reply_free(socks5_server_reply_t *victim);
  866. /** Try to parse a socks5_server_reply from the buffer in 'input',
  867. * using up to 'len_in' bytes from the input buffer. On success,
  868. * return the number of bytes consumed and set *output to the newly
  869. * allocated socks5_server_reply_t. On failure, return -2 if the input
  870. * appears truncated, and -1 if the input is otherwise invalid.
  871. */
  872. ssize_t socks5_server_reply_parse(socks5_server_reply_t **output, const uint8_t *input, const size_t len_in);
  873. /** Return the number of bytes we expect to need to encode the
  874. * socks5_server_reply in 'obj'. On failure, return a negative value.
  875. * Note that this value may be an overestimate, and can even be an
  876. * underestimate for certain unencodeable objects.
  877. */
  878. ssize_t socks5_server_reply_encoded_len(const socks5_server_reply_t *obj);
  879. /** Try to encode the socks5_server_reply from 'input' into the buffer
  880. * at 'output', using up to 'avail' bytes of the output buffer. On
  881. * success, return the number of bytes used. On failure, return -2 if
  882. * the buffer was not long enough, and -1 if the input was invalid.
  883. */
  884. ssize_t socks5_server_reply_encode(uint8_t *output, size_t avail, const socks5_server_reply_t *input);
  885. /** Check whether the internal state of the socks5_server_reply in
  886. * 'obj' is consistent. Return NULL if it is, and a short message if
  887. * it is not.
  888. */
  889. const char *socks5_server_reply_check(const socks5_server_reply_t *obj);
  890. /** Clear any errors that were set on the object 'obj' by its setter
  891. * functions. Return true iff errors were cleared.
  892. */
  893. int socks5_server_reply_clear_errors(socks5_server_reply_t *obj);
  894. /** Return the value of the version field of the socks5_server_reply_t
  895. * in 'inp'
  896. */
  897. uint8_t socks5_server_reply_get_version(const socks5_server_reply_t *inp);
  898. /** Set the value of the version field of the socks5_server_reply_t in
  899. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  900. * code on 'inp' on failure.
  901. */
  902. int socks5_server_reply_set_version(socks5_server_reply_t *inp, uint8_t val);
  903. /** Return the value of the reply field of the socks5_server_reply_t
  904. * in 'inp'
  905. */
  906. uint8_t socks5_server_reply_get_reply(const socks5_server_reply_t *inp);
  907. /** Set the value of the reply field of the socks5_server_reply_t in
  908. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  909. * code on 'inp' on failure.
  910. */
  911. int socks5_server_reply_set_reply(socks5_server_reply_t *inp, uint8_t val);
  912. /** Return the value of the reserved field of the
  913. * socks5_server_reply_t in 'inp'
  914. */
  915. uint8_t socks5_server_reply_get_reserved(const socks5_server_reply_t *inp);
  916. /** Set the value of the reserved field of the socks5_server_reply_t
  917. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  918. * code on 'inp' on failure.
  919. */
  920. int socks5_server_reply_set_reserved(socks5_server_reply_t *inp, uint8_t val);
  921. /** Return the value of the atype field of the socks5_server_reply_t
  922. * in 'inp'
  923. */
  924. uint8_t socks5_server_reply_get_atype(const socks5_server_reply_t *inp);
  925. /** Set the value of the atype field of the socks5_server_reply_t in
  926. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  927. * code on 'inp' on failure.
  928. */
  929. int socks5_server_reply_set_atype(socks5_server_reply_t *inp, uint8_t val);
  930. /** Return the value of the bind_addr_ipv4 field of the
  931. * socks5_server_reply_t in 'inp'
  932. */
  933. uint32_t socks5_server_reply_get_bind_addr_ipv4(const socks5_server_reply_t *inp);
  934. /** Set the value of the bind_addr_ipv4 field of the
  935. * socks5_server_reply_t in 'inp' to 'val'. Return 0 on success;
  936. * return -1 and set the error code on 'inp' on failure.
  937. */
  938. int socks5_server_reply_set_bind_addr_ipv4(socks5_server_reply_t *inp, uint32_t val);
  939. /** Return the (constant) length of the array holding the
  940. * bind_addr_ipv6 field of the socks5_server_reply_t in 'inp'.
  941. */
  942. size_t socks5_server_reply_getlen_bind_addr_ipv6(const socks5_server_reply_t *inp);
  943. /** Return the element at position 'idx' of the fixed array field
  944. * bind_addr_ipv6 of the socks5_server_reply_t in 'inp'.
  945. */
  946. uint8_t socks5_server_reply_get_bind_addr_ipv6(socks5_server_reply_t *inp, size_t idx);
  947. /** As socks5_server_reply_get_bind_addr_ipv6, but take and return a
  948. * const pointer
  949. */
  950. uint8_t socks5_server_reply_getconst_bind_addr_ipv6(const socks5_server_reply_t *inp, size_t idx);
  951. /** Change the element at position 'idx' of the fixed array field
  952. * bind_addr_ipv6 of the socks5_server_reply_t in 'inp', so that it
  953. * will hold the value 'elt'.
  954. */
  955. int socks5_server_reply_set_bind_addr_ipv6(socks5_server_reply_t *inp, size_t idx, uint8_t elt);
  956. /** Return a pointer to the 16-element array field bind_addr_ipv6 of
  957. * 'inp'.
  958. */
  959. uint8_t * socks5_server_reply_getarray_bind_addr_ipv6(socks5_server_reply_t *inp);
  960. /** As socks5_server_reply_get_bind_addr_ipv6, but take and return a
  961. * const pointer
  962. */
  963. const uint8_t * socks5_server_reply_getconstarray_bind_addr_ipv6(const socks5_server_reply_t *inp);
  964. /** Return the value of the bind_addr_domainname field of the
  965. * socks5_server_reply_t in 'inp'
  966. */
  967. struct domainname_st * socks5_server_reply_get_bind_addr_domainname(socks5_server_reply_t *inp);
  968. /** As socks5_server_reply_get_bind_addr_domainname, but take and
  969. * return a const pointer
  970. */
  971. const struct domainname_st * socks5_server_reply_getconst_bind_addr_domainname(const socks5_server_reply_t *inp);
  972. /** Set the value of the bind_addr_domainname field of the
  973. * socks5_server_reply_t in 'inp' to 'val'. Free the old value if any.
  974. * Steals the referenceto 'val'.Return 0 on success; return -1 and set
  975. * the error code on 'inp' on failure.
  976. */
  977. int socks5_server_reply_set_bind_addr_domainname(socks5_server_reply_t *inp, struct domainname_st *val);
  978. /** As socks5_server_reply_set_bind_addr_domainname, but does not free
  979. * the previous value.
  980. */
  981. int socks5_server_reply_set0_bind_addr_domainname(socks5_server_reply_t *inp, struct domainname_st *val);
  982. /** Return the value of the bind_port field of the
  983. * socks5_server_reply_t in 'inp'
  984. */
  985. uint16_t socks5_server_reply_get_bind_port(const socks5_server_reply_t *inp);
  986. /** Set the value of the bind_port field of the socks5_server_reply_t
  987. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  988. * code on 'inp' on failure.
  989. */
  990. int socks5_server_reply_set_bind_port(socks5_server_reply_t *inp, uint16_t val);
  991. #endif