qstat.c
// ipaddr should be network byte-order
// port should be host byte-order
// NOTE: This will return the first matching server, which is not nessacarily correct
// depending on if duplicate ports are allowed
ipaddr should be network byte-order
port should be host byte-order
NOTE: This will return the first matching server, which is not nessacarily correct
depending on if duplicate ports are allowed
ipaddr should be network byte - order port should be host byte - order NOTE : This will return the first matching server which is not nessacarily correct depending on if duplicate ports are allowed
struct qserver *find_server_by_address(unsigned int ipaddr, unsigned short port)
{
	struct qserver **hashed;
	unsigned int hash, i;
	if ( ! noserverdups && show_errors )
	{
		fprintf( stderr, "error: find_server_by_address while duplicates are allowed, this is unsafe!" );
	}
	hash = (ipaddr + port) % ADDRESS_HASH_LENGTH;
	if (ipaddr == 0)
	{
		for (hash = 0; hash < ADDRESS_HASH_LENGTH; hash++)
		{
			printf("%3d %d\n", hash, server_hash_len[hash]);
		}
		return NULL;
	}
	hashed = server_hash[hash];
	for (i = server_hash_len[hash]; i; i--, hashed++)
	{
		if (*hashed && (*hashed)->ipaddr == ipaddr && (*hashed)->port == port)
		{
			return *hashed;
		}
	}
	return NULL;
}
struct qserver * find_server_by_address ( unsigned int ipaddr , unsigned short port ) { struct qserver * * hashed ; unsigned int hash , i ; if ( ! noserverdups && show_errors ) { fprintf ( stderr , " " ) ; } hash = ( ipaddr + port ) % ADDRESS_HASH_LENGTH ; if ( ipaddr == 0 ) { for ( hash = 0 ; hash < ADDRESS_HASH_LENGTH ; hash ++ ) { printf ( " \n " , hash , server_hash_len [ hash ] ) ; } return NULL ; } hashed = server_hash [ hash ] ; for ( i = server_hash_len [ hash ] ; i ; i -- , hashed ++ ) { if ( * hashed && ( * hashed ) -> ipaddr == ipaddr && ( * hashed ) -> port == port ) { return * hashed ; } } return NULL ; }
ipaddr should be network byte-order
port should be host byte-order
NOTE: This will return the first matching server, which is not nessacarily correct
depending on if duplicate ports are allowed
ipaddr should be network byte - order port should be host byte - order NOTE : This will return the first matching server which is not nessacarily correct depending on if duplicate ports are allowed