diff --git a/Kernel/API/POSIX/netinet/in.h b/Kernel/API/POSIX/netinet/in.h new file mode 100644 index 0000000000..5b9bb8ac9e --- /dev/null +++ b/Kernel/API/POSIX/netinet/in.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2018-2021, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t in_addr_t; + +#define INADDR_ANY ((in_addr_t)0) +#define INADDR_NONE ((in_addr_t)-1) +#define INADDR_LOOPBACK 0x7f000001 + +#define IN_LOOPBACKNET 127 + +#define IP_TTL 2 +#define IP_MULTICAST_LOOP 3 +#define IP_ADD_MEMBERSHIP 4 +#define IP_DROP_MEMBERSHIP 5 +#define IP_MULTICAST_IF 6 +#define IP_MULTICAST_TTL 7 + +/* Make sure these don't overlap with any other IPv4 and IPv6 options */ +#define MCAST_JOIN_SOURCE_GROUP 100 +#define MCAST_LEAVE_SOURCE_GROUP 101 + +#define IPPORT_RESERVED 1024 +#define IPPORT_USERRESERVED 5000 + +typedef uint16_t in_port_t; + +struct in_addr { + uint32_t s_addr; +}; + +struct sockaddr_in { + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + char sin_zero[8]; +}; + +struct ip_mreq { + struct in_addr imr_multiaddr; + struct in_addr imr_interface; +}; + +struct group_source_req { + uint32_t gsr_interface; + struct sockaddr_storage gsr_group; + struct sockaddr_storage gsr_source; +}; + +struct ip_mreq_source { + struct in_addr imr_multiaddr; + struct in_addr imr_sourceaddr; + struct in_addr imr_interface; +}; + +#define IPV6_UNICAST_HOPS 1 +#define IPV6_MULTICAST_HOPS 2 +#define IPV6_MULTICAST_LOOP 3 +#define IPV6_MULTICAST_IF 4 +#define IPV6_ADD_MEMBERSHIP 5 +#define IPV6_DROP_MEMBERSHIP 6 +#define IP_ADD_SOURCE_MEMBERSHIP 7 +#define IP_DROP_SOURCE_MEMBERSHIP 8 +#define IPV6_V6ONLY 9 + +struct in6_addr { + uint8_t s6_addr[16]; +}; + +#define IN6ADDR_ANY_INIT \ + { \ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ + } + +extern struct in6_addr in6addr_any; + +struct sockaddr_in6 { + sa_family_t sin6_family; // AF_INET6. + in_port_t sin6_port; // Port number. + uint32_t sin6_flowinfo; // IPv6 traffic class and flow information. + struct in6_addr sin6_addr; // IPv6 address. + uint32_t sin6_scope_id; // Set of interfaces for a scop +}; + +struct ipv6_mreq { + struct in6_addr ipv6mr_multiaddr; + uint32_t ipv6mr_interface; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Kernel/UnixTypes.h b/Kernel/UnixTypes.h index ef99db7bf4..f3f211ab45 100644 --- a/Kernel/UnixTypes.h +++ b/Kernel/UnixTypes.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -134,37 +135,6 @@ enum { #define FUTEX_BITSET_MATCH_ANY 0xffffffff -#define S_IFMT 0170000 -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 - -typedef u32 dev_t; -typedef u64 ino_t; -typedef u16 mode_t; -typedef u32 nlink_t; -typedef u32 uid_t; -typedef u32 gid_t; -typedef u32 clock_t; -typedef u32 socklen_t; -typedef int pid_t; // Avoid interference with AK/Types.h and LibC/sys/types.h by defining *separate* names: TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ProcessID); TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ThreadID); @@ -243,39 +213,6 @@ struct pollfd { short revents; }; -#define IPPROTO_IP 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 - -#define IP_TTL 2 -#define IP_MULTICAST_LOOP 3 -#define IP_ADD_MEMBERSHIP 4 -#define IP_DROP_MEMBERSHIP 5 - -#define S_IFSOCK 0140000 - -struct in_addr { - uint32_t s_addr; -}; -typedef uint32_t in_addr_t; - -struct sockaddr_in { - int16_t sin_family; - uint16_t sin_port; - struct in_addr sin_addr; - char sin_zero[8]; -}; - -struct ip_mreq { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -#define INADDR_ANY ((in_addr_t)0) -#define INADDR_NONE ((in_addr_t)-1) -#define INADDR_LOOPBACK 0x7f000001 - typedef u32 __u32; typedef u16 __u16; typedef u8 __u8; diff --git a/Userland/Libraries/LibC/netinet/in.h b/Userland/Libraries/LibC/netinet/in.h index da5e5e08a3..6d389892dd 100644 --- a/Userland/Libraries/LibC/netinet/in.h +++ b/Userland/Libraries/LibC/netinet/in.h @@ -6,97 +6,10 @@ #pragma once -#include -#include -#include +#include __BEGIN_DECLS -typedef uint32_t in_addr_t; -in_addr_t inet_addr(const char*); - -#define INADDR_ANY ((in_addr_t)0) -#define INADDR_NONE ((in_addr_t)-1) -#define INADDR_LOOPBACK 0x7f000001 - -#define IN_LOOPBACKNET 127 - -#define IP_TTL 2 -#define IP_MULTICAST_LOOP 3 -#define IP_ADD_MEMBERSHIP 4 -#define IP_DROP_MEMBERSHIP 5 -#define IP_MULTICAST_IF 6 -#define IP_MULTICAST_TTL 7 - -/* Make sure these don't overlap with any other IPv4 and IPv6 options */ -#define MCAST_JOIN_SOURCE_GROUP 100 -#define MCAST_LEAVE_SOURCE_GROUP 101 - -#define IPPORT_RESERVED 1024 -#define IPPORT_USERRESERVED 5000 - -typedef uint16_t in_port_t; - -struct in_addr { - uint32_t s_addr; -}; - -struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - char sin_zero[8]; -}; - -struct ip_mreq { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct group_source_req { - uint32_t gsr_interface; - struct sockaddr_storage gsr_group; - struct sockaddr_storage gsr_source; -}; - -struct ip_mreq_source { - struct in_addr imr_multiaddr; - struct in_addr imr_sourceaddr; - struct in_addr imr_interface; -}; - -#define IPV6_UNICAST_HOPS 1 -#define IPV6_MULTICAST_HOPS 2 -#define IPV6_MULTICAST_LOOP 3 -#define IPV6_MULTICAST_IF 4 -#define IPV6_ADD_MEMBERSHIP 5 -#define IPV6_DROP_MEMBERSHIP 6 -#define IP_ADD_SOURCE_MEMBERSHIP 7 -#define IP_DROP_SOURCE_MEMBERSHIP 8 -#define IPV6_V6ONLY 9 - -struct in6_addr { - uint8_t s6_addr[16]; -}; - -#define IN6ADDR_ANY_INIT \ - { \ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ - } - -extern struct in6_addr in6addr_any; - -struct sockaddr_in6 { - sa_family_t sin6_family; // AF_INET6. - in_port_t sin6_port; // Port number. - uint32_t sin6_flowinfo; // IPv6 traffic class and flow information. - struct in6_addr sin6_addr; // IPv6 address. - uint32_t sin6_scope_id; // Set of interfaces for a scop -}; - -struct ipv6_mreq { - struct in6_addr ipv6mr_multiaddr; - uint32_t ipv6mr_interface; -}; +in_addr_t inet_addr(char const*); __END_DECLS