blob: 741ddecb0eeb2a1ba7c6aa4966d4b5245f42eccb [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020012#include "p2p/base/stunserver.h"
Yves Gerey3e707812018-11-28 16:47:49 +010013#include "rtc_base/asyncudpsocket.h"
14#include "rtc_base/socketaddress.h"
15#include "rtc_base/socketserver.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}