1 /* dtls -- a very basic DTLS implementation
2  *
3  * Copyright (C) 2011--2014 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without
8  * restriction, including without limitation the rights to use, copy,
9  * modify, merge, publish, distribute, sublicense, and/or sell copies
10  * of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef _DTLS_SESSION_H_
27 #define _DTLS_SESSION_H_
28 
29 #include <string.h>
30 
31 #include "tinydtls.h"
32 #include "global.h"
33 
34 #ifdef WITH_CONTIKI
35 #include "ip/uip.h"
36 typedef struct {
37   unsigned char size;
38   uip_ipaddr_t addr;
39   unsigned short port;
40   int ifindex;
41 } session_t;
42 
43 #else /* WITH_CONTIKI */
44 
45 #include <sys/socket.h>
46 #include <netinet/in.h>
47 #include <arpa/inet.h>
48 
49 typedef struct {
50   socklen_t size;		/**< size of addr */
51   union {
52     struct sockaddr     sa;
53     struct sockaddr_storage st;
54     struct sockaddr_in  sin;
55     struct sockaddr_in6 sin6;
56   } addr;
57   uint8_t ifindex;
58 } session_t;
59 #endif /* WITH_CONTIKI */
60 
61 /**
62  * Resets the given session_t object @p sess to its default
63  * values.  In particular, the member rlen must be initialized to the
64  * available size for storing addresses.
65  *
66  * @param sess The session_t object to initialize.
67  */
68 void dtls_session_init(session_t *sess);
69 
70 /**
71  * Compares the given session objects. This function returns @c 0
72  * when @p a and @p b differ, @c 1 otherwise.
73  */
74 int dtls_session_equals(const session_t *a, const session_t *b);
75 
76 #endif /* _DTLS_SESSION_H_ */
77