xref: /titanic_44/usr/src/lib/libnsl/nsl/t_getinfo.c (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
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 
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
24 /*	  All Rights Reserved  	*/
25 
26 /*
27  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
32 
33 #include "mt.h"
34 #include <stdlib.h>
35 #include <string.h>
36 #include <strings.h>
37 #include <unistd.h>
38 #include <errno.h>
39 #include <stropts.h>
40 #include <sys/stream.h>
41 #define	_SUN_TPI_VERSION 2
42 #include <sys/tihdr.h>
43 #include <sys/timod.h>
44 #include <sys/stat.h>
45 #include <xti.h>
46 #include <fcntl.h>
47 #include <signal.h>
48 #include <assert.h>
49 #include <syslog.h>
50 #include <limits.h>
51 #include "tx.h"
52 
53 int
54 _tx_getinfo(int fd, struct t_info *info, int api_semantics)
55 {
56 	struct T_info_req *inforeqp;
57 	struct T_info_ack *infoackp;
58 	int retlen;
59 	struct _ti_user *tiptr;
60 	int retval, sv_errno, didalloc;
61 	struct strbuf ctlbuf;
62 
63 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == 0)
64 		return (-1);
65 	sig_mutex_lock(&tiptr->ti_lock);
66 
67 	/*
68 	 * Acquire buffer for use in sending/receiving the message.
69 	 * Note: assumes (correctly) that ti_ctlsize is large enough
70 	 * to hold sizeof (struct T_info_req/ack)
71 	 */
72 	if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
73 		sv_errno = errno;
74 		sig_mutex_unlock(&tiptr->ti_lock);
75 		errno = sv_errno;
76 		return (-1);
77 	}
78 
79 	/* LINTED pointer cast */
80 	inforeqp =  (struct T_info_req *)ctlbuf.buf;
81 	inforeqp->PRIM_type = T_INFO_REQ;
82 
83 	do {
84 		retval = _t_do_ioctl(fd, ctlbuf.buf,
85 			(int)sizeof (struct T_info_req), TI_GETINFO, &retlen);
86 	} while (retval < 0 && errno == EINTR);
87 
88 	if (retval < 0)
89 		goto err_out;
90 
91 	if (retlen != (int)sizeof (struct T_info_ack)) {
92 		t_errno = TSYSERR;
93 		errno = EIO;
94 		goto err_out;
95 	}
96 
97 	/* LINTED pointer cast */
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 	return (0);
120 
121 err_out:
122 	sv_errno = errno;
123 	if (didalloc)
124 		free(ctlbuf.buf);
125 	else
126 		tiptr->ti_ctlbuf = ctlbuf.buf;
127 	sig_mutex_unlock(&tiptr->ti_lock);
128 	errno = sv_errno;
129 	return (-1);
130 }
131