Lumenarium/src_v2/platform/linux/lumenarium_linux_network.h

95 lines
1.9 KiB
C
Raw Normal View History

2022-05-13 11:45:40 +00:00
#ifndef LUMENARIUM_LINUX_NETWORK_H
#define LUMENARIUM_LINUX_NETWORK_H 1
Socket_Handle
os_socket_create(s32 domain, s32 type, s32 protocol)
{
2022-07-18 11:31:48 +00:00
Socket_Handle result = {};
OS_SOCKET_TYPE sock = socket(domain, type, protocol);
if (sock == -1) {
perror("Error: os_socket_create\n");
return result;
}
result = open_sockets_put(sock);
if (result.value == 0)
{
fprintf(stderr, "Error: os_socket_create = not enough room in open_sockets\n");
}
return result;
2022-05-13 11:45:40 +00:00
}
bool
os_socket_bind()
{
invalid_code_path;
return false;
}
bool
os_socket_connect()
{
invalid_code_path;
return false;
}
bool
os_socket_close()
{
invalid_code_path;
return false;
}
Data
os_socket_recv()
{
invalid_code_path;
return (Data){};
2022-05-13 11:45:40 +00:00
}
s32
os_socket_set_listening()
{
invalid_code_path;
return 0;
}
s32
os_socket_send()
{
invalid_code_path;
return 0;
}
s32
os_socket_send_to(Socket_Handle handle, u32 addr, u32 port, Data data, s32 flags)
{
2022-07-18 11:31:48 +00:00
OS_SOCKET_TYPE sock = open_sockets_get(handle);
struct sockaddr_in dst = {
.sin_family = AF_INET,
.sin_port = hton_u16(port),
.sin_addr.s_addr = hton_u32(addr),
};
struct sockaddr* dst_ptr = (struct sockaddr*)&dst;
s32 len_sent = sendto(sock, data.base, data.size, flags, dst_ptr, sizeof(struct sockaddr_in));
if (len_sent == -1)
{
perror("Error: os_socket_send_to\n");
return 0;
}
return len_sent;
2022-05-13 11:45:40 +00:00
}
s32
os_socket_set_opt(Socket_Handle handle, int level, int option_name, u8* option_value, s32 option_len)
{
2022-07-18 11:31:48 +00:00
OS_SOCKET_TYPE sock = open_sockets_get(handle);
s32 err = setsockopt(sock, level, option_name, (void*)option_value, (socklen_t)option_len);
if (err) {
fprintf(stderr, "Error: setsockopt - %d\n\targs: %d %d %.*s\n", err, level, option_name, option_len, (char*)option_value);
}
2022-05-13 11:45:40 +00:00
return 0;
}
#endif // LUMENARIUM_LINUX_NETWORK_H