stun-client.h 1.98 KB
Newer Older
1 2
/*
 * stun-client.h
Ghislain MARY's avatar
Ghislain MARY committed
3
 * Copyright (C) 2010-2017 Belledonne Communications SARL
4
 *
Ghislain MARY's avatar
Ghislain MARY committed
5 6 7 8
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
9 10 11 12 13 14 15
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Ghislain MARY's avatar
Ghislain MARY committed
16 17
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 19 20 21 22
 */

#ifndef _STUN_CLIENT_H_
#define _STUN_CLIENT_H_

23 24
#include <string>

25 26 27 28 29 30
#include <ortp/port.h>

#include "linphone/utils/general.h"

// =============================================================================

31 32 33
L_DECL_C_STRUCT_PREFIX_LESS(SalMediaDescription);
L_DECL_C_STRUCT(LinphoneCore);

34 35 36 37 38 39 40 41 42 43 44 45 46 47
LINPHONE_BEGIN_NAMESPACE

class StunClient {
	struct Candidate {
		std::string address;
		int port;
	};

public:
	StunClient (LinphoneCore *core) : core(core) {}

	int run (int audioPort, int videoPort, int textPort);
	void updateMediaDescription (SalMediaDescription *md) const;

48 49 50 51 52 53 54 55 56 57 58
	const Candidate &getAudioCandidate () const {
		return audioCandidate;
	}

	const Candidate &getVideoCandidate () const {
		return videoCandidate;
	}

	const Candidate &getTextCandidate () const {
		return textCandidate;
	}
59 60

	ortp_socket_t createStunSocket (int localPort);
61 62
	int recvStunResponse (ortp_socket_t sock, Candidate &candidate, int &id);
	int sendStunRequest (ortp_socket_t sock, const struct sockaddr *server, socklen_t addrlen, int id, bool changeAddr);
63 64 65 66 67 68 69 70 71 72 73

private:
	LinphoneCore *core = nullptr;
	Candidate audioCandidate;
	Candidate videoCandidate;
	Candidate textCandidate;
};

LINPHONE_END_NAMESPACE

#endif // ifndef _STUN_CLIENT_H_