title: c++ send UDP broadcast
body: <p>For a project i need to send a UDP broadcast every second to 87.255.255.255 and port 4448 with the values of my project. I have writen some code in c++ but i got always the error:</p>
  
  <p>Assertion `::bind(s, (sockaddr *)&amp;si_me, sizeof(sockaddr))!=-1' failed </p>
  
  <p>with this line:</p>
  
  <pre><code>//assert(::bind(s, (sockaddr *)&amp;si_me, sizeof(sockaddr))!=-1);
  </code></pre>
  
  <p>When i delete this line the code runs but i find nothing on wireshark.</p>
  
  <p>Does anyone have a solution or some extra info to build a broadcast sender?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctime&gt;
  
  int main(int argc, char const *argv[]) {
  
    sockaddr_in si_me, si_other;
    int s;
    printf("Making socket\n");
    assert((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))!=-1);
    fprintf(stderr,"usage %s hostname port\n", argv[0]);
    int port=4448;
    int broadcast=1;
    setsockopt(s, SOL_SOCKET, SO_BROADCAST,
          &amp;broadcast, sizeof broadcast);
  
          memset(&amp;si_me, 0, sizeof(si_me));
          si_me.sin_family = AF_INET;
          si_me.sin_port = htons(port);
          si_me.sin_addr.s_addr = INADDR_ANY;
  
    assert(::bind(s, (sockaddr *)&amp;si_me, sizeof(sockaddr))!=-1);
  
    while(1)
    {
       printf("Send message to broadcast\n");
       char buf[10000];
       strcpy(buf, "test for wireshark");
       unsigned slen=sizeof(sockaddr);
       send(s, buf, sizeof(buf)-1, 0);
       //recvfrom(s, buf, sizeof(buf)-1, 0, (sockaddr *)&amp;si_other, &amp;slen);
       printf("recv: %s\n", buf);
       sleep(1);
    }
  }
  </code></pre>