title: socket programming c++ connect error
body: <p>can you please help me on an issue of socket programming. my aim is to read a .txt file containing some ip's, open a socket and check the connection status of all the ip's.
  the code that i have written for this is :-</p>
  
  <pre><code>int main()
  
  {
  
  char data[100];
  
  ofstream myfile;
  myfile.open("new.txt");
  
  myfile&lt;&lt;"www.google.com";
  
  myfile&lt;&lt;"www.yahoo.com"
  
  myfile.close();
  
  ifstream readfile;
  
  readfile.open("new.txt");
  
  while(!readfile.eof())
  
  {
  
  if(!readfile.eof())
  
  {
  
  readfile.getline(data,100);
  
  int status;
  
  struct addrinfo host_info;
  
  struct addrinfo *host_info_list;
  
   memset(&amp;host_info, 0, sizeof host_info);
  
   host_info.ai_family = AF_INET;
  
   host_info.ai_socktype = SOCK_STREAM;
  
   status = getaddrinfo("data", "22", &amp;host_info, &amp;host_info_list);
  
   if (status != 0)  cout &lt;&lt; "getaddrinfo error" &lt;&lt; gai_strerror(status) ;
  
  
  else
  
  {
  
   int socketfd;
  
  socketfd = socket(host_info_list-&gt;ai_family, host_info_list-&gt;ai_socktype, 
  
  host_info_list-&gt;ai_protocol);
  
  if (socketfd == -1) cout &lt;&lt; "socket error " ;
  
  else
  
  {
  
  cout &lt;&lt; "Connect()ing..."  &lt;&lt; std::endl;
  
  //int status;
  
  status = connect(socketfd, host_info_list-&gt;ai_addr, host_info_list-       &gt;  ai_addrlen);
  
  if (status == -1)  cout &lt;&lt; "connect error" ;
  
  else
  
   {
  
   cout &lt;&lt; "connection successful"&lt;&lt;endl;
  
      freeaddrinfo(host_info_list);
  
      close(socketfd);
  
  }
  
   }}}}
  
   return 0;
   }
  </code></pre>