lib/dgr.c
/** Initializes a master DGR process that will send packets out on the network. */
Initializes a master DGR process that will send packets out on the network.
Initializes a master DGR process that will send packets out on the network .
static void dgr_init_master()
{
#if !defined __MINGW32__ && !defined _WIN32
	const char *ipAddr = kuhl_config_get("dgr.master.dest");
	char *tokens[DGR_ADDRINFO_MAX_SIZE*2];
	int numTokens = kuhl_tokenize(tokens, DGR_ADDRINFO_MAX_SIZE*2, ipAddr, " ");
	if(numTokens == 0)
	{
		dgr_disabled = 1;
		msg(MSG_ERROR, "DGR Master: Won't transmit since IP address was not provided.\n");
	}
	else if(numTokens % 2 == 1)
	{
		dgr_disabled = 1;
		msg(MSG_ERROR, "DGR Master: Won't transmit since dgr.master.dest must have an even number of tokens in it: ipaddr1 port1 ipaddr2 port2 ....\n");
	}
	else
		dgr_disabled = 0;
	for(int i=0; i<numTokens; i=i+2)
	{
		char *addr = tokens[i];
		char *port = tokens[i+1];
		msg(MSG_INFO, "DGR Master: Preparing to send packets to %s port %s.\n", addr, port);
		struct addrinfo hints, *servinfo;
		memset(&hints, 0, sizeof hints);
		hints.ai_family = AF_UNSPEC;
		hints.ai_socktype = SOCK_DGRAM;
		int rv;
		if ((rv = getaddrinfo(addr, port, &hints, &servinfo)) != 0) {
			msg(MSG_ERROR, "DGR Master: getaddrinfo: %s\n", gai_strerror(rv));
			exit(1);
		}
		struct addrinfo *p;
		for(p = servinfo; p != NULL; p = p->ai_next) {
			if ((dgr_socket = socket(p->ai_family, p->ai_socktype,
			                         p->ai_protocol)) == -1) {
				msg(MSG_ERROR, "DGR: Master: socket(): %s", strerror(errno));
				continue;
			}
			break;
		}
		if (p == NULL) {
			msg(MSG_FATAL, "DGR Master: failed to bind socket\n");
			exit(EXIT_FAILURE);
		}
		dgr_addrinfo[dgr_addrinfo_len] = p;
		dgr_addrinfo_len++;
		if(dgr_addrinfo_len >= DGR_ADDRINFO_MAX_SIZE)
			i = numTokens;
	}
	kuhl_tokenize_free(tokens, DGR_ADDRINFO_MAX_SIZE*2);
#endif 
}
static void dgr_init_master ( ) { #if ! defined __MINGW32__ && ! defined _WIN32 const char * ipAddr = kuhl_config_get ( " " ) ; char * tokens [ DGR_ADDRINFO_MAX_SIZE * 2 ] ; int numTokens = kuhl_tokenize ( tokens , DGR_ADDRINFO_MAX_SIZE * 2 , ipAddr , " " ) ; if ( numTokens == 0 ) { dgr_disabled = 1 ; msg ( MSG_ERROR , " \n " ) ; } else if ( numTokens % 2 == 1 ) { dgr_disabled = 1 ; msg ( MSG_ERROR , " \n " ) ; } else dgr_disabled = 0 ; for ( int i = 0 ; i < numTokens ; i = i + 2 ) { char * addr = tokens [ i ] ; char * port = tokens [ i + 1 ] ; msg ( MSG_INFO , " \n " , addr , port ) ; struct addrinfo hints , * servinfo ; memset ( & hints , 0 , sizeof hints ) ; hints . ai_family = AF_UNSPEC ; hints . ai_socktype = SOCK_DGRAM ; int rv ; if ( ( rv = getaddrinfo ( addr , port , & hints , & servinfo ) ) != 0 ) { msg ( MSG_ERROR , " \n " , gai_strerror ( rv ) ) ; exit ( 1 ) ; } struct addrinfo * p ; for ( p = servinfo ; p != NULL ; p = p -> ai_next ) { if ( ( dgr_socket = socket ( p -> ai_family , p -> ai_socktype , p -> ai_protocol ) ) == -1 ) { msg ( MSG_ERROR , " " , strerror ( errno ) ) ; continue ; } break ; } if ( p == NULL ) { msg ( MSG_FATAL , " \n " ) ; exit ( EXIT_FAILURE ) ; } dgr_addrinfo [ dgr_addrinfo_len ] = p ; dgr_addrinfo_len ++ ; if ( dgr_addrinfo_len >= DGR_ADDRINFO_MAX_SIZE ) i = numTokens ; } kuhl_tokenize_free ( tokens , DGR_ADDRINFO_MAX_SIZE * 2 ) ; #endif }
Initializes a master DGR process that will send packets out on the network.
Initializes a master DGR process that will send packets out on the network .
// loop through all the results and make a socket // bail out of loop if too many IP addresses are specified. // __MINGW32__