title: Socket C++ program successfully compiled crashes at runtime
body: <p>I've been struggling with this for hours, but I couldn't manage to find out what am I doing wrong. This is a very simple program that SHOULD send out a simple UDP packet to a given IP on a given port. g++ compiles this program without any error or warning, but when I run it...!
  It just dies. On stdout it prints: 0 (this should mean binding worked correctly) and "TRYING TO SEND". And then nothing. It simply doesn't print "HERE I AM". No errors, no messages, nothing. Does anybody have any hint?
  Here is the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;time.h&gt;
  #include &lt;stdio.h&gt;
  
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;ifaddrs.h&gt;
  
  using namespace std;
  
  int main()
  {
      struct sockaddr_in local_addr;
      local_addr.sin_family=AF_INET;
      local_addr.sin_port=0;
      local_addr.sin_addr.s_addr=htonl(INADDR_ANY);
      memset(local_addr.sin_zero, '\0', sizeof(local_addr.sin_zero));
  
      int local_socket;
      local_socket = socket(PF_INET, SOCK_STREAM, 0);
      cout&lt;&lt;bind(local_socket, (struct sockaddr *)&amp;local_addr, sizeof(sockaddr_in))        &lt;&lt;endl;;
  
  
      char remote_addr[]="95.110.232.188";
  
      struct sockaddr_in remote_sockaddr;
      remote_sockaddr.sin_family=AF_INET;
      remote_sockaddr.sin_port=1180;
      remote_sockaddr.sin_addr.s_addr=inet_addr(remote_addr);
      memset(remote_sockaddr.sin_zero, '\0', sizeof(remote_sockaddr.sin_zero));
      cout&lt;&lt;"TRYING TO SEND.."&lt;&lt;endl;
      cout&lt;&lt;sendto(local_socket, "PTDMW", 5, 0, (struct sockaddr *) &amp; remote_sockaddr, sizeof(sockaddr_in))&lt;&lt;endl;
      cout&lt;&lt;"HERE I AM!!"&lt;&lt;endl;  
  
  }
  </code></pre>