blob: 8180069bf036acc54da4095618c411793a385f45 [file] [log] [blame]
Donald E Curtisa8736442015-08-05 15:48:13 -07001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Donald E Curtisa8736442015-08-05 15:48:13 -070010#include <iostream>
11
Steve Anton10542f22019-01-11 09:11:00 -080012#include "p2p/base/stun_server.h"
13#include "rtc_base/async_udp_socket.h"
14#include "rtc_base/socket_address.h"
15#include "rtc_base/socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "rtc_base/thread.h"
Donald E Curtisa8736442015-08-05 15:48:13 -070017
jbauch70625e52015-12-09 14:18:14 -080018using cricket::StunServer;
Donald E Curtisa8736442015-08-05 15:48:13 -070019
20int main(int argc, char* argv[]) {
21 if (argc != 2) {
22 std::cerr << "usage: stunserver address" << std::endl;
23 return 1;
24 }
25
26 rtc::SocketAddress server_addr;
27 if (!server_addr.FromString(argv[1])) {
28 std::cerr << "Unable to parse IP address: " << argv[1];
29 return 1;
30 }
31
Yves Gerey665174f2018-06-19 15:03:05 +020032 rtc::Thread* pthMain = rtc::Thread::Current();
Donald E Curtisa8736442015-08-05 15:48:13 -070033
34 rtc::AsyncUDPSocket* server_socket =
35 rtc::AsyncUDPSocket::Create(pthMain->socketserver(), server_addr);
36 if (!server_socket) {
37 std::cerr << "Failed to create a UDP socket" << std::endl;
38 return 1;
39 }
40
41 StunServer* server = new StunServer(server_socket);
42
43 std::cout << "Listening at " << server_addr.ToString() << std::endl;
44
45 pthMain->Run();
46
47 delete server;
48 return 0;
49}