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