From aeab3ef7acb3315c7f356f6a2dc21f80e9341161 Mon Sep 17 00:00:00 2001 From: Jean-Francois Simon Date: Tue, 15 Nov 2022 17:09:29 +0100 Subject: [PATCH] Fixed C++ builds. --- mongoose.c | 7 ++++++- test/mip_test.c | 25 ++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index c1f4df31..1e7dad37 100644 --- a/mongoose.c +++ b/mongoose.c @@ -7007,7 +7007,7 @@ static size_t tx_tcp(struct mip_if *ifp, uint32_t dst_ip, uint8_t flags, struct ip *ip = tx_ip(ifp, 6, ifp->ip, dst_ip, sizeof(struct tcp) + len); struct tcp *tcp = (struct tcp *) (ip + 1); memset(tcp, 0, sizeof(*tcp)); - memmove(tcp + 1, buf, len); + if (buf != NULL && len) memmove(tcp + 1, buf, len); tcp->sport = sport; tcp->dport = dport; tcp->seq = seq; @@ -7374,6 +7374,11 @@ void mip_init(struct mg_mgr *mgr, struct mip_if *ifp) { } } +void mip_free(struct mip_if * ifp) { + free((char *)ifp->rx.ptr); + free((char *)ifp->tx.ptr); +} + int mg_mkpipe(struct mg_mgr *m, mg_event_handler_t fn, void *d, bool udp) { (void) m, (void) fn, (void) d, (void) udp; MG_ERROR(("Not implemented")); diff --git a/test/mip_test.c b/test/mip_test.c index 01a0727a..790646d8 100644 --- a/test/mip_test.c +++ b/test/mip_test.c @@ -122,7 +122,12 @@ static void f_http_fetch_query(struct mg_connection *c, int ev, void *ev_data, v // Fetch utility returns message from fetch(..., URL, POST) char *fetch(struct mg_mgr *mgr, const char *url, const char *fn_data) { - struct Post_reply post_reply = {.post=(char*)fn_data, .http_response=0, .http_responses_received=0}; + struct Post_reply post_reply; + { + post_reply.post=(char*)fn_data; + post_reply.http_response=0; + post_reply.http_responses_received=0; + } struct mg_connection *conn; conn = mg_http_connect(mgr, url, f_http_fetch_query, &post_reply); ASSERT(conn != NULL); // Assertion on initialisation @@ -135,7 +140,7 @@ char *fetch(struct mg_mgr *mgr, const char *url, const char *fn_data) { if (!post_reply.http_responses_received) return 0; else - return post_reply.http_response; + return (char*)post_reply.http_response; } // Returns server's HTTP response code @@ -174,8 +179,18 @@ static void test_http_fetch(void) { mg_mgr_init(&mgr); // Initialise event manager // MIP driver - struct mip_driver driver = {.tx = tap_tx, .up = tap_up, .rx = tap_rx}; - struct mip_if mif = {.use_dhcp = true, .driver = &driver, .driver_data = &fd}; + struct mip_driver driver; + { + driver.tx = tap_tx; + driver.up = tap_up; + driver.rx = tap_rx; + } + struct mip_if mif; + { + mif.use_dhcp = true; + mif.driver = &driver; + mif.driver_data = &fd; + } sscanf(mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &mif.mac[0], &mif.mac[1], &mif.mac[2], &mif.mac[3], &mif.mac[4], &mif.mac[5]); @@ -197,7 +212,7 @@ static void test_http_fetch(void) { // Simple HTTP fetch { - char* http_feedback = ""; + char* http_feedback = (char*)""; const bool ipv6 = 0; if (ipv6) { http_feedback = fetch (&mgr, "ipv6.google.com",\