Index: src/OFSocket.m ================================================================== --- src/OFSocket.m +++ src/OFSocket.m @@ -24,15 +24,10 @@ # include /* For memalign() */ #endif #include -#include "platform.h" -#if defined(HAVE_NET_IF_H) && !defined(OF_MORPHOS) -# include -#endif - #import "OFArray.h" #import "OFCharacterSet.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" @@ -51,14 +46,12 @@ #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" #import "OFOutOfRangeException.h" #import "OFUnlockFailedException.h" -#ifdef OF_WINDOWS -# define interface struct -# include -# undef interface +#ifdef HAVE_NET_IF_H +# include #endif #ifdef OF_AMIGAOS # include #endif @@ -99,15 +92,10 @@ struct SocketIFace *ISocket = NULL; # endif # endif #endif -#ifdef OF_WINDOWS -static WINAPI PCHAR (*if_indextonamePtr)(NET_IFINDEX, PCHAR); -static WINAPI NET_IFINDEX (*if_nametoindexPtr)(PCSTR); -#endif - #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OF_CONSTRUCTOR() { if (OFTLSKeyNew(&OFSocketBaseKey) != 0) @throw [OFInitializationFailedException exception]; @@ -123,21 +111,13 @@ static void init(void) { # if defined(OF_WINDOWS) WSADATA wsa; - HMODULE module; if (WSAStartup(MAKEWORD(2, 0), &wsa)) return; - - if ((module = LoadLibrary("iphlpapi.dll")) != NULL) { - if_indextonamePtr = (WINAPI PCHAR (*)(NET_IFINDEX, PCHAR)) - GetProcAddress(module, "if_indextoname"); - if_nametoindexPtr = (WINAPI NET_IFINDEX (*)(PCSTR)) - GetProcAddress(module, "if_nametoindex"); - } # elif defined(OF_AMIGAOS) if ((SocketBase = OpenLibrary("bsdsocket.library", 4)) == NULL) return; # ifdef OF_AMIGAOS4 @@ -469,23 +449,25 @@ addrIn6->sin6_family = AF_UNSPEC; #endif addrIn6->sin6_port = OFToBigEndian16(port); if ((percent = [IPv6 rangeOfString: @"%"].location) != OFNotFound) { -#if defined(HAVE_IF_NAMETOINDEX) || defined(OF_WINDOWS) OFString *interface = [IPv6 substringFromIndex: percent + 1]; -#endif IPv6 = [IPv6 substringToIndex: percent]; -#if defined(OF_WINDOWS) - if (if_nametoindexPtr != NULL) - addrIn6->sin6_scope_id = if_nametoindexPtr([interface + @try { + addrIn6->sin6_scope_id = (uint32_t)[interface + unsignedLongLongValueWithBase: 10]; + } @catch (OFInvalidFormatException *e) { +#if defined(HAVE_IF_NAMETOINDEX) && !defined(OF_WINDOWS) + addrIn6->sin6_scope_id = if_nametoindex([interface cStringWithEncoding: [OFLocale encoding]]); -#elif defined(HAVE_IF_NAMETOINDEX) - addrIn6->sin6_scope_id = if_nametoindex( - [interface cStringWithEncoding: [OFLocale encoding]]); #endif + } + + if (addrIn6->sin6_scope_id == 0) + @throw [OFInvalidArgumentException exception]; } doubleColon = [IPv6 rangeOfString: @"::"].location; if (doubleColon != OFNotFound) { OFString *left = [IPv6 substringToIndex: doubleColon]; @@ -907,27 +889,20 @@ addrIn6->sin6_addr.s6_addr[i + 1]]; first = false; } } -#if defined(HAVE_IF_INDEXTONAME) || defined(OF_WINDOWS) if (addrIn6->sin6_scope_id != 0) { -# ifdef OF_WINDOWS - char interface[IF_MAX_STRING_SIZE]; - - if (if_indextonamePtr != NULL && if_indextonamePtr( - addrIn6->sin6_scope_id, interface) != NULL) -# else +#if defined(HAVE_IF_INDEXTONAME) && !defined(OF_WINDOWS) char interface[IF_NAMESIZE]; if (if_indextoname(addrIn6->sin6_scope_id, interface) != NULL) -# endif [string appendFormat: @"%%%s", interface]; else +# endif [string appendFormat: @"%%%u", addrIn6->sin6_scope_id]; } -#endif [string makeImmutable]; return string; }