Skip to content

Commit 5bb4f7f

Browse files
Fix issues building examples with LWIP_IPV6 (#268)
Fixes #265
1 parent f31966d commit 5bb4f7f

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

pico_w/access_point/dhcpserver/dhcpserver.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,9 @@ static void dhcp_socket_free(struct udp_pcb **udp) {
109109
}
110110
}
111111

112-
static int dhcp_socket_bind(struct udp_pcb **udp, uint32_t ip, uint16_t port) {
113-
ip_addr_t addr;
114-
IP4_ADDR(&addr, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff);
112+
static int dhcp_socket_bind(struct udp_pcb **udp, uint16_t port) {
115113
// TODO convert lwIP errors to errno
116-
return udp_bind(*udp, &addr, port);
114+
return udp_bind(*udp, IP_ANY_TYPE, port);
117115
}
118116

119117
static int dhcp_socket_sendto(struct udp_pcb **udp, const void *buf, size_t len, uint32_t ip, uint16_t port) {
@@ -129,7 +127,7 @@ static int dhcp_socket_sendto(struct udp_pcb **udp, const void *buf, size_t len,
129127
memcpy(p->payload, buf, len);
130128

131129
ip_addr_t dest;
132-
IP4_ADDR(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff);
130+
IP4_ADDR(ip_2_ip4(&dest), ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff);
133131
err_t err = udp_sendto(*udp, p, &dest, port);
134132

135133
pbuf_free(p);
@@ -151,7 +149,7 @@ static uint8_t *opt_find(uint8_t *opt, uint8_t cmd) {
151149
return NULL;
152150
}
153151

154-
static void opt_write_n(uint8_t **opt, uint8_t cmd, size_t n, void *data) {
152+
static void opt_write_n(uint8_t **opt, uint8_t cmd, size_t n, const void *data) {
155153
uint8_t *o = *opt;
156154
*o++ = cmd;
157155
*o++ = n;
@@ -198,7 +196,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p,
198196
}
199197

200198
dhcp_msg.op = DHCPOFFER;
201-
memcpy(&dhcp_msg.yiaddr, &d->ip.addr, 4);
199+
memcpy(&dhcp_msg.yiaddr, &ip4_addr_get_u32(ip_2_ip4(&d->ip)), 4);
202200

203201
uint8_t *opt = (uint8_t *)&dhcp_msg.options;
204202
opt += 4; // assume magic cookie: 99, 130, 83, 99
@@ -241,7 +239,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p,
241239
// Should be NACK
242240
goto ignore_request;
243241
}
244-
if (memcmp(o + 2, &d->ip.addr, 3) != 0) {
242+
if (memcmp(o + 2, &ip4_addr_get_u32(ip_2_ip4(&d->ip)), 3) != 0) {
245243
// Should be NACK
246244
goto ignore_request;
247245
}
@@ -273,9 +271,9 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p,
273271
goto ignore_request;
274272
}
275273

276-
opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &d->ip.addr);
277-
opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &d->nm.addr);
278-
opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &d->ip.addr); // aka gateway; can have mulitple addresses
274+
opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &ip4_addr_get_u32(ip_2_ip4(&d->ip)));
275+
opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &ip4_addr_get_u32(ip_2_ip4(&d->nm)));
276+
opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &ip4_addr_get_u32(ip_2_ip4(&d->ip))); // aka gateway; can have mulitple addresses
279277
opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have mulitple addresses
280278
opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S);
281279
*opt++ = DHCP_OPT_END;
@@ -292,7 +290,7 @@ void dhcp_server_init(dhcp_server_t *d, ip_addr_t *ip, ip_addr_t *nm) {
292290
if (dhcp_socket_new_dgram(&d->udp, d, dhcp_server_process) != 0) {
293291
return;
294292
}
295-
dhcp_socket_bind(&d->udp, 0, PORT_DHCP_SERVER);
293+
dhcp_socket_bind(&d->udp, PORT_DHCP_SERVER);
296294
}
297295

298296
void dhcp_server_deinit(dhcp_server_t *d) {

pico_w/access_point/picow_access_point.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool tcp_server_open(void *arg) {
9393
return false;
9494
}
9595

96-
err_t err = tcp_bind(pcb, NULL, TCP_PORT);
96+
err_t err = tcp_bind(pcb, IP_ANY_TYPE, TCP_PORT);
9797
if (err) {
9898
DEBUG_printf("failed to bind to port %d\n");
9999
return false;
@@ -136,9 +136,9 @@ int main() {
136136

137137
cyw43_arch_enable_ap_mode(ap_name, password, CYW43_AUTH_WPA2_AES_PSK);
138138

139-
ip4_addr_t gw, mask;
140-
IP4_ADDR(&gw, 192, 168, 4, 1);
141-
IP4_ADDR(&mask, 255, 255, 255, 0);
139+
ip_addr_t gw, mask;
140+
IP4_ADDR(ip_2_ip4(&gw), 192, 168, 4, 1);
141+
IP4_ADDR(ip_2_ip4(&mask), 255, 255, 255, 0);
142142

143143
// Start the dhcp server
144144
dhcp_server_t dhcp_server;

pico_w/freertos/ping/picow_freertos_ping.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main_task(__unused void *params) {
3737
}
3838

3939
ip_addr_t ping_addr;
40-
ip4_addr_set_u32(&ping_addr, ipaddr_addr(PING_ADDR));
40+
ipaddr_aton(PING_ADDR, &ping_addr);
4141
ping_init(&ping_addr);
4242

4343
while(true) {

pico_w/ntp_client/picow_ntp_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static void ntp_dns_found(const char *hostname, const ip_addr_t *ipaddr, void *a
7676
NTP_T *state = (NTP_T*)arg;
7777
if (ipaddr) {
7878
state->ntp_server_address = *ipaddr;
79-
printf("ntp address %s\n", ip4addr_ntoa(ipaddr));
79+
printf("ntp address %s\n", ipaddr_ntoa(ipaddr));
8080
ntp_request(state);
8181
} else {
8282
printf("ntp dns request failed\n");

0 commit comments

Comments
 (0)