cmdriver/src/CMDriver.cxx
//---------------------------------------------------------------------------
// Checks if the given service is accessible thru socket.
//    Returns: -1 - no name server,
//              0 - service is not running or is not accessible,
//              1 - service exists and is accessible.
//---------------------------------------------------------------------------
Checks if the given service is accessible thru socket.
Returns: -1 - no name server,
0 - service is not running or is not accessible,
1 - service exists and is accessible.
Checks if the given service is accessible thru socket . Returns : - 1 - no name server 0 - service is not running or is not accessible 1 - service exists and is accessible .
int checkService(const char *service_name) {
    _DBG(fprintf(log_fd, "  Checking service '%s'...\n", service_name));
    int	nPort, nAddress;
    int res = NameServerGetService(service_name, nPort, nAddress);
    if(res == 0 || res == -1) {
        _DBG(fprintf(log_fd, "    Service '%s' doesn't exist.\n",
                     service_name));
        return res;
    }
    _DBG(fprintf(log_fd, "    Service '%s' exists.\n", service_name));
    _DBG(fprintf(log_fd, "    Creating socket to connect through...\n"));
    int sock = socket(PF_INET, SOCK_STREAM, 0);
    if(sock < 0) {
        _DBG(fprintf(log_fd, "    Unable to create socket!\n"));
        return 0;
    }
    struct sockaddr_in serv_addr;
    serv_addr.sin_family = AF_INET;
    serv_addr.sin_port = htons(nPort);
#if 1
    serv_addr.sin_addr.s_addr = htonl(nAddress);
#else
    serv_addr.sin_addr.S_un.S_addr = htonl(nAddress);
#endif
    int e = connect(sock, (struct sockaddr *)&serv_addr, sizeof(sockaddr_in));
    closesocket(sock);
    if(e < 0) {
        _DBG(fprintf(log_fd, 
                     "    Unable to connect to '%s' trough socket!\n",
                     service_name));
        return 0;
    }
    return 1;
}
int checkService ( const char * service_name ) { _DBG ( fprintf ( log_fd , " \n " , service_name ) ) ; int nPort , nAddress ; int res = NameServerGetService ( service_name , nPort , nAddress ) ; if ( res == 0 || res == -1 ) { _DBG ( fprintf ( log_fd , " \n " , service_name ) ) ; return res ; } _DBG ( fprintf ( log_fd , " \n " , service_name ) ) ; _DBG ( fprintf ( log_fd , " \n " ) ) ; int sock = socket ( PF_INET , SOCK_STREAM , 0 ) ; if ( sock < 0 ) { _DBG ( fprintf ( log_fd , " \n " ) ) ; return 0 ; } struct sockaddr_in serv_addr ; serv_addr . sin_family = AF_INET ; serv_addr . sin_port = htons ( nPort ) ; #if 1 serv_addr . sin_addr . s_addr = htonl ( nAddress ) ; #else serv_addr . sin_addr . S_un . S_addr = htonl ( nAddress ) ; #endif int e = connect ( sock , ( struct sockaddr * ) & serv_addr , sizeof ( sockaddr_in ) ) ; closesocket ( sock ) ; if ( e < 0 ) { _DBG ( fprintf ( log_fd , " \n " , service_name ) ) ; return 0 ; } return 1 ; }
Checks if the given service is accessible thru socket.
Checks if the given service is accessible thru socket .
// Ask name server about this service... // Create socket... // Open socket... // Service exist and is accessible.