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