components/trousers/patches/tspi_rpc_tcstp_rpc.c.patch
branchs11-sru
changeset 2391 811524a2620b
child 5941 db8aa9865e9f
equal deleted inserted replaced
2390:5b1bfaf90eeb 2391:811524a2620b
       
     1 --- src/tspi/rpc/tcstp/rpc.c	2010-03-11 12:26:51.000000000 -0800
       
     2 +++ src/tspi/rpc/tcstp/rpc.c	2012-04-11 14:28:08.181630000 -0700
       
     3 @@ -345,41 +345,67 @@
       
     4  	BYTE *buffer;
       
     5  	TSS_RESULT result;
       
     6  
       
     7 -	struct sockaddr_in addr;
       
     8 -	struct hostent *hEnt = NULL;
       
     9 +	if (get_port() == 0) { /* use UNIX Domain socket */
       
    10 +		struct sockaddr_un addr;
       
    11  
       
    12 -	sd = socket(PF_INET, SOCK_STREAM, 0);
       
    13 -	if (sd == -1) {
       
    14 -		LogError("socket: %s", strerror(errno));
       
    15 -		result = TSPERR(TSS_E_COMM_FAILURE);
       
    16 -		goto err_exit;
       
    17 -	}
       
    18 -
       
    19 -	memset(&addr, 0, sizeof(addr));
       
    20 -	addr.sin_family = AF_INET;
       
    21 -	addr.sin_port = htons(get_port());
       
    22 +		sd = socket(PF_UNIX, SOCK_STREAM, 0);
       
    23 +		if (sd == -1) {
       
    24 +			LogError("socket(PF_UNIX): %s", strerror(errno));
       
    25 +			result = TSPERR(TSS_E_COMM_FAILURE);
       
    26 +			goto err_exit;
       
    27 +		}
       
    28  
       
    29 -	LogDebug("Sending TSP packet to host %s.", hte->hostname);
       
    30 +		memset(&addr, 0, sizeof(addr));
       
    31 +		addr.sun_family = AF_UNIX;
       
    32 +		strncpy(addr.sun_path, TCSD_DEFAULT_SOCKET,
       
    33 +			sizeof(addr.sun_path));
       
    34 +
       
    35 +		LogDebug("Connecting to UNIX Domain socket %s",
       
    36 +			TCSD_DEFAULT_SOCKET);
       
    37 +
       
    38 +		if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
       
    39 +			LogError("connect: %s", strerror(errno));
       
    40 +			result = TSPERR(TSS_E_COMM_FAILURE);
       
    41 +			goto err_exit;
       
    42 +		}
       
    43  
       
    44 -	/* try to resolve by hostname first */
       
    45 -	hEnt = gethostbyname((char *)hte->hostname);
       
    46 -	if (hEnt == NULL) {
       
    47 -		/* if by hostname fails, try by dot notation */
       
    48 -		if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) {
       
    49 -			LogError("hostname %s does not resolve to a valid address.", hte->hostname);
       
    50 -			result = TSPERR(TSS_E_CONNECTION_FAILED);
       
    51 +	} else { /* use TCP socket */
       
    52 +		struct sockaddr_in addr;
       
    53 +		struct hostent *hEnt = NULL;
       
    54 +
       
    55 +		sd = socket(PF_INET, SOCK_STREAM, 0);
       
    56 +		if (sd == -1) {
       
    57 +			LogError("socket: %s", strerror(errno));
       
    58 +			result = TSPERR(TSS_E_COMM_FAILURE);
       
    59  			goto err_exit;
       
    60  		}
       
    61 -	} else {
       
    62 -		memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4);
       
    63 -	}
       
    64  
       
    65 -	LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr));
       
    66 +		memset(&addr, 0, sizeof(addr));
       
    67 +		addr.sin_family = AF_INET;
       
    68 +		addr.sin_port = htons(get_port());
       
    69 +
       
    70 +		LogDebug("Sending TSP packet to host %s.", hte->hostname);
       
    71 +
       
    72 +		/* try to resolve by hostname first */
       
    73 +		hEnt = gethostbyname((char *)hte->hostname);
       
    74 +		if (hEnt == NULL) {
       
    75 +			/* if by hostname fails, try by dot notation */
       
    76 +			if (inet_aton((char *)hte->hostname, &addr.sin_addr) == 0) {
       
    77 +				LogError("hostname %s does not resolve to a valid address.", hte->hostname);
       
    78 +				result = TSPERR(TSS_E_CONNECTION_FAILED);
       
    79 +				goto err_exit;
       
    80 +			}
       
    81 +		} else {
       
    82 +			memcpy(&addr.sin_addr, hEnt->h_addr_list[0], 4);
       
    83 +		}
       
    84  
       
    85 -	if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
       
    86 -		LogError("connect: %s", strerror(errno));
       
    87 -		result = TSPERR(TSS_E_COMM_FAILURE);
       
    88 -		goto err_exit;
       
    89 +		LogDebug("Connecting to %s", inet_ntoa(addr.sin_addr));
       
    90 +
       
    91 +		if (connect(sd, (struct sockaddr *) &addr, sizeof (addr))) {
       
    92 +			LogError("connect: %s", strerror(errno));
       
    93 +			result = TSPERR(TSS_E_COMM_FAILURE);
       
    94 +			goto err_exit;
       
    95 +		}
       
    96  	}
       
    97  
       
    98  	if (send_to_socket(sd, hte->comm.buf, hte->comm.hdr.packet_size) < 0) {