Skip to content

Commit 3477d40

Browse files
committed
API rename, docs update, fixes
1 parent c6a09c9 commit 3477d40

28 files changed

+1125
-633
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ CMakeTmp
1212
build/*
1313
test/unit/unit
1414
tags
15+
cppcheck_results.xml

Makefile

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
CC?=gcc
2-
CFLAGS:=-Wall -Werror -Wextra -I.
2+
CFLAGS:=-Wall -Werror -Wextra -I. -D_GNU_SOURCE
33
CFLAGS+=-g -ggdb
44
LDFLAGS+=-pthread
55

6-
OBJ=build/wolftcp.o \
6+
CPPCHECK=cppcheck
7+
CPPCHECK_FLAGS=--enable=all --suppress=missingIncludeSystem \
8+
--suppress=unusedFunction --suppress=unusedVariable \
9+
--suppress=missingInclude --suppress=variableScope \
10+
--suppress=constVariable --suppress=constVariablePointer \
11+
--suppress=constParameterPointer \
12+
--suppress=constParameterCallback \
13+
--suppress=toomanyconfigs \
14+
--suppress=unmatchedSuppression --inconclusive \
15+
--std=c99 --language=c \
16+
--platform=unix64 \
17+
--error-exitcode=1 --xml --xml-version=2
18+
19+
OBJ=build/wolfip.o \
720
build/port/posix/linux_tap.o
821

922
EXE=build/tcpecho build/tcp_netcat_poll build/tcp_netcat_select \
1023
build/test-evloop build/test-dns
11-
LIB=libwolftcp.so
24+
LIB=libwolfip.so
1225

1326
PREFIX=/usr/local
1427

@@ -24,8 +37,8 @@ static: libtcpip.a
2437
libtcpip.a: $(OBJ)
2538
@ar rcs $@ $^
2639

27-
libwolftcp.so:CFLAGS+=-fPIC
28-
libwolftcp.so: build/pie/port/posix/bsd_socket.o build/pie/wolftcp.o \
40+
libwolfip.so:CFLAGS+=-fPIC
41+
libwolfip.so: build/pie/port/posix/bsd_socket.o build/pie/wolfip.o \
2942
build/pie/port/posix/linux_tap.o
3043
@mkdir -p `dirname $@` || true
3144
@echo "[LD] $@"
@@ -65,8 +78,8 @@ build/tcp_netcat_select: $(OBJ) build/port/posix/bsd_socket.o build/test/tcp_net
6578
@$(CC) $(CFLAGS) $(LDFLAGS) -o $@ -Wl,--start-group $(^) -Wl,--end-group
6679

6780

68-
build/test-wolfssl:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFTCP
69-
build/test-httpd:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFTCP -Isrc/http
81+
build/test-wolfssl:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP
82+
build/test-httpd:CFLAGS+=-Wno-cpp -DWOLFSSL_DEBUG -DWOLFSSL_WOLFIP -Isrc/http
7083

7184

7285
build/test-wolfssl: $(OBJ) build/test/test_native_wolfssl.o build/port/wolfssl_io.o build/certs/server_key.o build/certs/ca_cert.o build/certs/server_cert.o
@@ -126,7 +139,10 @@ build/test/unit:
126139
# Install dynamic library to re-link linux applications
127140
#
128141
install:
129-
install libwolftcp.so $(PREFIX)/lib
142+
install libwolfip.so $(PREFIX)/lib
130143
ldconfig
131144

132-
.PHONY: clean all static
145+
.PHONY: clean all static cppcheck
146+
147+
cppcheck:
148+
$(CPPCHECK) $(CPPCHECK_FLAGS) src/ 2>cppcheck_results.xml

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# wolfTCP
2-
3-
The smallest TCP/IP stack on the planet
1+
# wolfIP
42

53
## Description and project goals
64

7-
wolfTCP is a TCP/IP stack with no dynamic memory allocations, designed to be
5+
wolfIP is a TCP/IP stack with no dynamic memory allocations, designed to be
86
used in resource-constrained embedded systems.
97

10-
Endpoint only mode is supported, which means that wolftcp can be used to
8+
Endpoint only mode is supported, which means that wolfip can be used to
119
establish network connections but it does not route traffic between different
1210
network interfaces.
1311

@@ -31,6 +29,6 @@ A single network interface can be associated with the device.
3129

3230
## Copyright and License
3331

34-
wolfTCP is licensed under the GPLv3 license. See the LICENSE file for details.
32+
wolfIP is licensed under the GPLv3 license. See the LICENSE file for details.
3533
Copyright (c) 2025 wolfSSL Inc.
3634

config.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
#define ETHERNET
55
#define LINK_MTU 1536
66

7-
#define MAX_TCPSOCKETS 20
7+
#define MAX_TCPSOCKETS 4
88
#define MAX_UDPSOCKETS 2
99
#define RXBUF_SIZE LINK_MTU * 4
10-
#define TXBUF_SIZE LINK_MTU * 16
10+
#define TXBUF_SIZE LINK_MTU * 4
1111

1212
#define MAX_NEIGHBORS 16
1313

1414
/* Linux test configuration */
15-
#define WOLFTCP_IP "10.10.10.2"
15+
#define WOLFIP_IP "10.10.10.2"
1616
#define LINUX_IP "10.10.10.1"
1717

1818
#endif

core.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# wolfTCP
1+
# wolfIP
22

33
## Stack architecture
44

@@ -20,7 +20,7 @@
2020

2121

2222

23-
### wolfTCP fifo
23+
### wolfIP fifo
2424

2525
```
2626
+---------------------------------------------------------------------------------------------------------------------------+
@@ -42,7 +42,7 @@
4242

4343

4444

45-
### wolfTCP queue
45+
### wolfIP queue
4646

4747
```
4848
+--------------+--------------------------------------------+---------------------------------------------------------------+

docs/API.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# wolfIP API Documentation
2+
3+
## Overview
4+
5+
wolfIP is a minimal TCP/IP stack designed for resource-constrained embedded systems. It features zero dynamic memory allocation, using pre-allocated buffers and a fixed number of concurrent sockets.
6+
7+
## Key Features
8+
9+
- No dynamic memory allocation
10+
- Fixed number of concurrent sockets
11+
- Pre-allocated buffers for packet processing
12+
- BSD-like non-blocking socket API with callbacks
13+
- Protocol Support:
14+
- ARP (RFC 826)
15+
- IPv4 (RFC 791)
16+
- ICMP (RFC 792) - ping replies only
17+
- DHCP (RFC 2131) - client only
18+
- DNS (RFC 1035) - client only
19+
- UDP (RFC 768) - unicast only
20+
- TCP (RFC 793) with options (Timestamps, MSS)
21+
22+
## Core Data Structures
23+
24+
### Device Driver Interface
25+
```c
26+
struct ll {
27+
uint8_t mac[6]; // Device MAC address
28+
char ifname[16]; // Interface name
29+
int (*poll)(struct ll *ll, void *buf, uint32_t len); // Receive function
30+
int (*send)(struct ll *ll, void *buf, uint32_t len); // Transmit function
31+
};
32+
```
33+
34+
### IP Configuration
35+
```c
36+
struct ipconf {
37+
struct ll *ll; // Link layer device
38+
ip4 ip; // IPv4 address
39+
ip4 mask; // Subnet mask
40+
ip4 gw; // Default gateway
41+
};
42+
```
43+
44+
### Socket Address Structures
45+
```c
46+
struct wolfIP_sockaddr_in {
47+
uint16_t sin_family; // Address family (AF_INET)
48+
uint16_t sin_port; // Port number
49+
struct sin_addr {
50+
uint32_t s_addr; // IPv4 address
51+
} sin_addr;
52+
};
53+
54+
struct wolfIP_sockaddr {
55+
uint16_t sa_family; // Address family
56+
};
57+
```
58+
59+
## Socket Interface Functions
60+
61+
### Socket Creation and Control
62+
```c
63+
int wolfIP_sock_socket(struct wolfIP *s, int domain, int type, int protocol);
64+
```
65+
Creates a new socket.
66+
- Parameters:
67+
- s: wolfIP instance
68+
- domain: Address family (AF_INET)
69+
- type: Socket type (SOCK_STREAM/SOCK_DGRAM)
70+
- protocol: Protocol (usually 0)
71+
- Returns: Socket descriptor or negative error code
72+
73+
```c
74+
int wolfIP_sock_bind(struct wolfIP *s, int sockfd, const struct wolfIP_sockaddr *addr, socklen_t addrlen);
75+
```
76+
Binds a socket to a local address.
77+
- Parameters:
78+
- s: wolfIP instance
79+
- sockfd: Socket descriptor
80+
- addr: Local address to bind to
81+
- addrlen: Length of address structure
82+
- Returns: 0 on success, negative error code on failure
83+
84+
```c
85+
int wolfIP_sock_listen(struct wolfIP *s, int sockfd, int backlog);
86+
```
87+
Marks a socket as passive (listening for connections).
88+
- Parameters:
89+
- s: wolfIP instance
90+
- sockfd: Socket descriptor
91+
- backlog: Maximum length of pending connections queue
92+
- Returns: 0 on success, negative error code on failure
93+
94+
### Connection Management
95+
```c
96+
int wolfIP_sock_connect(struct wolfIP *s, int sockfd, const struct wolfIP_sockaddr *addr, socklen_t addrlen);
97+
```
98+
Initiates a connection on a socket.
99+
- Parameters:
100+
- s: wolfIP instance
101+
- sockfd: Socket descriptor
102+
- addr: Address to connect to
103+
- addrlen: Length of address structure
104+
- Returns: 0 on success, negative error code on failure
105+
106+
```c
107+
int wolfIP_sock_accept(struct wolfIP *s, int sockfd, struct wolfIP_sockaddr *addr, socklen_t *addrlen);
108+
```
109+
Accepts a connection on a listening socket.
110+
- Parameters:
111+
- s: wolfIP instance
112+
- sockfd: Listening socket descriptor
113+
- addr: Address of connecting peer
114+
- addrlen: Length of address structure
115+
- Returns: New socket descriptor or negative error code
116+
117+
### Data Transfer
118+
```c
119+
int wolfIP_sock_send(struct wolfIP *s, int sockfd, const void *buf, size_t len, int flags);
120+
int wolfIP_sock_recv(struct wolfIP *s, int sockfd, void *buf, size_t len, int flags);
121+
```
122+
Send/receive data on a connected socket.
123+
- Parameters:
124+
- s: wolfIP instance
125+
- sockfd: Socket descriptor
126+
- buf: Data buffer
127+
- len: Buffer length
128+
- flags: Operation flags
129+
- Returns: Number of bytes transferred or negative error code
130+
131+
```c
132+
int wolfIP_sock_sendto(struct wolfIP *s, int sockfd, const void *buf, size_t len, int flags, const struct wolfIP_sockaddr *dest_addr, socklen_t addrlen);
133+
int wolfIP_sock_recvfrom(struct wolfIP *s, int sockfd, void *buf, size_t len, int flags, struct wolfIP_sockaddr *src_addr, socklen_t *addrlen);
134+
```
135+
Send/receive data on a datagram socket.
136+
- Parameters similar to send/recv with additional address parameters
137+
138+
## Stack Interface Functions
139+
140+
```c
141+
void wolfIP_init(struct wolfIP *s);
142+
```
143+
Initializes the TCP/IP stack.
144+
- Parameters:
145+
- s: wolfIP instance to initialize
146+
147+
```c
148+
void wolfIP_init_static(struct wolfIP **s);
149+
```
150+
Initializes a static wolfIP instance.
151+
- Parameters:
152+
- s: Pointer to wolfIP instance pointer
153+
154+
```c
155+
int wolfIP_poll(struct wolfIP *s, uint64_t now);
156+
```
157+
Processes pending network events.
158+
- Parameters:
159+
- s: wolfIP instance
160+
- now: Current timestamp
161+
- Returns: Number of events processed
162+
163+
```c
164+
void wolfIP_ipconfig_set(struct wolfIP *s, ip4 ip, ip4 mask, ip4 gw);
165+
void wolfIP_ipconfig_get(struct wolfIP *s, ip4 *ip, ip4 *mask, ip4 *gw);
166+
```
167+
Set/get IP configuration.
168+
- Parameters:
169+
- s: wolfIP instance
170+
- ip: IPv4 address
171+
- mask: Subnet mask
172+
- gw: Default gateway
173+
174+
## DHCP Client Functions
175+
176+
```c
177+
int dhcp_client_init(struct wolfIP *s);
178+
```
179+
Initializes DHCP client.
180+
- Parameters:
181+
- s: wolfIP instance
182+
- Returns: 0 on success, negative error code on failure
183+
184+
```c
185+
int dhcp_bound(struct wolfIP *s);
186+
```
187+
Checks if DHCP client is bound.
188+
- Parameters:
189+
- s: wolfIP instance
190+
- Returns: 1 if bound, 0 otherwise
191+
192+
## DNS Client Functions
193+
194+
```c
195+
int nslookup(struct wolfIP *s, const char *name, uint16_t *id, void (*lookup_cb)(uint32_t ip));
196+
```
197+
Performs DNS lookup.
198+
- Parameters:
199+
- s: wolfIP instance
200+
- name: Hostname to resolve
201+
- id: Transaction ID
202+
- lookup_cb: Callback function for result
203+
- Returns: 0 on success, negative error code on failure
204+
205+
## Utility Functions
206+
207+
```c
208+
uint32_t atou(const char *s);
209+
```
210+
Converts ASCII string to unsigned integer.
211+
212+
```c
213+
ip4 atoip4(const char *ip);
214+
```
215+
Converts dotted decimal IP address string to 32-bit integer.
216+
217+
```c
218+
void iptoa(ip4 ip, char *buf);
219+
```
220+
Converts 32-bit IP address to dotted decimal string.
221+
222+
## Event Callback Registration
223+
224+
```c
225+
void wolfIP_register_callback(struct wolfIP *s, int sock_fd, void (*cb)(int sock_fd, uint16_t events, void *arg), void *arg);
226+
```
227+
Registers event callback for a socket.
228+
- Parameters:
229+
- s: wolfIP instance
230+
- sock_fd: Socket descriptor
231+
- cb: Callback function
232+
- arg: User data for callback
233+
234+
Event flags:
235+
- CB_EVENT_READABLE (0x01): Data available or connection accepted
236+
- CB_EVENT_TIMEOUT (0x02): Operation timed out
237+
- CB_EVENT_WRITABLE (0x04): Connected or space available to send
238+
- CB_EVENT_CLOSED (0x10): Connection closed by peer

0 commit comments

Comments
 (0)