Relevant dsicver server routine from squeezelite source in slimproto.c

Code:
--------------------
    
  in_addr_t discover_server(void) {
  struct sockaddr_in d;
  struct sockaddr_in s;
        char *buf;
        struct pollfd pollinfo;
  
        int disc_sock = socket(AF_INET, SOCK_DGRAM, 0);
  
        socklen_t enable = 1;
        setsockopt(disc_sock, SOL_SOCKET, SO_BROADCAST, (const void *)&enable, 
sizeof(enable));
  
        buf = "e";
  
        memset(&d, 0, sizeof(d));
  d.sin_family = AF_INET;
        d.sin_port = htons(PORT);
  d.sin_addr.s_addr = htonl(INADDR_BROADCAST);
  
        pollinfo.fd = disc_sock;
        pollinfo.events = POLLIN;
  
        do {
  
                LOG_INFO("sending discovery");
                memset(&s, 0, sizeof(s));
  
                if (sendto(disc_sock, buf, 1, 0, (struct sockaddr *)&d, 
sizeof(d)) < 0) {
                        LOG_INFO("error sending disovery");
                }
  
                if (poll(&pollinfo, 1, 5000) == 1) {
                        char readbuf[10];
                        socklen_t slen = sizeof(s);
                        recvfrom(disc_sock, readbuf, 10, 0, (struct sockaddr 
*)&s, &slen);
                        LOG_INFO("got response from: %s:%d", 
inet_ntoa(s.sin_addr), ntohs(s.sin_port));
                }
  
        } while (s.sin_addr.s_addr == 0 && running);
  
        closesocket(disc_sock);
  
        return s.sin_addr.s_addr;
  }
  
--------------------


------------------------------------------------------------------------
bpa's Profile: http://forums.slimdevices.com/member.php?userid=1806
View this thread: http://forums.slimdevices.com/showthread.php?t=105040

_______________________________________________
discuss mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/discuss

Reply via email to