• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
27 #include <string.h>
28 
29 #include "ngtcp2_addr.h"
30 
ngtcp2_path_init(ngtcp2_path * path,const ngtcp2_addr * local,const ngtcp2_addr * remote)31 void ngtcp2_path_init(ngtcp2_path *path, const ngtcp2_addr *local,
32                       const ngtcp2_addr *remote) {
33   path->local = *local;
34   path->remote = *remote;
35 }
36 
ngtcp2_path_copy(ngtcp2_path * dest,const ngtcp2_path * src)37 void ngtcp2_path_copy(ngtcp2_path *dest, const ngtcp2_path *src) {
38   ngtcp2_addr_copy(&dest->local, &src->local);
39   ngtcp2_addr_copy(&dest->remote, &src->remote);
40   dest->user_data = src->user_data;
41 }
42 
ngtcp2_path_eq(const ngtcp2_path * a,const ngtcp2_path * b)43 int ngtcp2_path_eq(const ngtcp2_path *a, const ngtcp2_path *b) {
44   return ngtcp2_addr_eq(&a->local, &b->local) &&
45          ngtcp2_addr_eq(&a->remote, &b->remote);
46 }
47 
ngtcp2_path_storage_init(ngtcp2_path_storage * ps,const ngtcp2_sockaddr * local_addr,ngtcp2_socklen local_addrlen,const ngtcp2_sockaddr * remote_addr,ngtcp2_socklen remote_addrlen,void * user_data)48 void ngtcp2_path_storage_init(ngtcp2_path_storage *ps,
49                               const ngtcp2_sockaddr *local_addr,
50                               ngtcp2_socklen local_addrlen,
51                               const ngtcp2_sockaddr *remote_addr,
52                               ngtcp2_socklen remote_addrlen, void *user_data) {
53   ngtcp2_addr_init(&ps->path.local, (const ngtcp2_sockaddr *)&ps->local_addrbuf,
54                    0);
55   ngtcp2_addr_init(&ps->path.remote,
56                    (const ngtcp2_sockaddr *)&ps->remote_addrbuf, 0);
57 
58   ngtcp2_addr_copy_byte(&ps->path.local, local_addr, local_addrlen);
59   ngtcp2_addr_copy_byte(&ps->path.remote, remote_addr, remote_addrlen);
60 
61   ps->path.user_data = user_data;
62 }
63 
ngtcp2_path_storage_init2(ngtcp2_path_storage * ps,const ngtcp2_path * path)64 void ngtcp2_path_storage_init2(ngtcp2_path_storage *ps,
65                                const ngtcp2_path *path) {
66   ngtcp2_path_storage_init(ps, path->local.addr, path->local.addrlen,
67                            path->remote.addr, path->remote.addrlen,
68                            path->user_data);
69 }
70 
ngtcp2_path_storage_zero(ngtcp2_path_storage * ps)71 void ngtcp2_path_storage_zero(ngtcp2_path_storage *ps) {
72   ngtcp2_addr_init(&ps->path.local, (const ngtcp2_sockaddr *)&ps->local_addrbuf,
73                    0);
74   ngtcp2_addr_init(&ps->path.remote,
75                    (const ngtcp2_sockaddr *)&ps->remote_addrbuf, 0);
76   ps->path.user_data = NULL;
77 }
78