newntui/nameserver/api/nameservcalls.cxx
// Function connects to name server and asks if for specified service
// returns 1 on success and sets up "service_port" and "tcp_addr"
// returns 0 if no service found
// returns -1 if unable to connect to name server
Function connects to name server and asks if for specified service
returns 1 on success and sets up "service_port" and "tcp_addr"
returns 0 if no service found
returns -1 if unable to connect to name server
Function connects to name server and asks if for specified service returns 1 on success and sets up " service_port " and " tcp_addr " returns 0 if no service found returns - 1 if unable to connect to name server
int NameServerGetService(const char *name, int &service_port, int &tcp_addr)
{
    unsigned char len_buf[4];
    int sock = ConnectToNameServer();
    if(sock < 0)
	return -1;
    if(!SendCommand(sock, FIND_SERVER))
	return -1;
    if(!SendInteger(sock, strlen(name))) {
	closesocket(sock);
	return -1;
    }
    if(!SendBuffer(sock, name, strlen(name))) {
	closesocket(sock);
	return -1;
    }
    int res = recv(sock, (char *)len_buf, 1, 0);
    if(res <= 0) {
	closesocket(sock);
	return -1;
    }
    if(len_buf[0] == 0){
	closesocket(sock);
	return 0;
    }
    res = recv(sock, (char *)len_buf, 4, 0);
    if(res <= 0){
	closesocket(sock);
	return -1;
    }
    service_port = len_buf[0] | ((unsigned)len_buf[1] << 8) | ((unsigned)len_buf[2] << 16) | ((unsigned)len_buf[3] << 24);
    res          = recv(sock, (char *)len_buf, 4, 0);
    if(res <= 0){
	closesocket(sock);
	return -1;
    }
    tcp_addr = len_buf[0] | ((unsigned)len_buf[1] << 8) | ((unsigned)len_buf[2] << 16) | ((unsigned)len_buf[3] << 24);
    closesocket(sock);
    return 1;
}
int NameServerGetService ( const char * name , int & service_port , int & tcp_addr ) { unsigned char len_buf [ 4 ] ; int sock = ConnectToNameServer ( ) ; if ( sock < 0 ) return -1 ; if ( ! SendCommand ( sock , FIND_SERVER ) ) return -1 ; if ( ! SendInteger ( sock , strlen ( name ) ) ) { closesocket ( sock ) ; return -1 ; } if ( ! SendBuffer ( sock , name , strlen ( name ) ) ) { closesocket ( sock ) ; return -1 ; } int res = recv ( sock , ( char * ) len_buf , 1 , 0 ) ; if ( res <= 0 ) { closesocket ( sock ) ; return -1 ; } if ( len_buf [ 0 ] == 0 ) { closesocket ( sock ) ; return 0 ; } res = recv ( sock , ( char * ) len_buf , 4 , 0 ) ; if ( res <= 0 ) { closesocket ( sock ) ; return -1 ; } service_port = len_buf [ 0 ] | ( ( unsigned ) len_buf [ 1 ] << 8 ) | ( ( unsigned ) len_buf [ 2 ] << 16 ) | ( ( unsigned ) len_buf [ 3 ] << 24 ) ; res = recv ( sock , ( char * ) len_buf , 4 , 0 ) ; if ( res <= 0 ) { closesocket ( sock ) ; return -1 ; } tcp_addr = len_buf [ 0 ] | ( ( unsigned ) len_buf [ 1 ] << 8 ) | ( ( unsigned ) len_buf [ 2 ] << 16 ) | ( ( unsigned ) len_buf [ 3 ] << 24 ) ; closesocket ( sock ) ; return 1 ; }
Function connects to name server and asks if for specified service
returns 1 on success and sets up "service_port" and "tcp_addr"
returns 0 if no service found
returns -1 if unable to connect to name server
Function connects to name server and asks if for specified service returns 1 on success and sets up " service_port " and " tcp_addr " returns 0 if no service found returns - 1 if unable to connect to name server