title: How to check error messages from perror?
body: <p>I know this a simple but i couldn't get it.</p>
  
  <p>I am using OS- Ubuntu. The following code has been written in mysql source code (in sql_parse.cc file). I need to check the perror error message. How can i get those messages?
  I don't think this error messages will be shown in the console where i am running mysql client/ server?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;sys/socket.h&gt;
  
  { 
  string hashed;
  int sockfd, n;
  char buf[MAXDATASIZE], url[MAXDATASIZE], ack[6];
  struct hostent *he;
  struct sockaddr_in remote_addr;
  
  if ((he=gethostbyname("localhost")) == NULL) { // get the host info
      perror("gethostbyname");
      exit(1);
      }
  
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      perror("socket");
      exit(1);
      }
  
  remote_addr.sin_family = AF_INET; // host byte order
  remote_addr.sin_port = htons(PORT); // short, network byte order
  remote_addr.sin_addr = *((struct in_addr *)he-&gt;h_addr);
  memset(&amp;(remote_addr.sin_zero), '\0', 8); // zero the rest of the struct
  
  if (connect(sockfd, (struct sockaddr *)&amp;remote_addr, sizeof(struct sockaddr)) == -1) {
      perror("connect");
      exit(1);
      }
  </code></pre>
  
  <p>Please help me....</p>