title: I got error in run time that "Cannot assign requested address" in C under Linux (Centos)
body: <p>When I assign this address , it says <code>cannot assign requested address</code>. But when I put local address (127.0.0.1) it accepts it. Why???</p>
  
  <pre><code>char* hostname = "192.168.1.8"; 
  </code></pre>
  
  <p></p>
  
  <pre><code>int sockfd;
  struct sockaddr_in my_addr; // my address information
  struct sockaddr_in their_addr; // connector's address information
  socklen_t addr_len;
  int numbytes;
  char buf[MAXBUFLEN];
  int port =5000;
  
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
      perror("socket");
      exit(1);
  }
  try
  {
      my_addr.sin_family = AF_INET;        // host byte order
      my_addr.sin_addr.s_addr = inet_addr(hostname);
  
      printf("Accepted/n");
      // automatically fill with my IP
      my_addr.sin_port = htons(5000);  // short, network byte order
      memset(&amp;(my_addr.sin_zero), '\0', 8); // zero the rest of the struct
  
      if (bind(sockfd, (struct sockaddr *)&amp;my_addr, sizeof(struct sockaddr)) == -1)
      {
          perror("bind");
          exit(1);
      }
      while (1)
      {
          addr_len = sizeof(struct sockaddr);
          if ((numbytes = recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
              (struct sockaddr *)&amp;their_addr, &amp;addr_len)) == -1) {
              perror("recvfrom");
              exit(1);
          }
  
          //printf("got packet from %s\n",inet_ntoa(their_addr.sin_addr));
          //printf("packet is %d bytes long\n",numbytes);
          buf[numbytes] = '\0';
         //printf("packet contains \"%s\"\n",buf);
      }
  
      close(sockfd);
  }
  catch(...)
  {
  </code></pre>