ngtcp2_path.c 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ngtcp2
  3. *
  4. * Copyright (c) 2019 ngtcp2 contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include "ngtcp2_path.h"
  26. #include <string.h>
  27. #include "ngtcp2_addr.h"
  28. void ngtcp2_path_init(ngtcp2_path *path, const ngtcp2_addr *local,
  29. const ngtcp2_addr *remote) {
  30. path->local = *local;
  31. path->remote = *remote;
  32. }
  33. void ngtcp2_path_copy(ngtcp2_path *dest, const ngtcp2_path *src) {
  34. ngtcp2_addr_copy(&dest->local, &src->local);
  35. ngtcp2_addr_copy(&dest->remote, &src->remote);
  36. dest->user_data = src->user_data;
  37. }
  38. int ngtcp2_path_eq(const ngtcp2_path *a, const ngtcp2_path *b) {
  39. return ngtcp2_addr_eq(&a->local, &b->local) &&
  40. ngtcp2_addr_eq(&a->remote, &b->remote);
  41. }
  42. void ngtcp2_path_storage_init(ngtcp2_path_storage *ps,
  43. const ngtcp2_sockaddr *local_addr,
  44. ngtcp2_socklen local_addrlen,
  45. const ngtcp2_sockaddr *remote_addr,
  46. ngtcp2_socklen remote_addrlen, void *user_data) {
  47. ngtcp2_addr_init(&ps->path.local, (const ngtcp2_sockaddr *)&ps->local_addrbuf,
  48. 0);
  49. ngtcp2_addr_init(&ps->path.remote,
  50. (const ngtcp2_sockaddr *)&ps->remote_addrbuf, 0);
  51. ngtcp2_addr_copy_byte(&ps->path.local, local_addr, local_addrlen);
  52. ngtcp2_addr_copy_byte(&ps->path.remote, remote_addr, remote_addrlen);
  53. ps->path.user_data = user_data;
  54. }
  55. void ngtcp2_path_storage_init2(ngtcp2_path_storage *ps,
  56. const ngtcp2_path *path) {
  57. ngtcp2_path_storage_init(ps, path->local.addr, path->local.addrlen,
  58. path->remote.addr, path->remote.addrlen,
  59. path->user_data);
  60. }
  61. void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps) {
  62. ngtcp2_addr_init(&ps->path.local, (const ngtcp2_sockaddr *)&ps->local_addrbuf,
  63. 0);
  64. ngtcp2_addr_init(&ps->path.remote,
  65. (const ngtcp2_sockaddr *)&ps->remote_addrbuf, 0);
  66. ps->path.user_data = NULL;
  67. }