Files
opencoreC/include/abi/net.h
T
RarDog 5a4206acb6 feat(microkernel): implement pure microkernel architecture with vfs_server, net_server, and procmgr
- Added vfs_server in Ring 3 (Endpoint 5) managing unified VFS tree (/, /bin, /etc, /proc, /dev, /tmp)
- Added net_server in Ring 3 (Endpoint 6) owning RTL8139 hardware NIC, DHCP, DNS, and TCP/IPv4 stack
- Refactored procmgr in Ring 3 (Endpoint 4) to handle userspace process spawning via PROC_OP_SPAWN
- Added primitive microkernel syscalls in Ring 0: SYS_TASK_CREATE (29), SYS_TASK_MAP_PAGE (30), SYS_TASK_START (31)
- Updated shell (sh) and desktop GUI (gui_server) to delegate process management and I/O to Ring 3 daemons
- Expanded boot pipeline to orchestrate 7 concurrent Ring 3 servers across dedicated SMP CPU cores
2026-09-03 11:03:35 +03:00

130 lines
2.8 KiB
C

#pragma once
#include "stdint.h"
#include "stddef.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ETHERTYPE_IPv4 0x0800
#define ETHERTYPE_ARP 0x0806
#define IP_PROTO_ICMP 1
#define IP_PROTO_TCP 6
#define IP_PROTO_UDP 17
#define ICMP_ECHO_REPLY 0
#define ICMP_ECHO_REQUEST 8
/* NET_ENDPOINT (6) IPC Opcodes */
#define NET_OP_GET_CONFIG 1
#define NET_OP_PING 2
#define NET_OP_DNS 3
#define NET_OP_DHCP 4
#pragma pack(push, 1)
typedef struct {
uint8_t dest_mac[6];
uint8_t src_mac[6];
uint16_t ethertype;
} eth_hdr_t;
typedef struct {
uint16_t hw_type;
uint16_t proto_type;
uint8_t hw_len;
uint8_t proto_len;
uint16_t opcode;
uint8_t sender_mac[6];
uint32_t sender_ip;
uint8_t target_mac[6];
uint32_t target_ip;
} arp_hdr_t;
typedef struct {
uint8_t version_ihl;
uint8_t tos;
uint16_t total_length;
uint16_t id;
uint16_t flags_fragment;
uint8_t ttl;
uint8_t protocol;
uint16_t checksum;
uint32_t src_ip;
uint32_t dst_ip;
} ipv4_hdr_t;
typedef struct {
uint8_t type;
uint8_t code;
uint16_t checksum;
uint16_t id;
uint16_t sequence;
} icmp_hdr_t;
typedef struct {
uint16_t src_port;
uint16_t dst_port;
uint32_t seq_num;
uint32_t ack_num;
uint8_t data_offset_reserved;
uint8_t flags;
uint16_t window_size;
uint16_t checksum;
uint16_t urgent_ptr;
} tcp_hdr_t;
typedef struct {
uint16_t src_port;
uint16_t dst_port;
uint16_t length;
uint16_t checksum;
} udp_hdr_t;
typedef struct {
uint16_t id;
uint16_t flags;
uint16_t qdcount;
uint16_t ancount;
uint16_t nscount;
uint16_t arcount;
} dns_hdr_t;
#define TCP_FLAG_FIN 0x01
#define TCP_FLAG_SYN 0x02
#define TCP_FLAG_RST 0x04
#define TCP_FLAG_PSH 0x08
#define TCP_FLAG_ACK 0x10
#define TCP_FLAG_URG 0x20
#pragma pack(pop)
typedef struct {
uint32_t ip;
uint32_t netmask;
uint32_t gateway;
uint32_t dns_server;
uint8_t mac[6];
} net_config_t;
extern net_config_t g_net_cfg;
// Net API
void net_init(void);
uint16_t net_checksum(const void *buf, size_t len);
uint16_t net_tcp_checksum(uint32_t src_ip, uint32_t dst_ip, const tcp_hdr_t *tcp, size_t tcp_len);
int net_send_arp_request(uint32_t target_ip);
int net_send_icmp_ping(uint32_t target_ip, uint16_t seq);
int net_poll_icmp_reply(uint32_t *from_ip, uint16_t *seq);
int net_dns_resolve(const char *domain, uint32_t *out_ip);
int net_dhcp_discover(void);
int net_http_get(uint32_t target_ip, uint16_t port, const char *path, const char *host_header, char *out_body, size_t max_body_len);
int net_http_get_url(const char *url, char *out_body, size_t max_body_len);
uint32_t parse_ip(const char *str);
void format_ip(uint32_t ip, char *buf);
#ifdef __cplusplus
}
#endif