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