xref: /illumos-gate/usr/src/lib/libnsl/nsl/t_getinfo.c (revision 7c478bd9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /*
27  * Copyright 1993-2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 
32 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
33 
34 #include "mt.h"
35 #include <errno.h>
36 #include <sys/types.h>
37 #include <unistd.h>
38 #include <stdlib.h>
39 #include <rpc/trace.h>
40 #include <sys/stream.h>
41 #define	_SUN_TPI_VERSION 2
42 #include <sys/tihdr.h>
43 #include <sys/timod.h>
44 #include <xti.h>
45 #include <signal.h>
46 #include <stropts.h>
47 #include "tx.h"
48 
49 int
50 _tx_getinfo(int fd, struct t_info *info, int api_semantics)
51 {
52 	struct T_info_req *inforeqp;
53 	struct T_info_ack *infoackp;
54 	int retlen;
55 	struct _ti_user *tiptr;
56 	int retval, sv_errno, didalloc;
57 	struct strbuf ctlbuf;
58 
59 	trace2(TR_t_getinfo, 0, fd);
60 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == 0) {
61 		sv_errno = errno;
62 		trace2(TR_t_getinfo, 1, fd);
63 		errno = sv_errno;
64 		return (-1);
65 	}
66 	sig_mutex_lock(&tiptr->ti_lock);
67 
68 	/*
69 	 * Acquire buffer for use in sending/receiving the message.
70 	 * Note: assumes (correctly) that ti_ctlsize is large enough
71 	 * to hold sizeof (struct T_info_req/ack)
72 	 */
73 	if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
74 		sv_errno = errno;
75 		sig_mutex_unlock(&tiptr->ti_lock);
76 		trace2(TR_t_getinfo, 1, fd);
77 		errno = sv_errno;
78 		return (-1);
79 	}
80 
81 	inforeqp =  (struct T_info_req *)ctlbuf.buf;
82 	inforeqp->PRIM_type = T_INFO_REQ;
83 
84 	do {
85 		retval = _t_do_ioctl(fd, ctlbuf.buf,
86 			(int)sizeof (struct T_info_req), TI_GETINFO, &retlen);
87 	} while (retval < 0 && errno == EINTR);
88 
89 	if (retval < 0)
90 		goto err_out;
91 
92 	if (retlen != (int)sizeof (struct T_info_ack)) {
93 		t_errno = TSYSERR;
94 		errno = EIO;
95 		goto err_out;
96 	}
97 
98 	infoackp = (struct T_info_ack *)ctlbuf.buf;
99 
100 	info->addr = infoackp->ADDR_size;
101 	info->options = infoackp->OPT_size;
102 	info->tsdu = infoackp->TSDU_size;
103 	info->etsdu = infoackp->ETSDU_size;
104 	info->connect = infoackp->CDATA_size;
105 	info->discon = infoackp->DDATA_size;
106 	info->servtype = infoackp->SERV_type;
107 
108 	if (_T_IS_XTI(api_semantics)) {
109 		/* XTI ONLY - TLI t_info struct does not have "flags" */
110 		info->flags = 0;
111 		if (infoackp->PROVIDER_flag & (SENDZERO|OLD_SENDZERO))
112 			info->flags |= T_SENDZERO;
113 	}
114 	if (didalloc)
115 		free(ctlbuf.buf);
116 	else
117 		tiptr->ti_ctlbuf = ctlbuf.buf;
118 	sig_mutex_unlock(&tiptr->ti_lock);
119 	trace2(TR_t_getinfo, 1, fd);
120 	return (0);
121 
122 err_out:
123 	sv_errno = errno;
124 	if (didalloc)
125 		free(ctlbuf.buf);
126 	else
127 		tiptr->ti_ctlbuf = ctlbuf.buf;
128 	sig_mutex_unlock(&tiptr->ti_lock);
129 	trace2(TR_t_getinfo, 1, fd);
130 	errno = sv_errno;
131 	return (-1);
132 }
133