Skip to content

Commit 92593aa

Browse files
committed
Fix bind, remove hard coded ip
1 parent 35045f0 commit 92593aa

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

ports/espressif/common-hal/socketpool/Socket.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,17 @@ socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_o
131131
bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *self,
132132
const char *host, size_t hostlen, uint32_t port) {
133133
struct sockaddr_in bind_addr;
134-
bind_addr.sin_addr.s_addr = inet_addr(host);
134+
const char *broadcast = "<broadcast>";
135+
uint32_t ip;
136+
if (hostlen == 0) {
137+
ip = IPADDR_ANY;
138+
} else if (hostlen == strlen(broadcast) &&
139+
memcmp(host, broadcast, strlen(broadcast)) == 0) {
140+
ip = IPADDR_BROADCAST;
141+
} else {
142+
ip = inet_addr(host);
143+
}
144+
bind_addr.sin_addr.s_addr = ip;
135145
bind_addr.sin_family = AF_INET;
136146
bind_addr.sin_port = htons(port);
137147

@@ -141,7 +151,6 @@ bool common_hal_socketpool_socket_bind(socketpool_socket_obj_t *self,
141151
mp_raise_RuntimeError(translate("Cannot set socket options"));
142152
}
143153
int result = lwip_bind(self->num, (struct sockaddr *)&bind_addr, sizeof(bind_addr));
144-
ESP_LOGE(TAG, "bind result %d", result);
145154
return result == 0;
146155
}
147156

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,9 @@ void supervisor_start_web_workflow(void) {
220220
common_hal_socketpool_socket_settimeout(&listening, 0);
221221
// Bind to any ip.
222222
// TODO: Make this port .env configurable.
223-
const char *ip = "192.168.1.94";
224-
common_hal_socketpool_socket_bind(&listening, ip, strlen(ip), 80);
223+
common_hal_socketpool_socket_bind(&listening, "", 0, 80);
225224
common_hal_socketpool_socket_listen(&listening, 1);
226225

227-
228226
mp_int_t api_password_len = dotenv_get_key("/.env", "CIRCUITPY_WEB_API_PASSWORD", _api_password + 1, sizeof(_api_password) - 2);
229227
if (api_password_len > 0) {
230228
_api_password[0] = ':';

0 commit comments

Comments
 (0)