Wed Jan 8 2020 09:49:51

Asterisk developer's documentation


stun.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2008, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*!
20  * \file stun.h
21  * \brief STUN support.
22  *
23  * STUN is defined in RFC 3489.
24  */
25 
26 #ifndef _ASTERISK_STUN_H
27 #define _ASTERISK_STUN_H
28 
29 #include "asterisk/network.h"
30 
31 #if defined(__cplusplus) || defined(c_plusplus)
32 extern "C" {
33 #endif
34 
35 static const int STANDARD_STUN_PORT = 3478;
36 
40 };
41 
42 struct stun_attr;
43 
44 /*!
45  * \brief Generic STUN request.
46  *
47  * \param s The socket used to send the request.
48  * \param dst If non null, the address of the STUN server.
49  * Only needed if the socket is not bound or connected.
50  * \param username If non null, add the username in the request.
51  * \param answer If non null, the function waits for a response and
52  * puts here the externally visible address.
53  *
54  * \details
55  * Send a generic STUN request to the server specified, possibly
56  * waiting for a reply and filling the answer parameter with the
57  * externally visible address. Note that in this case the
58  * request will be blocking.
59  *
60  * \note The interface may change slightly in the future.
61  *
62  * \retval 0 on success.
63  * \retval <0 on error.
64  * \retval >0 on timeout.
65  */
66 int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer);
67 
68 /*! \brief callback type to be invoked on stun responses. */
69 typedef int (stun_cb_f)(struct stun_attr *attr, void *arg);
70 
71 /*!
72  * \brief handle an incoming STUN message.
73  *
74  * \param s Socket to send any response to.
75  * \param src Address where packet came from.
76  * \param data STUN packet buffer to process.
77  * \param len Length of packet
78  * \param stun_cb If not NULL, callback for each STUN attribute.
79  * \param arg Arg to pass to callback.
80  *
81  * \details
82  * Do some basic sanity checks on packet size and content,
83  * try to extract a bit of information, and possibly reply.
84  * At the moment this only processes BIND requests, and returns
85  * the externally visible address of the request.
86  * If a callback is specified, invoke it with the attribute.
87  *
88  * \retval AST_STUN_ACCEPT if responed to a STUN request
89  * \retval AST_STUN_IGNORE
90  * \retval -1 on error
91  */
92 int ast_stun_handle_packet(int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg);
93 
94 #if defined(__cplusplus) || defined(c_plusplus)
95 }
96 #endif
97 
98 #endif /* _ASTERISK_STUN_H */
Definition: stun.c:80
int ast_stun_handle_packet(int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg)
handle an incoming STUN message.
Definition: stun.c:264
int( stun_cb_f)(struct stun_attr *attr, void *arg)
callback type to be invoked on stun responses.
Definition: stun.h:69
static const int STANDARD_STUN_PORT
Definition: stun.h:35
int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer)
Generic STUN request.
Definition: stun.c:373
ast_stun_result
Definition: stun.h:37
Wrapper for network related headers, masking differences between various operating systems...
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
unsigned short attr
Definition: stun.c:81