Skip to content

Improved integration with the lwip library#20441

Closed
MAntoniak wants to merge 1 commit intocurl:masterfrom
MAntoniak:lwip
Closed

Improved integration with the lwip library#20441
MAntoniak wants to merge 1 commit intocurl:masterfrom
MAntoniak:lwip

Conversation

@MAntoniak
Copy link
Contributor

@MAntoniak MAntoniak commented Jan 26, 2026

Using the lwip_* function family.
Use of the inet_ntop and lwip_inet_pton functions.
I did not change references to functions if they appeared inside the linux or USE_WINSOCK definitions.

Comment on lines +1092 to +1100
#ifdef HAVE_GETHOSTBYNAME_R_6
#define CURL_GETHOSTBYNAME_R lwip_gethostbyname_r
#endif
#ifdef HAVE_GETPEERNAME
#define CURL_GETPEERNAME lwip_getpeername
#endif
#ifdef HAVE_GETSOCKNAME
#define CURL_GETSOCKNAME lwip_getsockname
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what cases are these these 3 functions unavailable when
USE_LWIPSOCK is defined? Why guard them like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's unnecessary. I can update it, but I'm waiting for a decision on the future of this PR.

(curl_socklen_t)(size))
#elif defined(USE_LWIPSOCK)
#define curlx_inet_ntop(af,addr,buf,size) \
lwip_inet_ntop(af, addr, buf, (curl_socklen_t)(size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lwip_inet_ntop(af, addr, buf, (curl_socklen_t)(size))
lwip_inet_ntop(af, addr, buf, (curl_socklen_t)(size))

(minor indent nit)

#define CURL_LISTEN listen
#define CURL_SELECT select
#define CURL_SETSOCKOPT setsockopt
#endif
Copy link
Member

@vszakats vszakats Jan 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't the new macros need to be used in test code too,
for consistency, and to allow building (and running) tests
with lwip enabled?

edit: also in src.

@dfandrich
Copy link
Contributor

It seems strange that lwip provides a POSIX-like API but with different identifiers. Does it not have a compatibility mode that provides the standard names? Does it really expect every network application to adapt to its oddball names?

@dfandrich
Copy link
Contributor

The INSTALL.md file actually mentions lwip and talks about "BSD-style lwIP TCP/IP stack support" and that curl has been tested with lwip 1.4.0. Have you looked at that section of the document and make sure to abide by the prerequisites?

@bagder
Copy link
Member

bagder commented Jan 26, 2026

It seems strange that lwip provides a POSIX-like API but with different identifiers. Does it not have a compatibility mode that provides the standard names? Does it really expect every network application to adapt to its oddball names?

And if they need oddball names, why not define them the other way around? In this style:

#ifdef USE_LWIPSOCK
#define setsockopt() lwip_.... ()
...
#endif

@vszakats
Copy link
Member

vszakats commented Jan 27, 2026

Looking at lwip sources, it offers a macro to enable defining standard
functions, mapping them to lwip-prefixed one automatically: LWIP_COMPAT_SOCKETS.
https://github.com/lwip-tcpip/lwip/blob/4599f551dead9eac233b91c0b9ee5879f5d0620a/src/include/lwip/sockets.h#L551-L593
(it goes back to the initial commit from year 2002.)

It also offers POSIX-compatible headers via:
https://github.com/lwip-tcpip/lwip/tree/master/src/include/compat
they were added in 2012 via lwip-tcpip/lwip@d910786, released in v2.0.

I wonder if there is a reason not using them.

@MAntoniak
Copy link
Contributor Author

The main reason for these changes is the use of the lwip library without defining LWIP_COMPAT_SOCKETS. I was inspired by what has already been done for the close and fcntl functions in the curl_setup_once.h file.

We use the curl and lwip libraries in the embedded system. Our main code is written in C++. The entire project is built by Visual Studio and gcc. When defining LWIP_COMPAT_SOCKETS, it is not possible to build the project because we use these function/method names in many places, even though they are often private class methods or functions written in a different namespace. Macros will always win over a method name because it runs before compilation. For this reason, we decided not to define LWIP_COMPAT_SOCKETS.

@vszakats
Copy link
Member

The main reason for these changes is the use of the lwip library without defining LWIP_COMPAT_SOCKETS. I was inspired by what has already been done for the close and fcntl functions in the curl_setup_once.h file.

We use the curl and lwip libraries in the embedded system. Our main code is written in C++. The entire project is built by Visual Studio and gcc. When defining LWIP_COMPAT_SOCKETS, it is not possible to build the project because we use these function/method names in many places, even though they are often private class methods or functions written in a different namespace. Macros will always win over a method name because it runs before compilation. For this reason, we decided not to define LWIP_COMPAT_SOCKETS.

Past cases required strong reasons, since they impact working with
the code in significant ways. (also src and tests.)

I'd expect LWIP_COMPAT_SOCKETS to only affect the curl build itself,
which is a distinct one, producing the library and accessed via it and the
public headers. Do I understand correctly, that you build libcurl sources
as part of another project without such separation?

@MAntoniak
Copy link
Contributor Author

Do I understand correctly, that you build libcurl sources as part of another project without such separation?

Yes, I am building the project as a single piece to be programmed on a microcontroller.

@dfandrich
Copy link
Contributor

dfandrich commented Jan 27, 2026 via email

@MAntoniak
Copy link
Contributor Author

Yes, I am building the project as a single piece to be programmed on a microcontroller.
Why not enable lwip BSD compatibility only when building the libcurl portion of the project? Any build system that is capable of building libcurl would be capable of building different parts independently. I'm still not sure exactly what the problem is.

I also use the lwip library in other parts of project, such as the TCP server/client, UDP server, protocol SNTP etc. The lwip library is heavily integrated into the project and it is not easy to separate lwip from the rest.

@dfandrich
Copy link
Contributor

dfandrich commented Jan 27, 2026 via email

@MAntoniak
Copy link
Contributor Author

But, if the compatibility layer is just a set of macros, that could be enabled only when compiling libcurl, right?

I'm not sure if I understand correctly, but this could work if the macro set were defined in this file. However, these macros are defined in lwip/sockets.h.

@dfandrich
Copy link
Contributor

dfandrich commented Jan 27, 2026 via email

vszakats added a commit that referenced this pull request Jan 28, 2026
Also:
- checksrc: ban `send` and `recv`, as documented in `CODE_STYLE.md`.

Follow-up to 9a26633 #17572
Ref: a585cc3 #20097
Ref: #20441

Closes #20459
@vszakats
Copy link
Member

vszakats commented Jan 28, 2026

Agreed this is better solved locally on the build side, by separating
components or build settings.

I tried building curl with lwIP, and found a number of issues. Also
found that existing few lwip_-prefixed API uses don't seem to be
necessary with the lwIP compat macro enabled (which is the default).
(also why prefix these 4 APIs in particular?)

Further, lwip_init() is only called on Windows, and some code in
setup-win32.h, and INSTALL.md suggest lwIP support was
implemented specifically for Windows? Yet, configuration in
setup-win32.h is incomplete, _WIN32 and USE_WINSOCK
uses mixed up, CURL_TYPEOF_CURL_SOCKLEN_T size wrong.
It made me wonder how it may compile in a real-world setting?
INSTALL.md mentions v1.4.0 (2011-05-06) which was prior to
POSIX-compatible headers. Requiring v2.0.0 (2016-11-10) may help
using lwIP transparently as a BSD-style socket API on non-BSD.

Also lwIP support is missing from both cmake and autotools.

[ Finally, lwIP itself did not produce a linkable library with mingw-w64,
even after getting around some of the build issues. Maybe its Windows
support is limited to MSVC, I'm not sure. It feels not really made for
"general consumption". ]

I merged a couple of related fixes via #20455 and #20459.

@MAntoniak
Copy link
Contributor Author

I have decided to close this PR. I am unable to address this issue at this time. Thank you for all your advice.

@MAntoniak MAntoniak closed this Feb 3, 2026
@MAntoniak MAntoniak deleted the lwip branch February 4, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants