int create_receive_socket( void ) { const char *any_addr; int sock; any_addr = (gconf->af == AF_INET) ? "0.0.0.0" : "::"; sock = net_bind( "LPD", any_addr, LPD_PORT, gconf->dht_ifname, IPPROTO_UDP, gconf->af ); const int opt_off = 0; if( multicast_set_loop( sock, gconf->af, opt_off ) < 0 ) { log_warn( "LPD: Failed to set IP_MULTICAST_LOOP: %s", strerror( errno ) ); goto fail; } const int opt_on = 1; if( setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &opt_on, sizeof(opt_on) ) < 0 ) { log_warn( "LPD: Unable to set SO_REUSEADDR: %s", strerror( errno ) ); goto fail; } return sock; fail: close( sock ); return -1; }
int create_receive_socket( void ) { int sock_recv; sock_recv = net_bind( "LPD", gconf->lpd_addr, DHT_PORT_MCAST, gconf->dht_ifce, IPPROTO_UDP, gconf->af ); /* We don't want to receive our own packets */ if( multicast_set_loop( sock_recv, gconf->af, 0 ) < 0 ) { close( sock_recv ); log_warn( "LPD: Failed to set IP_MULTICAST_LOOP: %s", strerror( errno ) ); return -1; } return sock_recv; }
int create_send_socket( void ) { int sock_send; sock_send = net_socket( "LPD", gconf->dht_ifce, IPPROTO_UDP, gconf->af ); if( multicast_set_ttl( sock_send, gconf->af, 1 ) < 0 ) { log_err( "LPD: Failed to set IP_MULTICAST_TTL for sending socket: %s", strerror( errno )); goto fail; } if( multicast_set_loop( sock_send, gconf->af, 0 ) < 0 ) { log_warn( "LPD: Failed to set IP_MULTICAST_LOOP: %s", strerror( errno ) ); goto fail; } return sock_send; fail: close( sock_send ); return -1; }