diff options
author | Lee Salzman <[email protected]> | 2017-05-06 14:55:03 -0400 |
---|---|---|
committer | Lee Salzman <[email protected]> | 2017-05-06 14:55:03 -0400 |
commit | 3ae5af4548d4d0fbf9335f415d14897ce231a5a1 (patch) | |
tree | f998314a5e7d1388718d8d120a7e42f52b12cfdf /win32.c | |
parent | f46fee0acc8e243b2b6910b09693f93c3aad775f (diff) | |
download | enet-3ae5af4548d4d0fbf9335f415d14897ce231a5a1.tar.gz enet-3ae5af4548d4d0fbf9335f415d14897ce231a5a1.zip |
add portable enet_address_set_host_ip that can properly parse broadcast address
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 34 |
1 files changed, 27 insertions, 7 deletions
@@ -60,6 +60,32 @@ enet_time_set (enet_uint32 newTimeBase) } int +enet_address_set_host_ip (ENetAddress * address, const char * name) +{ + enet_uint8 vals [4] = { 0, 0, 0, 0 }; + int i; + + for (i = 0; i < 4; ++ i) + { + const char * next = name + 1; + if (* name != '0') + { + long val = strtol (name, (char **) & next, 10); + if (val < 0 || val > 255 || next == name || next - name > 3) + return -1; + vals [i] = (enet_uint8) val; + } + + if (* next != (i < 3 ? '.' : '\0')) + return -1; + name = next + 1; + } + + memcpy (& address -> host, vals, sizeof (enet_uint32)); + return 0; +} + +int enet_address_set_host (ENetAddress * address, const char * name) { struct hostent * hostEntry; @@ -67,13 +93,7 @@ enet_address_set_host (ENetAddress * address, const char * name) hostEntry = gethostbyname (name); if (hostEntry == NULL || hostEntry -> h_addrtype != AF_INET) - { - unsigned long host = inet_addr (name); - if (host == INADDR_NONE) - return -1; - address -> host = host; - return 0; - } + return enet_address_set_host_ip (address, name); address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; |