コード例 #1
0
ファイル: HostAddressLinux.cpp プロジェクト: vinay/Transcend
HostAddress *HostAddress::getLocalAddress() {
	int bufferLength = 200;
	char *buffer = new char[ bufferLength ];

	gethostname( buffer, bufferLength );

    
    char *name = stringDuplicate( buffer );

	delete [] buffer;


    // this class will destroy name for us
    HostAddress *nameAddress = new HostAddress( name, 0 );

    HostAddress *fullAddress = nameAddress->getNumericalAddress();

    if( fullAddress != NULL ) {
    
        delete nameAddress;

        return fullAddress;
        }
    else {
        return nameAddress;
        }
    
    }
コード例 #2
0
HostAddress *HostAddress::getLocalAddress() {
	
    // first make sure sockets are initialized
    if( !Socket::isFrameworkInitialized() ) {
		
		// try to init the framework
		
		int error = Socket::initSocketFramework();
		
		if( error == -1 ) {
			
			printf( "initializing network socket framework failed\n" );
			return NULL;
			}
		}
	
	
	
	
	int bufferLength = 200;
	char *buffer = new char[ bufferLength ];

	gethostname( buffer, bufferLength );

    char *name = stringDuplicate( buffer );

	delete [] buffer;


    // this class will destroy name for us
    HostAddress *nameAddress = new HostAddress( name, 0 );

    HostAddress *fullAddress = nameAddress->getNumericalAddress();

    delete nameAddress;

    
    return fullAddress;    
	}