2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A
2N/A#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5.1.1 */
2N/A
2N/A/*
2N/A *
2N/A * nlsrequest(3):
2N/A *
2N/A * Send service request message to remote listener
2N/A * on previously established virtual circuit to remote
2N/A * listener process.
2N/A *
2N/A * If an error occurrs, t_errno will contain an error code.
2N/A *
2N/A * Setting the external integer "_nlslog" to any non-zero
2N/A * value before calling nlsrequest, will cause nlsrequest
2N/A * to print debug information on stderr.
2N/A *
2N/A * client/server process pairs should include their own
2N/A * initial handshake to insure connectivity.
2N/A *
2N/A * This version of nlsrequest includes the
2N/A * service request response message.
2N/A */
2N/A
2N/A
2N/A#include <stdio.h>
2N/A#include <ctype.h>
2N/A#include <fcntl.h>
2N/A#include <errno.h>
2N/A#include <string.h>
2N/A#include <stdlib.h>
2N/A#include <sys/tiuser.h>
2N/A#include "listen.h"
2N/A
2N/Aextern int _nlslog; /* non-zero allows use of stderr */
2N/Achar *_nlsrmsg = (char *)0;
2N/Astatic char _nlsbuf[256];
2N/A
2N/A
2N/Aint
2N/Anlsrequest(int fd, char *svc_code)
2N/A{
2N/A int len, err, flags;
2N/A char buf[256];
2N/A char *p;
2N/A int version, ret;
2N/A extern int t_errno;
2N/A
2N/A t_errno = 0; /* indicates a 'name' problem */
2N/A buf[0] = 0;
2N/A
2N/A /*
2N/A * Validate service code
2N/A */
2N/A
2N/A if (!svc_code || !strlen(svc_code) ||
2N/A (strlen(svc_code) >= (size_t)SVC_CODE_SZ)) {
2N/A if (_nlslog)
2N/A fprintf(stderr, "nlsrequest: invalid service code format\n");
2N/A return(-1);
2N/A }
2N/A
2N/A /*
2N/A * send protocol message requesting the service
2N/A */
2N/A
2N/A len = sprintf(buf, nls_v2_msg, svc_code)+1;/* inc trailing null */
2N/A
2N/A if (t_snd(fd, buf, len, 0) < len) {
2N/A if (_nlslog)
2N/A t_error("t_snd of listener request message failed");
2N/A return(-1);
2N/A }
2N/A
2N/A p = _nlsbuf;
2N/A len = 0;
2N/A
2N/A do {
2N/A if (++len > sizeof(_nlsbuf)) {
2N/A if (_nlslog)
2N/A fprintf(stderr, "nlsrequest: _nlsbuf not large enough\n");
2N/A return(-1);
2N/A }
2N/A if (t_rcv(fd, p, sizeof(char), &flags) != sizeof(char)) {
2N/A if (_nlslog)
2N/A t_error("t_rcv of listener response msg failed");
2N/A return(-1);
2N/A }
2N/A
2N/A } while (*p++ != '\0');
2N/A
2N/A
2N/A if ((p = strtok(_nlsbuf, ":")) == (char *)0)
2N/A goto parsefail;
2N/A version = atoi(p);
2N/A
2N/A if ((p = strtok((char *)0, ":")) == (char *)0)
2N/A goto parsefail;
2N/A ret = atoi(p);
2N/A _nlsrmsg = p + strlen(p) + 1;
2N/A if (ret && _nlslog)
2N/A fprintf(stderr, "%s\n", _nlsrmsg); /* debug only */
2N/A return(ret);
2N/A
2N/Aparsefail:
2N/A if (_nlslog)
2N/A fprintf(stderr, "nlsrequest: failed parse of response message\n");
2N/A return(-1);
2N/A}