Hi, I am the very beginner in network programming and need to find a way to show all IP addresses being in the same network. I considered solution of getting machine's IP and subnet mask and perform some bit operations. I've already found the code to get the IP address of the local machine
but still have no idea how to get a subnet mask.
I would be grateful for any suggestions
Code:
#include <iostream>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <string>
int GetHostIP()
{
char *Ip;
WSADATA wsaData;
struct hostent *pHostEnt=NULL;
struct sockaddr_in tmpSockAddr; //placeholder for the ip address
// Not needed if it is already taken care by some other part of the application
WSAStartup(MAKEWORD(2,0),&wsaData);
char hostname[100]; //assume windows doesn't allow having longer hostnames
gethostname(hostname, sizeof hostname);
//This will retrieve the ip details and put it into pHostEnt structure
pHostEnt = gethostbyname(hostname);
if(pHostEnt == NULL)
{
printf("Error occured: %s\n",GetLastError());
WSACleanup();
return 1;
}
I would be grateful for any suggestions