Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
socket.h
Go to the documentation of this file.
1#ifndef __NET__SOCKET_H__
2#define __NET__SOCKET_H__
3
5#include "net/netdev.h"
6#include <type.h>
7
8/* Socket General */
13
14/* Raw / packet socket: bind ke NIC + EtherType */
15typedef struct sockaddr_ll {
16 uint16_t sll_family; /* AF_RAW atau AF_PACKET */
17 uint16_t sll_protocol; /* EtherType (host byte order) */
18 uint8_t sll_nic_id; /* NIC id (0..MAX_NICS-1), 0xff = semua NIC */
22
23/* IPv4 socket address */
24typedef struct sockaddr_in {
25 uint16_t sin_family; /* AF_INET */
26 uint16_t sin_port; /* port dalam network byte order */
27 uint32_t sin_addr; /* IP dalam network byte order */
30
31typedef struct socket socket_t;
32typedef struct socket_ops {
33 int (*recv)(socket_t* socket, void* buffer, size_t size);
34 // recv with zero copy
35 int (*recv_zc)(socket_t* socket, void** buffer, size_t size);
36
38 int (*set_sockopt)(socket_t* socket, uint32_t level, uint32_t optname,
39 const void* optval, uint32_t optlen);
41
42typedef enum {
43 AF_RAW = 0, /* raw Ethernet frame (L2) */
44 AF_INET = 2, /* IPv4 (TCP/UDP — diimplementasi di atas) */
45 AF_INET6 = 10, /* IPv6 */
46 AF_PACKET = 17, /* Linux-style packet socket */
48
49typedef enum {
50 SOCK_RAW = 0, /* raw, tidak ada transport header */
51 SOCK_DGRAM = 1, /* datagram (UDP-style, connectionless) */
52 SOCK_STREAM = 2, /* stream (TCP-style, connection-oriented) */
54
79
82
83/* sock option*/
84#define SOL_SOCKET 1
85#define IPPROTO_IP 0
86#define IPPROTO_TCP 6
87#define IPPROTO_UDP 17
88
89#define SO_BINDTODEVICE 25 /* bind ke netdvev, default by route table */
90#define SO_RCVBUF 8 /* ukuran RX buffer */
91#define SO_SNDBUF 7 /* ukuran TX buffer */
92#define SO_BROADCAST 6 /* izinkan broadcast */
93#define SO_PROMISC 200 /* aktifkan promiscuous di NIC terikat */
94#define SO_NONBLOCK 201 /* non-blocking mode */
95
96/* error type */
97#define SOCK_OK 0
98#define SOCK_ERR_NOFD -1 /* tidak ada file descriptor kosong */
99#define SOCK_ERR_INVAL -2 /* argumen tidak valid */
100#define SOCK_ERR_NODEV -3 /* NIC tidak ditemukan */
101#define SOCK_ERR_AGAIN -4 /* non-blocking, tidak ada data */
102#define SOCK_ERR_NOMEM -5 /* buffer pool habis */
103#define SOCK_ERR_NOTCONN -6 /* belum connect() */
104
105#endif // __NET__SOCKET_H__
volatile uint64_t addr
Definition e1000.hpp:0
volatile uint32_t buffer[5]
Definition ehci.hpp:8
#define NIC_MAC_LEN
Definition ioforge_nic.h:8
uint8_t protocol
Definition ipv4.h:6
struct netdev netdev_t
Definition netdev.h:19
size_t len
Definition oct2bin.h:7
void vxSocket(sock_family_t family, sock_type_t type, uint16_t protocol, socket_t **socket)
Definition socket.c:35
struct sockaddr sockaddr_t
struct socket socket_t
Definition socket.h:31
struct sockaddr_in sockaddr_in_t
sock_family_t
Definition socket.h:42
@ AF_INET6
Definition socket.h:45
@ AF_INET
Definition socket.h:44
@ AF_PACKET
Definition socket.h:46
@ AF_RAW
Definition socket.h:43
sock_type_t
Definition socket.h:49
@ SOCK_DGRAM
Definition socket.h:51
@ SOCK_RAW
Definition socket.h:50
@ SOCK_STREAM
Definition socket.h:52
struct socket_ops socket_ops_t
struct sockaddr_ll sockaddr_ll_t
uint16_t sin_family
Definition socket.h:25
uint8_t _pad[8]
Definition socket.h:28
uint16_t sin_port
Definition socket.h:26
uint32_t sin_addr
Definition socket.h:27
uint8_t sll_nic_id
Definition socket.h:18
uint16_t sll_family
Definition socket.h:16
uint16_t sll_protocol
Definition socket.h:17
uint8_t sll_mac[6]
Definition socket.h:19
uint8_t _pad
Definition socket.h:20
uint16_t sa_family
Definition socket.h:10
uint8_t sa_data[14]
Definition socket.h:11
int(* recv)(socket_t *socket, void *buffer, size_t size)
Definition socket.h:33
int(* set_sockopt)(socket_t *socket, uint32_t level, uint32_t optname, const void *optval, uint32_t optlen)
Definition socket.h:38
int(* bind)(socket_t *socket, sockaddr_in_t *addr, uint32_t len)
Definition socket.h:37
int(* recv_zc)(socket_t *socket, void **buffer, size_t size)
Definition socket.h:35
uint64_t tx_packets
Definition socket.h:71
socket_ops_t * ops
Definition socket.h:77
uint8_t nonblocking
Definition socket.h:63
sock_family_t family
Definition socket.h:56
uint16_t protocol
Definition socket.h:58
sock_type_t type
Definition socket.h:57
netdev_t * netdev
Definition socket.h:61
uint8_t broadcast
Definition socket.h:64
sockaddr_in_t local_addr
Definition socket.h:66
uint64_t rx_packets
Definition socket.h:70
uint8_t _in_use
Definition socket.h:74
uint64_t rx_dropped
Definition socket.h:72
sockaddr_in_t remote_addr
Definition socket.h:67
unsigned short uint16_t
Definition type.h:13
unsigned int uint32_t
Definition type.h:19
unsigned long uint64_t
Definition type.h:25
unsigned char uint8_t
Definition type.h:7
uint8_t type
Definition vnode.h:2
size_t size
Definition vnode.h:3