dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libnls / common / nlsrequest.c
blobded00717e7d16c091a606c80da2298eed43a0214
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5.1.1 */
30 * nlsrequest(3):
32 * Send service request message to remote listener
33 * on previously established virtual circuit to remote
34 * listener process.
36 * If an error occurrs, t_errno will contain an error code.
38 * Setting the external integer "_nlslog" to any non-zero
39 * value before calling nlsrequest, will cause nlsrequest
40 * to print debug information on stderr.
42 * client/server process pairs should include their own
43 * initial handshake to insure connectivity.
45 * This version of nlsrequest includes the
46 * service request response message.
50 #include <stdio.h>
51 #include <ctype.h>
52 #include <fcntl.h>
53 #include <errno.h>
54 #include <string.h>
55 #include <stdlib.h>
56 #include <sys/tiuser.h>
57 #include "listen.h"
59 extern int _nlslog; /* non-zero allows use of stderr */
60 char *_nlsrmsg = NULL;
61 static char _nlsbuf[256];
64 int
65 nlsrequest(int fd, char *svc_code)
67 int len, err, flags;
68 char buf[256];
69 char *p;
70 int version, ret;
71 extern int t_errno;
73 t_errno = 0; /* indicates a 'name' problem */
74 buf[0] = 0;
77 * Validate service code
80 if (!svc_code || !strlen(svc_code) ||
81 (strlen(svc_code) >= (size_t)SVC_CODE_SZ)) {
82 if (_nlslog)
83 fprintf(stderr, "nlsrequest: invalid service code format\n");
84 return(-1);
88 * send protocol message requesting the service
91 len = sprintf(buf, nls_v2_msg, svc_code)+1;/* inc trailing null */
93 if (t_snd(fd, buf, len, 0) < len) {
94 if (_nlslog)
95 t_error("t_snd of listener request message failed");
96 return(-1);
99 p = _nlsbuf;
100 len = 0;
102 do {
103 if (++len > sizeof(_nlsbuf)) {
104 if (_nlslog)
105 fprintf(stderr, "nlsrequest: _nlsbuf not large enough\n");
106 return(-1);
108 if (t_rcv(fd, p, sizeof(char), &flags) != sizeof(char)) {
109 if (_nlslog)
110 t_error("t_rcv of listener response msg failed");
111 return(-1);
114 } while (*p++ != '\0');
117 if ((p = strtok(_nlsbuf, ":")) == NULL)
118 goto parsefail;
119 version = atoi(p);
121 if ((p = strtok(NULL, ":")) == NULL)
122 goto parsefail;
123 ret = atoi(p);
124 _nlsrmsg = p + strlen(p) + 1;
125 if (ret && _nlslog)
126 fprintf(stderr, "%s\n", _nlsrmsg); /* debug only */
127 return(ret);
129 parsefail:
130 if (_nlslog)
131 fprintf(stderr, "nlsrequest: failed parse of response message\n");
132 return(-1);