Skip to content
Permalink
Browse files
Added Windows implementation of SDLNet_GetLocalAddresses()
  • Loading branch information
slouken committed Jan 15, 2012
1 parent aadbb43 commit 4096417c9047dd012675367cb3a04edec1376fab
Showing with 468 additions and 12 deletions.
  1. +38 −4 SDLnet.c
  2. +1 −0 SDLnetsys.h
  3. +13 −0 VisualC/SDL_net_VS2008.sln
  4. +4 −4 VisualC/SDL_net_VS2008.vcproj
  5. +408 −0 VisualC/showinterfaces/showinterfaces.vcproj
  6. +2 −2 configure
  7. +2 −2 configure.in
@@ -188,16 +188,50 @@ int SDLNet_GetLocalAddresses(IPaddress *addresses, int maxcount)
}

ifr = (struct ifreq*)data;
while ((char*)ifr < data+conf.ifc_len && count < maxcount) {
while ((char*)ifr < data+conf.ifc_len) {
if (ifr->ifr_addr.sa_family == AF_INET) {
sock_addr = (struct sockaddr_in*)&ifr->ifr_addr;
addresses[count].host = sock_addr->sin_addr.s_addr;
addresses[count].port = sock_addr->sin_port;
if (count < maxcount) {
sock_addr = (struct sockaddr_in*)&ifr->ifr_addr;
addresses[count].host = sock_addr->sin_addr.s_addr;
addresses[count].port = sock_addr->sin_port;
}
++count;
}
ifr = (struct ifreq*)((char*)ifr + _SIZEOF_ADDR_IFREQ(*ifr));
}
closesocket(sock);
#elif defined(__WIN32__)
PIP_ADAPTER_INFO pAdapterInfo;
PIP_ADAPTER_INFO pAdapter;
PIP_ADDR_STRING pAddress;
DWORD dwRetVal = 0;
ULONG ulOutBufLen = sizeof (IP_ADAPTER_INFO);

pAdapterInfo = (IP_ADAPTER_INFO *) SDL_malloc(sizeof (IP_ADAPTER_INFO));
if (pAdapterInfo == NULL) {
return 0;
}

if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == ERROR_BUFFER_OVERFLOW) {
pAdapterInfo = (IP_ADAPTER_INFO *) SDL_realloc(pAdapterInfo, ulOutBufLen);
if (pAdapterInfo == NULL) {
return 0;
}
dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
}

if (dwRetVal == NO_ERROR) {
for (pAdapter = pAdapterInfo; pAdapter; pAdapter = pAdapter->Next) {
for (pAddress = &pAdapterInfo->IpAddressList; pAddress; pAddress = pAddress->Next) {
if (count < maxcount) {
addresses[count].host = inet_addr(pAddress->IpAddress.String);
addresses[count].port = 0;
}
++count;
}
}
}
SDL_free(pAdapterInfo);
#endif
return count;
}
@@ -42,6 +42,7 @@
* and is defined only for winsock2. */
typedef int socklen_t;
#endif /* W64 */
#include <iphlpapi.h>
#else /* UNIX */
#include <sys/types.h>
#ifdef __FreeBSD__
@@ -3,6 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SDL_net", "SDL_net_VS2008.vcproj", "{8AB3504F-5E58-4910-AFE8-7A1E595AC3F4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "showinterfaces", "showinterfaces\showinterfaces.vcproj", "{7B1F60CD-2A09-4514-937C-D9DD044428FB}"
ProjectSection(ProjectDependencies) = postProject
{8AB3504F-5E58-4910-AFE8-7A1E595AC3F4} = {8AB3504F-5E58-4910-AFE8-7A1E595AC3F4}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -19,6 +24,14 @@ Global
{8AB3504F-5E58-4910-AFE8-7A1E595AC3F4}.Release|Win32.Build.0 = Release|Win32
{8AB3504F-5E58-4910-AFE8-7A1E595AC3F4}.Release|x64.ActiveCfg = Release|x64
{8AB3504F-5E58-4910-AFE8-7A1E595AC3F4}.Release|x64.Build.0 = Release|x64
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Debug|Win32.ActiveCfg = Debug|Win32
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Debug|Win32.Build.0 = Debug|Win32
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Debug|x64.ActiveCfg = Debug|x64
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Debug|x64.Build.0 = Debug|x64
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Release|Win32.ActiveCfg = Release|Win32
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Release|Win32.Build.0 = Release|Win32
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Release|x64.ActiveCfg = Release|x64
{7B1F60CD-2A09-4514-937C-D9DD044428FB}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -72,7 +72,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wsock32.lib SDL.lib"
AdditionalDependencies="wsock32.lib iphlpapi.lib SDL.lib"
OutputFile=".\Debug/SDL_net.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
@@ -162,7 +162,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib SDL.lib"
AdditionalDependencies="ws2_32.lib iphlpapi.lib SDL.lib"
OutputFile=".\Debug/SDL_net.dll"
LinkIncremental="2"
SuppressStartupBanner="true"
@@ -250,7 +250,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wsock32.lib SDL.lib"
AdditionalDependencies="wsock32.lib iphlpapi.lib SDL.lib"
OutputFile=".\Release/SDL_net.dll"
LinkIncremental="1"
SuppressStartupBanner="true"
@@ -337,7 +337,7 @@
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="ws2_32.lib SDL.lib"
AdditionalDependencies="ws2_32.lib iphlpapi.lib SDL.lib"
OutputFile=".\Release/SDL_net.dll"
LinkIncremental="1"
SuppressStartupBanner="true"

0 comments on commit 4096417

Please sign in to comment.