Give the following a try to see if it works for you.
Code:
#include <windows.h>
#include <stdio.h>
#pragma comment(lib,"mpr")
#pragma comment(lib,"wsock32")
int main(void)
{
NETRESOURCE *pNetworkResource = NULL;
HANDLE hEnumerate;
DWORD dwResult;
DWORD dwSize = 16386;
DWORD dwNumber = -1;
char pszGroupName[255] = {0};
int iLength;
struct hostent* host = NULL;
WSADATA wsaData;
if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0 )
{
printf("WSAStartup failed\n");
return -1;
}
if(WNetOpenEnum(RESOURCE_CONTEXT,RESOURCETYPE_ANY,0,NULL,&hEnumerate) != 0)
{
printf("WNetOpenEnum failed\n");
WSACleanup();
return -1;
}
pNetworkResource=(LPNETRESOURCE)GlobalAlloc(GPTR, dwSize);
if( pNetworkResource == NULL)
{
printf("GlobalAlloc failed\n");
WNetCloseEnum(hEnumerate);
WSACleanup();
return -1;
}
WNetEnumResource( hEnumerate, &dwNumber, pNetworkResource, &dwSize);
for (DWORD dwIndex = 0; dwIndex < dwNumber; dwIndex++)
{
if (pNetworkResource[dwIndex].lpRemoteName==NULL)
continue;
iLength = strlen(pNetworkResource[dwIndex].lpRemoteName);
memset(&pszGroupName, 0, sizeof(pszGroupName));
// Remove the "\\" prefix
memcpy(pszGroupName, pNetworkResource[dwIndex].lpRemoteName + 2, iLength - 2);
host = gethostbyname(pszGroupName);
if(host != NULL)
printf("%s %s\n", host->h_name, inet_ntoa( *( in_addr *)host->h_addr) );
}
GlobalFree(pNetworkResource);
WNetCloseEnum(hEnumerate);
WSACleanup();
return 0;
}