bsd.h
1 /* ========================================================================== */
2 /* Operating system API */
3 /*
4  * Never include this file directly. Include 'posix.h' instead.
5  */
6 
7 #ifndef BSD_FOR_POSIX
8 # error Do not include 'bsd.h' directly, include 'posix.h' instead!
9 #endif /* BSD_FOR_POSIX */
10 
11 #include <unistd.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 
15 
16 /* ========================================================================== */
17 /* General stuff */
18 
19 #include <sys/socket.h>
20 
21 #define API_POSIX_MSG_PEEK MSG_PEEK
22 
23 #define api_posix_ssize_t ssize_t
24 
25 
26 /* ========================================================================== */
27 /* ARPA internet stuff */
28 
29 #include <netinet/in.h>
30 #include <arpa/inet.h>
31 
32 #define API_POSIX_AF_UNSPEC 0U
33 #define API_POSIX_AF_INET 1U
34 
35 typedef unsigned int api_posix_sa_family_t;
36 
37 #if CFG_HDR_INTTYPES_H
38 # include <inttypes.h>
39 typedef uint16_t api_posix_in_port_t;
40 typedef uint32_t api_posix_in_addr_t;
41 #else
42 typedef CFG_UINT16_TYPE api_posix_in_port_t;
43 typedef CFG_UINT32_TYPE api_posix_in_addr_t;
44 #endif /* CFG_HDR_INTTYPES_H */
45 
46 /* IPv4 network address */
47 struct api_posix_in_addr
48 {
49  api_posix_in_addr_t s_addr;
50 };
51 
52 #define api_posix_struct_in_addr struct api_posix_in_addr
53 
54 /* IPv4 socket address */
55 struct api_posix_sockaddr_in
56 {
57  api_posix_sa_family_t sin_family;
58  api_posix_in_port_t sin_port;
59  api_posix_struct_in_addr sin_addr;
60 };
61 
62 #define api_posix_struct_sockaddr_in struct api_posix_sockaddr_in
63 
64 #if CFG_HDR_INTTYPES_H
65 # include <inttypes.h>
66 uint16_t api_posix_htons(uint16_t);
67 uint32_t api_posix_htonl(uint32_t);
68 uint16_t api_posix_ntohs(uint16_t);
69 uint32_t api_posix_ntohl(uint32_t);
70 #else
71 unsigned short int api_posix_htons(unsigned short int);
72 unsigned long int api_posix_htonl(unsigned long int);
73 unsigned short int api_posix_ntohs(unsigned short int);
74 unsigned long int api_posix_ntohl(unsigned long int);
75 #endif /* CFG_HDR_INTTYPES_H */
76 
77 api_posix_in_addr_t api_posix_inet_addr(const char*);
78 int api_posix_inet_pton(int, const char*, void*);
79 
80 
81 /* ========================================================================== */
82 /* Socket API */
83 
84 #include <string.h>
85 
86 #define API_POSIX_SOCK_STREAM 0
87 
88 /* Yes, this type is signed in the original BSD API */
89 typedef int api_posix_socklen_t;
90 
91 /* Maximum size socket address structure to allocate memory */
92 struct api_posix_sockaddr_storage
93 {
94  api_posix_sa_family_t ss_family;
95  char ss_data[sizeof(api_posix_struct_sockaddr_in)
96  - sizeof(api_posix_sa_family_t)];
97 };
98 
99 #define api_posix_struct_sockaddr_storage struct api_posix_sockaddr_storage
100 
101 struct api_posix_sockaddr
102 {
103  api_posix_sa_family_t sa_family;
104  char sa_data[sizeof(api_posix_struct_sockaddr_in)
105  - sizeof(api_posix_sa_family_t)];
106 };
107 
108 #define api_posix_struct_sockaddr struct api_posix_sockaddr
109 
110 struct api_posix_servent
111 {
112  char* s_name;
113  char** s_aliases;
114  int s_port;
115  char* s_proto;
116 };
117 
118 #define api_posix_struct_servent struct api_posix_servent
119 
120 struct api_posix_hostent
121 {
122  char* h_name;
123  char** h_aliases;
124  int h_addrtype;
125  int h_length;
126  char** h_addr_list;
127 };
128 
129 #define api_posix_struct_hostent struct api_posix_hostent
130 
131 api_posix_struct_servent* api_posix_getservbyname(const char*, const char*);
132 api_posix_struct_hostent* api_posix_gethostbyname(const char*);
133 
134 int api_posix_socket(int, int, int);
135 int api_posix_connect(int, const api_posix_struct_sockaddr*, api_posix_socklen_t);
136 
137 #define API_POSIX_SOL_SOCKET 0
138 
139 #define API_POSIX_SO_ERROR 0
140 #define API_POSIX_SO_RCVTIMEO 1
141 #define API_POSIX_SO_SNDTIMEO 2
142 
143 int api_posix_getsockopt(int, int, int, void*, api_posix_socklen_t*);
144 int api_posix_setsockopt(int, int, int, const void*, api_posix_socklen_t);
145 
146 #define API_POSIX_POLLIN (short int) 0x0001
147 #define API_POSIX_POLLOUT (short int) 0x0002
148 #define API_POSIX_POLLERR (short int) 0x0004
149 #define API_POSIX_POLLHUP (short int) 0x0008
150 #define API_POSIX_POLLNVAL (short int) 0x0010
151 
152 typedef unsigned int api_posix_nfds_t;
153 
154 struct api_posix_pollfd
155 {
156  int fd;
157  short int events;
158  short int revents;
159 };
160 
161 #define api_posix_struct_pollfd struct api_posix_pollfd
162 
163 int api_posix_poll(api_posix_struct_pollfd [], api_posix_nfds_t, int);
164 
165 api_posix_ssize_t api_posix_send(int, const void*, size_t, int);
166 api_posix_ssize_t api_posix_recv(int, void*, size_t, int);
167 
168 
169 /* EOF */

Generated at 2026-01-27 using  doxygen