Thu Sep 7 01:03:05 2017

Asterisk developer's documentation


stun.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2008, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*!
00020  * \file stun.h
00021  * \brief STUN support.
00022  *
00023  * STUN is defined in RFC 3489.
00024  */
00025 
00026 #ifndef _ASTERISK_STUN_H
00027 #define _ASTERISK_STUN_H
00028 
00029 #include "asterisk/network.h"
00030 
00031 #if defined(__cplusplus) || defined(c_plusplus)
00032 extern "C" {
00033 #endif
00034 
00035 static const int STANDARD_STUN_PORT = 3478;
00036 
00037 enum ast_stun_result {
00038    AST_STUN_IGNORE = 0,
00039    AST_STUN_ACCEPT,
00040 };
00041 
00042 struct stun_attr;
00043 
00044 /*!
00045  * \brief Generic STUN request.
00046  *
00047  * \param s The socket used to send the request.
00048  * \param dst If non null, the address of the STUN server.
00049  *    Only needed if the socket is not bound or connected.
00050  * \param username If non null, add the username in the request.
00051  * \param answer If non null, the function waits for a response and
00052  *    puts here the externally visible address.
00053  *
00054  * \details
00055  * Send a generic STUN request to the server specified, possibly
00056  * waiting for a reply and filling the answer parameter with the
00057  * externally visible address.  Note that in this case the
00058  * request will be blocking.
00059  *
00060  * \note The interface may change slightly in the future.
00061  *
00062  * \retval 0 on success.
00063  * \retval <0 on error.
00064  * \retval >0 on timeout.
00065  */
00066 int ast_stun_request(int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer);
00067 
00068 /*! \brief callback type to be invoked on stun responses. */
00069 typedef int (stun_cb_f)(struct stun_attr *attr, void *arg);
00070 
00071 /*!
00072  * \brief handle an incoming STUN message.
00073  *
00074  * \param s Socket to send any response to.
00075  * \param src Address where packet came from.
00076  * \param data STUN packet buffer to process.
00077  * \param len Length of packet
00078  * \param stun_cb If not NULL, callback for each STUN attribute.
00079  * \param arg Arg to pass to callback.
00080  *
00081  * \details
00082  * Do some basic sanity checks on packet size and content,
00083  * try to extract a bit of information, and possibly reply.
00084  * At the moment this only processes BIND requests, and returns
00085  * the externally visible address of the request.
00086  * If a callback is specified, invoke it with the attribute.
00087  *
00088  * \retval AST_STUN_ACCEPT if responed to a STUN request
00089  * \retval AST_STUN_IGNORE
00090  * \retval -1 on error
00091  */
00092 int ast_stun_handle_packet(int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg);
00093 
00094 #if defined(__cplusplus) || defined(c_plusplus)
00095 }
00096 #endif
00097 
00098 #endif /* _ASTERISK_STUN_H */

Generated on 7 Sep 2017 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1