xref: /onnv-gate/usr/src/lib/libnsl/nsl/t_strerror.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 1993-2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate 
28*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.2 */
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate /*LINTLIBRARY*/
32*0Sstevel@tonic-gate #include "mt.h"
33*0Sstevel@tonic-gate #include <unistd.h>
34*0Sstevel@tonic-gate #include <stdio.h>
35*0Sstevel@tonic-gate #include <stddef.h>
36*0Sstevel@tonic-gate #include <libintl.h>
37*0Sstevel@tonic-gate #include <stropts.h>
38*0Sstevel@tonic-gate #include <xti.h>
39*0Sstevel@tonic-gate #include "tx.h"
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate static const char __nsl_dom[]  = "SUNW_OST_NETNSL";
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate static char *_xti_errlist[] = {
44*0Sstevel@tonic-gate 	"No Error",					/*  0 */
45*0Sstevel@tonic-gate 	"Incorrect address format",			/*  1 - TBADADDR */
46*0Sstevel@tonic-gate 	"Incorrect options format",			/*  2 - TBADOPT */
47*0Sstevel@tonic-gate 	"Illegal permissions",				/*  3 - TACCES */
48*0Sstevel@tonic-gate 	"Illegal file descriptor",			/*  4 - TBADF */
49*0Sstevel@tonic-gate 	"Couldn't allocate address",			/*  5 - TNOADDR */
50*0Sstevel@tonic-gate 	"Routine will place interface out of state",    /*  6 - TOUTSTATE */
51*0Sstevel@tonic-gate 	"Illegal called/calling sequence number",	/*  7 - TBADSEQ */
52*0Sstevel@tonic-gate 	"System error",					/*  8 - TSYSERR */
53*0Sstevel@tonic-gate 	"An event requires attention",			/*  9 - TLOOK */
54*0Sstevel@tonic-gate 	"Illegal amount of data",			/* 10 - TBADDATA */
55*0Sstevel@tonic-gate 	"Buffer not large enough",			/* 11 - TBUFOVFLW */
56*0Sstevel@tonic-gate 	"Can't send message - (blocked)",		/* 12 - TFLOW */
57*0Sstevel@tonic-gate 	"No message currently available",		/* 13 - TNODATA */
58*0Sstevel@tonic-gate 	"Disconnect message not found",			/* 14 - TNODIS */
59*0Sstevel@tonic-gate 	"Unitdata error message not found",		/* 15 - TNOUDERR */
60*0Sstevel@tonic-gate 	"Incorrect flags specified",			/* 16 - TBADFLAG */
61*0Sstevel@tonic-gate 	"Orderly release message not found",		/* 17 - TNOREL */
62*0Sstevel@tonic-gate 	"Primitive not supported by provider",		/* 18 - TNOTSUPPORT */
63*0Sstevel@tonic-gate 	"State is in process of changing",		/* 19 - TSTATECHNG */
64*0Sstevel@tonic-gate 
65*0Sstevel@tonic-gate 	/* Following error codes are new in XTI */
66*0Sstevel@tonic-gate 
67*0Sstevel@tonic-gate 	"Unsupported structure type requested",		/* 20 - TNOSTRUCTYPE */
68*0Sstevel@tonic-gate 	"Invalid transport provider name",		/* 21 - TBADNAME */
69*0Sstevel@tonic-gate 	"Listener queue length limit is zero",		/* 22 - TBADQLEN */
70*0Sstevel@tonic-gate 	"Transport address is in use",			/* 23 - TADDRBUSY */
71*0Sstevel@tonic-gate 	"Outstanding connection indications",		/* 24 - TINDOUT */
72*0Sstevel@tonic-gate 	"Listener-acceptor transport provider mismatch",
73*0Sstevel@tonic-gate 							/* 25 - TPROVMISMATCH */
74*0Sstevel@tonic-gate 	"Connection acceptor has listen queue length limit greater than zero",
75*0Sstevel@tonic-gate 							/* 26 - TRESQLEN */
76*0Sstevel@tonic-gate "Connection acceptor-listener address not same but required by transport",
77*0Sstevel@tonic-gate 							/* 27 - TRESADDR */
78*0Sstevel@tonic-gate 	"Incoming connection queue is full",		/* 28 - TQFULL */
79*0Sstevel@tonic-gate 	"Protocol error on transport primitive",	/* 29 - TPROTO */
80*0Sstevel@tonic-gate };
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate static int _xti_nerr = A_CNT(_xti_errlist)-1; /* take off entry t_errno 0 */
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate char *
85*0Sstevel@tonic-gate _tx_strerror(int errnum, int api_semantics)
86*0Sstevel@tonic-gate {
87*0Sstevel@tonic-gate 	static char buf[BUFSIZ];
88*0Sstevel@tonic-gate 
89*0Sstevel@tonic-gate 	if (_T_IS_XTI(api_semantics)) {
90*0Sstevel@tonic-gate 		if (errnum <= _xti_nerr && errnum >= 0)
91*0Sstevel@tonic-gate 			return (dgettext(__nsl_dom, _xti_errlist[errnum]));
92*0Sstevel@tonic-gate 		else {
93*0Sstevel@tonic-gate 			snprintf(buf, sizeof (buf), "%d: %s", errnum,
94*0Sstevel@tonic-gate 				dgettext(__nsl_dom, "error unknown"));
95*0Sstevel@tonic-gate 			return (buf);
96*0Sstevel@tonic-gate 		}
97*0Sstevel@tonic-gate 	} else {		/* TX_TLI_API */
98*0Sstevel@tonic-gate 		/*
99*0Sstevel@tonic-gate 		 * This code for TLI only. It uses "t_nerr" and "t_errlist"
100*0Sstevel@tonic-gate 		 * which are exposed interfaces in the t_error() man page.
101*0Sstevel@tonic-gate 		 * XTI uses different array to avoid binary compatibility
102*0Sstevel@tonic-gate 		 * issues in using the exposed array. [ XTI t_error() does
103*0Sstevel@tonic-gate 		 * not mention the error message list array ]
104*0Sstevel@tonic-gate 		 *
105*0Sstevel@tonic-gate 		 * For the moment we simply index into the t_errlist[] array.
106*0Sstevel@tonic-gate 		 * When the array fills (we cannot allow it to expand in size
107*0Sstevel@tonic-gate 		 * or binary compatibility will be broken), this code will need
108*0Sstevel@tonic-gate 		 * modification.  See the comment in _errlst.c.
109*0Sstevel@tonic-gate 		 */
110*0Sstevel@tonic-gate 		if (errnum < t_nerr && errnum >= 0)
111*0Sstevel@tonic-gate 			return (dgettext(__nsl_dom, t_errlist[errnum]));
112*0Sstevel@tonic-gate 		else {
113*0Sstevel@tonic-gate 			snprintf(buf, sizeof (buf), "%d: %s", errnum,
114*0Sstevel@tonic-gate 				dgettext(__nsl_dom, "error unknown"));
115*0Sstevel@tonic-gate 			return (buf);
116*0Sstevel@tonic-gate 		}
117*0Sstevel@tonic-gate 	}
118*0Sstevel@tonic-gate }
119