Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - vins

Pages: [1]
1
Network / error regarding over-range ip address (socket.connect)
« on: November 12, 2013, 07:56:59 pm »
i was trying to make port scanner using the references  through this link :-   
http://www.cplusplus.com/articles/o2N36Up4/

so, i want to know  how does the function (constructor IpAddress(address) )resolve the IP address, which are over-range (not allowed for ex:- 256.256.256.256 ) !!!!!

I meant, when i tried to input an IP address like 256.256.256.256 (or and string, which is not a valid address like "vins_net" and port 8080) , the function return value.

here's the source code and screen shot :-

#include <iostream>
#include <SFML/Network.hpp>

bool port_open(const std::string& address, int port)
{
        sf::TcpSocket socket;
        bool open = (socket.connect (sf::IpAddress(address), port)==sf::Socket::Done);
        socket.disconnect();
        return open;
}
int main()
{ std::string address;
  int port;

  std::cout<<"Enter the ip address of the client: ";
  std::cin>>address;

  std::cout<<"\nEnter the port to scan: ";
  std::cin>>port;

  if(port_open(address, port))
          std::cout<<"The port "<<port<<" at IP:"<<address<<" is OPEN."<<std::endl;
  else
          std::cout<<"The port "<<port<<" at IP:"<<address<<" is CLOSED.";

  system("pause");
  return 0;
}
 

Pages: [1]