blob: a97d1d66128362c4598e56199e52ec724f368021 [file] [log] [blame]
btolsch9ccfa782018-07-26 00:16:08 -07001// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PLATFORM_API_SOCKET_H_
6#define PLATFORM_API_SOCKET_H_
7
8#include "base/ip_address.h"
Yuri Wiitala82edd202018-10-31 18:42:58 -07009#include "platform/api/network_interface.h"
btolsch9ccfa782018-07-26 00:16:08 -070010
11namespace openscreen {
12namespace platform {
13
14// Opaque type for the platform to implement.
btolsch56aa52a2018-09-10 11:40:12 -070015struct UdpSocketPrivate;
16using UdpSocketPtr = UdpSocketPrivate*;
btolsch9ccfa782018-07-26 00:16:08 -070017
Yuri Wiitala82edd202018-10-31 18:42:58 -070018// TODO(miu): These should return std::unique_ptr<>, so that code structure
19// auto-scopes the lifetime of the instance (i.e., auto-closing the socket too).
btolsch56aa52a2018-09-10 11:40:12 -070020UdpSocketPtr CreateUdpSocketIPv4();
21UdpSocketPtr CreateUdpSocketIPv6();
btolsch9ccfa782018-07-26 00:16:08 -070022
Yuri Wiitalab94f12e2018-10-31 18:28:53 -070023// Returns true if |socket| is not null and it belongs to the IPv4/IPv6 address
24// family.
25bool IsIPv4Socket(UdpSocketPtr socket);
26bool IsIPv6Socket(UdpSocketPtr socket);
27
btolsch9ccfa782018-07-26 00:16:08 -070028// Closes the underlying platform socket and frees any allocated memory.
btolsch56aa52a2018-09-10 11:40:12 -070029void DestroyUdpSocket(UdpSocketPtr socket);
btolsch9ccfa782018-07-26 00:16:08 -070030
btolsch56aa52a2018-09-10 11:40:12 -070031bool BindUdpSocket(UdpSocketPtr socket,
32 const IPEndpoint& endpoint,
Yuri Wiitala82edd202018-10-31 18:42:58 -070033 InterfaceIndex ifindex);
btolsch56aa52a2018-09-10 11:40:12 -070034bool JoinUdpMulticastGroup(UdpSocketPtr socket,
35 const IPAddress& address,
Yuri Wiitala82edd202018-10-31 18:42:58 -070036 InterfaceIndex ifindex);
btolsch9ccfa782018-07-26 00:16:08 -070037
btolsch56aa52a2018-09-10 11:40:12 -070038int64_t ReceiveUdp(UdpSocketPtr socket,
39 void* data,
40 int64_t length,
41 IPEndpoint* src,
42 IPEndpoint* original_destination);
43int64_t SendUdp(UdpSocketPtr socket,
44 const void* data,
45 int64_t length,
46 const IPEndpoint& dest);
btolsch9ccfa782018-07-26 00:16:08 -070047
48} // namespace platform
49} // namespace openscreen
50
btolscha21e8ed2018-08-30 15:13:48 -070051#endif // PLATFORM_API_SOCKET_H_