blob: 63c2f1da59d01e7fe3811f0a2f5d8998e4073264 [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"
9
10namespace openscreen {
11namespace platform {
12
13// Opaque type for the platform to implement.
14struct UdpSocketIPv4Private;
15using UdpSocketIPv4Ptr = UdpSocketIPv4Private*;
16struct UdpSocketIPv6Private;
17using UdpSocketIPv6Ptr = UdpSocketIPv6Private*;
18
19UdpSocketIPv4Ptr CreateUdpSocketIPv4();
20UdpSocketIPv6Ptr CreateUdpSocketIPv6();
21
22// Closes the underlying platform socket and frees any allocated memory.
23void DestroyUdpSocket(UdpSocketIPv4Ptr socket);
24void DestroyUdpSocket(UdpSocketIPv6Ptr socket);
25
26bool BindUdpSocketIPv4(UdpSocketIPv4Ptr socket,
27 const IPv4Endpoint& endpoint,
28 int32_t ifindex);
29bool BindUdpSocketIPv6(UdpSocketIPv6Ptr socket,
30 const IPv6Endpoint& endpoint,
31 int32_t ifindex);
32bool JoinUdpMulticastGroupIPv4(UdpSocketIPv4Ptr socket,
33 const IPv4Address& address,
34 int32_t ifindex);
35bool JoinUdpMulticastGroupIPv6(UdpSocketIPv6Ptr socket,
36 const IPv6Address& address,
37 int32_t ifindex);
38
39int64_t ReceiveUdpIPv4(UdpSocketIPv4Ptr socket,
40 void* data,
41 int64_t length,
42 IPv4Endpoint* src,
43 IPv4Endpoint* original_destination);
44int64_t ReceiveUdpIPv6(UdpSocketIPv6Ptr socket,
45 void* data,
46 int64_t length,
47 IPv6Endpoint* src,
48 IPv6Endpoint* original_destination);
49int64_t SendUdpIPv4(UdpSocketIPv4Ptr socket,
50 const void* data,
51 int64_t length,
52 const IPv4Endpoint& dest);
53int64_t SendUdpIPv6(UdpSocketIPv6Ptr socket,
54 const void* data,
55 int64_t length,
56 const IPv6Endpoint& dest);
57
58} // namespace platform
59} // namespace openscreen
60
61#endif