The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
in.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdint.h>
4#include <sys/socket.h>
5
6/**
7 * @file netinet/in.h
8 * @brief IPv4 addresses and ports, and the IP protocols.
9 *
10 * the IPv6 types are here for programs that know both families. there is
11 * no IPv6 network: socket(AF_INET6, ...) gives EAFNOSUPPORT, and programs
12 * then use IPv4.
13 *
14 * addresses and ports in the structs are in network byte order (big
15 * endian); htons, htonl, ntohs and ntohl change between it and the CPU's.
16 */
17
20
21struct in_addr
22{
24};
25
27{
31 unsigned char sin_zero[8];
32};
33
35{
37};
38
47
48extern const struct in6_addr in6addr_any; // ::
49extern const struct in6_addr in6addr_loopback; // ::1
50
51#define IN6ADDR_ANY_INIT {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}
52#define IN6ADDR_LOOPBACK_INIT {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}}
53
54#define IPPROTO_IP 0
55#define IPPROTO_ICMP 1
56#define IPPROTO_TCP 6
57#define IPPROTO_UDP 17
58#define IPPROTO_IPV6 41
59
60#define IPV6_V6ONLY 26
61
62#define INADDR_ANY ((in_addr_t)0x00000000)
63#define INADDR_BROADCAST ((in_addr_t)0xFFFFFFFF)
64#define INADDR_NONE ((in_addr_t)0xFFFFFFFF)
65#define INADDR_LOOPBACK ((in_addr_t)0x7F000001) // 127.0.0.1, in host byte order
66
67#define INET_ADDRSTRLEN 16
68#define INET6_ADDRSTRLEN 46
69
70static inline uint16_t htons(uint16_t v)
71{
72 return __builtin_bswap16(v);
73}
74
75static inline uint16_t ntohs(uint16_t v)
76{
77 return __builtin_bswap16(v);
78}
79
80static inline uint32_t htonl(uint32_t v)
81{
82 return __builtin_bswap32(v);
83}
84
85static inline uint32_t ntohl(uint32_t v)
86{
87 return __builtin_bswap32(v);
88}
const struct in6_addr in6addr_loopback
uint16_t in_port_t
Definition in.h:19
uint32_t in_addr_t
Definition in.h:18
const struct in6_addr in6addr_any
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
integer types of fixed width.
unsigned short uint16_t
Definition stdint.h:13
sockets: Unix domain stream sockets, with file descriptor passing, and IPv4 sockets (TCP; UDP,...
unsigned short sa_family_t
Definition socket.h:22
Definition in.h:35
uint8_t s6_addr[16]
Definition in.h:36
Definition in.h:22
in_addr_t s_addr
Definition in.h:23
Definition in.h:40
in_port_t sin6_port
Definition in.h:42
struct in6_addr sin6_addr
Definition in.h:44
uint32_t sin6_flowinfo
Definition in.h:43
uint32_t sin6_scope_id
Definition in.h:45
sa_family_t sin6_family
Definition in.h:41
Definition in.h:27
unsigned char sin_zero[8]
Definition in.h:31
struct in_addr sin_addr
Definition in.h:30
sa_family_t sin_family
Definition in.h:28
in_port_t sin_port
Definition in.h:29