zpl-c / enet

⚡️ ENet reliable UDP networking library
https://blog.zpl.pw
MIT License
699 stars 60 forks source link

Should we define ENET_FEATURE_ADDRESS_MAPPING ? #25

Closed kestrelm closed 3 years ago

kestrelm commented 3 years ago

Hello,

I noticed defining ENET_FEATURE_ADDRESS_MAPPING switches between the new and old functions ( deprecated vs new ). Should we define this for calling: enet_address_set_host ?

What should be the correct way of using this new feature? I assume sending in ipv4 address strings ( 127.0.0.1, localhost etc. ) will work since with ENET_FEATURE_ADDRESS_MAPPING defined it looks like the code will correctly map over to the new ipv6 format?

Thanks

inlife commented 3 years ago

Hey @kestrelm

This switch is intended to be used as a general config switch before the library include happens. Example:

#define ENET_FEATURE_ADDRESS_MAPPING
#define ENET_IMPLEMENTATION
#include "enet.h"

// ... rest of the code

This switch is not mandatory, to put it simply if it works for you without it then it's not really required. :)

Additional information from the author of the Pull Request (@OptoCloud):

xxx.xxx.xxx.xxx // Normal IPv4
000.000.000.000 // IPv4_ANY
127.000.000.001 // IPv4_LOOPBACK
255.255.255.000 // IPv4_BROADCAST
255.255.255.255 // IPv4_NONE

                  Marks address as IPv4
                         vvvv
0000:0000:0000:0000:0000:ffff:0000:0000 // IPv6 (from IPv4)
0000:0000:0000:0000:0000:0000:0000:0000 // IPv6_ANY         [::]
0000:0000:0000:0000:0000:0000:0000:0001 // IPv6_LOOPBACK    [::1]
ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff // IPv6_NONE

He might be able to provide more details on the specifics.

Hope that helps!

kestrelm commented 3 years ago

Alright thank you for the guidance! Have a great day. Cheers

midn1 commented 1 year ago

Is there ever a reason not to define this? I was completely unable to connect to a local server by giving an IP address without this define. By the time I switched to this ENet codebase over freeminer's and tried this, I had already fallen sleep at 7PM.

That is vital information, BTW.

zpl-zak commented 1 year ago

Is there ever a reason not to define this? I was completely unable to connect to a local server by giving an IP address without this define. By the time I switched to this ENet codebase over freeminer's and tried this, I had already fallen sleep at 7PM.

That is vital information, BTW.

We left it disabled given we weren't entirely sure how much it would affect legacy server setup in other projects. Most of the time we had no issues having ENET_FEATURE_ADDRESS_MAPPING undefined, however, there are edge cases (like yours) where this switch might need to be enabled. See https://github.com/zpl-c/enet/issues/25#issuecomment-778570389 to understand what this switch aims to do.