| // Copyright 2018 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| library fuchsia.net; |
| |
| // Legacy interface to create a socket |
| enum SocketDomain { |
| inet = 2; |
| inet6 = 10; |
| }; |
| |
| enum SocketType { |
| stream = 1; |
| dgram = 2; |
| }; |
| |
| enum SocketProtocol { |
| ip = 0; |
| icmp = 1; |
| tcp = 6; |
| udp = 17; |
| ipv6 = 41; |
| icmpv6 = 58; |
| }; |
| |
| enum AddrInfoStatus { |
| ok = 0; |
| // invalid flags |
| bad_flags = 1; |
| // missing node name or service name |
| no_name = 2; |
| // temporary failure |
| again = 3; |
| // non-recoverable failure |
| fail = 4; |
| // no address found for node name |
| no_data = 5; |
| // argument buffer overflow |
| buffer_overflow = 6; |
| // system error |
| system_error = 7; |
| }; |
| |
| struct AddrInfoHints { |
| int32 flags; |
| int32 family; |
| int32 sock_type; |
| int32 protocol; |
| }; |
| |
| struct AddrStorage { |
| array<uint8>:16 val; |
| uint32 len; |
| }; |
| |
| struct AddrInfo { |
| int32 flags; |
| int32 family; |
| int32 sock_type; |
| int32 protocol; |
| AddrStorage addr; // TODO(FIDL-323): replace with vector<uint8>:16. |
| uint16 port; |
| }; |
| |
| // TODO(NET-1865): remove this, SocketDomain, SocketType, and SocketProtocol |
| // after Chromium rolls. |
| [Discoverable, Layout = "Simple"] |
| interface LegacySocketProvider { |
| 1: OpenSocket(SocketDomain domain, SocketType type, SocketProtocol protocol) |
| -> (handle<socket>? s, int32 status); |
| // TODO(FIDL-323): use vector<AddInfo>:4. |
| 2: GetAddrInfo(string:256? node, string:256? service, AddrInfoHints? hints) |
| -> (AddrInfoStatus status, uint32 nres, array<AddrInfo>:4 res); |
| }; |
| |
| // Chosen to match `sizeof(struct sockaddr_storage)`. |
| const uint64 MAX_ADDR = 128; |
| // Chosen to be large enough to hold whatever we might want to cram in it. |
| // So long as we support Ioctl, we don't have a good sense of what we might |
| // want to send as payload. |
| const uint64 MAX_BUFFER = 900; |
| |
| /// POSIX, as much as possible. |code| values are defined in errno.h. |
| [Discoverable, Layout = "Simple"] |
| interface SocketProvider { |
| Socket(int16 domain, int16 type, int16 protocol) -> (int16 code, handle<socket>? s); |
| // TODO(FIDL-323): use vector<AddInfo>:4. |
| GetAddrInfo(string:256? node, string:256? service, AddrInfoHints? hints) |
| -> (AddrInfoStatus status, uint32 nres, array<AddrInfo>:4 res); |
| }; |
| |
| // This interface is essentially POSIX. Its implementation must support |
| // Linux-specific arguments to {Get,Set}SockOpt. |
| [Transport = "SocketControl", Layout = "Simple"] |
| interface SocketControl { |
| Close() -> (int16 code); |
| Ioctl(int16 req, vector<uint8>:MAX_BUFFER in) -> (int16 code, vector<uint8>:MAX_BUFFER out); |
| Connect(vector<uint8>:MAX_ADDR addr) -> (int16 code); |
| Accept(int16 flags) -> (int16 code); |
| Bind(vector<uint8>:MAX_ADDR addr) -> (int16 code); |
| Listen(int16 backlog) -> (int16 code); |
| GetSockName() -> (int16 code, vector<uint8>:MAX_ADDR addr); |
| GetPeerName() -> (int16 code, vector<uint8>:MAX_ADDR addr); |
| SetSockOpt(int16 level, int16 optname, vector<uint8>:MAX_BUFFER optval) -> (int16 code); |
| GetSockOpt(int16 level, int16 optname) -> (int16 code, vector<uint8>:MAX_BUFFER optval); |
| }; |