zpl-c / enet

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

inet_ntop wants non const addr pointer in enet_address_get_host_ip in msvc #3

Closed las3rlars closed 5 years ago

las3rlars commented 6 years ago
    int enet_address_get_host_ip(const ENetAddress *address, char *name, size_t nameLength) {
#ifdef _MSC_VER
        if (inet_ntop(AF_INET6, (ENetAddress*)&address->host, name, nameLength) == NULL) {
#else
        if (inet_ntop(AF_INET6, &address->host, name, nameLength) == NULL) {
#endif
            return -1;
        }

        return 0;
    }
inlife commented 6 years ago

Hello @las3rlars,

Sorry, is this an error, or a suggestion? Not sure I understand, can you please elaborate more.

Thank you!

las3rlars commented 6 years ago

It's an error I get when compiling using visual studio 2017. The snippet I posted is my current fix but I'm not doing a pull request because you guys might have a different way of handling platform dependent code.

It's worth mentioning that I'm using enet.h through librg.h. Following a basic example from librg.

This is the declaration of inet_ntop on my machine (WS2tcpip.h)

PCSTR
WSAAPI
inet_ntop(
    _In_                                INT             Family,
    _In_                                PVOID           pAddr,
    _Out_writes_(StringBufSize)         PSTR            pStringBuf,
    _In_                                size_t          StringBufSize
    );
inlife commented 6 years ago

I think the idea behind your snippet is good. Just minor fix would be to cast to a proper type. Since ->host isn't a ENetAddress.

Also PR would be ok I think, unless you dont really wanna do it :)

And in any case, thank you!

inlife commented 5 years ago

was fixed in v2.1.0