summaryrefslogtreecommitdiff
path: root/src/core/hle/service/sockets/socket_utils.h
blob: d95d896caa14c21c086b453064aa6b45b6ef1230 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "common/common_types.h"
#include <array>
#include <cstring>

namespace Service::Sockets {

// Base socket structures and utilities for nn::socket

// in_addr struct similar to standard BSD/POSIX implementation
struct in_addr {
    u32 s_addr;
};

// sockaddr struct similar to standard BSD/POSIX implementation
struct sockaddr {
    u16 sa_family;
    char sa_data[14];
};

// sockaddr_in struct similar to standard BSD/POSIX implementation
struct sockaddr_in {
    u16 sin_family;
    u16 sin_port;
    in_addr sin_addr;
    char sin_zero[8];
};

// Socket configuration data based on LibraryConfigData from switchbrew
struct Config {
    u32 version;
    u32 tcp_tx_buf_size;
    u32 tcp_rx_buf_size;
    u32 tcp_tx_buf_max_size;
    u32 tcp_rx_buf_max_size;
    u32 udp_tx_buf_size;
    u32 udp_rx_buf_size;
    u32 sb_efficiency;
};

namespace nn::socket {

// InetAton converts an IPv4 address string to an in_addr structure
// Returns true on success, false on failure
bool InetAton(const char* ip, in_addr* addr);

// Connect to a remote host
// Returns 0 on success, -1 on failure
s32 Connect(s32 socket, const sockaddr* addr, u32 addr_len);

} // namespace nn::socket

} // namespace Service::Sockets