xref: /illumos-gate/usr/src/lib/libnsl/nsl/t_getinfo.c (revision 0ccfe5834c3b867c1b6c273cae02ec8922bc0fd2)
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 #include "mt.h"
32 #include <stdlib.h>
33 #include <string.h>
34 #include <strings.h>
35 #include <unistd.h>
36 #include <errno.h>
37 #include <stropts.h>
38 #include <sys/stream.h>
39 #define	_SUN_TPI_VERSION 2
40 #include <sys/tihdr.h>
41 #include <sys/timod.h>
42 #include <sys/stat.h>
43 #include <xti.h>
44 #include <fcntl.h>
45 #include <signal.h>
46 #include <assert.h>
47 #include <syslog.h>
48 #include <limits.h>
49 #include "tx.h"
50 
51 int
52 _tx_getinfo(int fd, struct t_info *info, int api_semantics)
53 {
54 	struct T_info_req *inforeqp;
55 	struct T_info_ack *infoackp;
56 	int retlen;
57 	struct _ti_user *tiptr;
58 	int retval, sv_errno, didalloc;
59 	struct strbuf ctlbuf;
60 
61 	if ((tiptr = _t_checkfd(fd, 0, api_semantics)) == 0)
62 		return (-1);
63 	sig_mutex_lock(&tiptr->ti_lock);
64 
65 	/*
66 	 * Acquire buffer for use in sending/receiving the message.
67 	 * Note: assumes (correctly) that ti_ctlsize is large enough
68 	 * to hold sizeof (struct T_info_req/ack)
69 	 */
70 	if (_t_acquire_ctlbuf(tiptr, &ctlbuf, &didalloc) < 0) {
71 		sv_errno = errno;
72 		sig_mutex_unlock(&tiptr->ti_lock);
73 		errno = sv_errno;
74 		return (-1);
75 	}
76 
77 	/* LINTED pointer cast */
78 	inforeqp =  (struct T_info_req *)ctlbuf.buf;
79 	inforeqp->PRIM_type = T_INFO_REQ;
80 
81 	do {
82 		retval = _t_do_ioctl(fd, ctlbuf.buf,
83 			(int)sizeof (struct T_info_req), TI_GETINFO, &retlen);
84 	} while (retval < 0 && errno == EINTR);
85 
86 	if (retval < 0)
87 		goto err_out;
88 
89 	if (retlen != (int)sizeof (struct T_info_ack)) {
90 		t_errno = TSYSERR;
91 		errno = EIO;
92 		goto err_out;
93 	}
94 
95 	/* LINTED pointer cast */
96 	infoackp = (struct T_info_ack *)ctlbuf.buf;
97 
98 	info->addr = infoackp->ADDR_size;
99 	info->options = infoackp->OPT_size;
100 	info->tsdu = infoackp->TSDU_size;
101 	info->etsdu = infoackp->ETSDU_size;
102 	info->connect = infoackp->CDATA_size;
103 	info->discon = infoackp->DDATA_size;
104 	info->servtype = infoackp->SERV_type;
105 
106 	if (_T_IS_XTI(api_semantics)) {
107 		/* XTI ONLY - TLI t_info struct does not have "flags" */
108 		info->flags = 0;
109 		if (infoackp->PROVIDER_flag & (SENDZERO|OLD_SENDZERO))
110 			info->flags |= T_SENDZERO;
111 	}
112 	if (didalloc)
113 		free(ctlbuf.buf);
114 	else
115 		tiptr->ti_ctlbuf = ctlbuf.buf;
116 	sig_mutex_unlock(&tiptr->ti_lock);
117 	return (0);
118 
119 err_out:
120 	sv_errno = errno;
121 	if (didalloc)
122 		free(ctlbuf.buf);
123 	else
124 		tiptr->ti_ctlbuf = ctlbuf.buf;
125 	sig_mutex_unlock(&tiptr->ti_lock);
126 	errno = sv_errno;
127 	return (-1);
128 }
129