bd848f28c50f8a22884fd354a0937d5a19ad6683
[platform/upstream/iotivity.git] / extlibs / tinydtls / session.h
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 "dtls_config.h"
32 #include "tinydtls.h"
33 #include "global.h"
34
35 #ifdef WITH_CONTIKI
36 #include "ip/uip.h"
37 typedef struct {
38   unsigned char size;
39   uip_ipaddr_t addr;
40   unsigned short port;
41   int ifindex;
42 } session_t;
43
44 #else /* WITH_CONTIKI */
45
46 #ifdef HAVE_SYS_SOCKET_H
47 #include <sys/socket.h>
48 #endif
49 #ifdef HAVE_NETINET_IN_H
50 #include <netinet/in.h>
51 #endif
52 #ifdef HAVE_ARPA_INET_H
53 #include <arpa/inet.h>
54 #endif
55 #ifdef HAVE_WINSOCK2_H
56 #include <winsock2.h>
57 #endif
58 #ifdef HAVE_WS2TCPIP_H
59 #include <ws2tcpip.h>
60 #endif
61 #include <stdint.h>
62
63 typedef struct {
64   socklen_t size;               /**< size of addr */
65   union {
66     struct sockaddr     sa;
67     struct sockaddr_storage st;
68     struct sockaddr_in  sin;
69     struct sockaddr_in6 sin6;
70   } addr;
71   uint8_t ifindex;
72 } session_t;
73 #endif /* WITH_CONTIKI */
74
75 /** 
76  * Resets the given session_t object @p sess to its default
77  * values.  In particular, the member rlen must be initialized to the
78  * available size for storing addresses.
79  * 
80  * @param sess The session_t object to initialize.
81  */
82 void dtls_session_init(session_t *sess);
83
84 /**
85  * Compares the given session objects. This function returns @c 0
86  * when @p a and @p b differ, @c 1 otherwise.
87  */
88 int dtls_session_equals(const session_t *a, const session_t *b);
89
90 #endif /* _DTLS_SESSION_H_ */