Skip to content

Commit

Permalink
Added Windows implementation of SDLNet_GetLocalAddresses()
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 15, 2012
1 parent aadbb43 commit 4096417
Show file tree
Hide file tree
Showing 7 changed files with 468 additions and 12 deletions.
42 changes: 38 additions & 4 deletions SDLnet.c
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions SDLnetsys.h
Expand Up @@ -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__
Expand Down
13 changes: 13 additions & 0 deletions VisualC/SDL_net_VS2008.sln
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions VisualC/SDL_net_VS2008.vcproj
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4096417

Please sign in to comment.