lib/dgr.c
/** Initializes a DGR slave process which will receive packets from a master process. */
Initializes a DGR slave process which will receive packets from a master process.
Initializes a DGR slave process which will receive packets from a master process .
static void dgr_init_slave()
{
#if !defined __MINGW32__ && !defined _WIN32
	const char* port = kuhl_config_get("dgr.slave.listenport");
	if(port == NULL)
	{
		msg(MSG_FATAL, "DGR Slave: DGR_SLAVE_LISTEN_PORT was not set.\n");
		exit(EXIT_FAILURE);
	}
	msg(MSG_INFO, "DGR Slave: Preparing to receive packets on port %s.\n", port);
	dgr_time_lastreceive = 0;
	struct addrinfo hints, *servinfo, *p;
	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC; 
	hints.ai_socktype = SOCK_DGRAM;
	hints.ai_flags = AI_PASSIVE; 
	int rv;
	if ((rv = getaddrinfo(NULL, port, &hints, &servinfo)) != 0) {
		msg(MSG_FATAL, "DGR Slave: getaddrinfo: %s\n", gai_strerror(rv));
		exit(EXIT_FAILURE);
	}
	for(p = servinfo; p != NULL; p = p->ai_next) {
		if ((dgr_socket = socket(p->ai_family, p->ai_socktype,
		                     p->ai_protocol)) == -1) {
			perror("DGR Slave: socket");
			continue;
		}
		if (bind(dgr_socket, p->ai_addr, p->ai_addrlen) == -1) {
			close(dgr_socket);
			msg(MSG_ERROR, "DGR Slave: bind: %s", strerror(errno));
			continue;
		}
		break;
	}
	if (p == NULL) {
		msg(MSG_FATAL, "DGR Slave: Failed to bind socket\n");
		exit(EXIT_FAILURE);
	}
	freeaddrinfo(servinfo);
#endif 
}
static void dgr_init_slave ( ) { #if ! defined __MINGW32__ && ! defined _WIN32 const char * port = kuhl_config_get ( " " ) ; if ( port == NULL ) { msg ( MSG_FATAL , " \n " ) ; exit ( EXIT_FAILURE ) ; } msg ( MSG_INFO , " \n " , port ) ; dgr_time_lastreceive = 0 ; struct addrinfo hints , * servinfo , * p ; memset ( & hints , 0 , sizeof hints ) ; hints . ai_family = AF_UNSPEC ; hints . ai_socktype = SOCK_DGRAM ; hints . ai_flags = AI_PASSIVE ; int rv ; if ( ( rv = getaddrinfo ( NULL , port , & hints , & servinfo ) ) != 0 ) { msg ( MSG_FATAL , " \n " , gai_strerror ( rv ) ) ; exit ( EXIT_FAILURE ) ; } for ( p = servinfo ; p != NULL ; p = p -> ai_next ) { if ( ( dgr_socket = socket ( p -> ai_family , p -> ai_socktype , p -> ai_protocol ) ) == -1 ) { perror ( " " ) ; continue ; } if ( bind ( dgr_socket , p -> ai_addr , p -> ai_addrlen ) == -1 ) { close ( dgr_socket ) ; msg ( MSG_ERROR , " " , strerror ( errno ) ) ; continue ; } break ; } if ( p == NULL ) { msg ( MSG_FATAL , " \n " ) ; exit ( EXIT_FAILURE ) ; } freeaddrinfo ( servinfo ) ; #endif }
Initializes a DGR slave process which will receive packets from a master process.
Initializes a DGR slave process which will receive packets from a master process .
// set to AF_INET forces IPv4; AF_INET6 forces IPv6; AF_UNSPEC allows any // use my IP // loop through all the results and bind to the first we can // __MINGW32__