6 * Copyright (C) 1987 by the Massachusetts Institute of Technology
7 * For copying and distribution information, please see the file
10 * This routine is part of the client library. It handles
11 * creating a connection to the sms server.
15 static char *rcsid_sms_connect_c = "$Header$";
18 #include <mit-copyright.h>
19 #include "sms_private.h"
23 static char *sms_server_host = 0;
26 * Open a connection to the sms server. Looks for the server name
27 * 1) passed as an argument, 2) in environment variable, 3) by hesiod
28 * 4) compiled in default (from sms_app.h).
31 int sms_connect(server)
35 char *p, **pp, sbuf[256];
36 extern char *getenv(), **hes_resolve();
38 if (!sms_inited) sms_init();
39 if (_sms_conn) return SMS_ALREADY_CONNECTED;
41 if (!server || (strlen(server) == 0)) {
42 server = getenv("MOIRASERVER");
46 if (!server || (strlen(server) == 0)) {
47 pp = hes_resolve("moira", "sloc");
52 if (!server || (strlen(server) == 0)) {
56 if (!index(server, ':')) {
57 p = index(SMS_SERVER, ':');
59 sprintf(sbuf, "%s:%s", server, p);
64 _sms_conn = start_server_connection(server, "");
65 if (_sms_conn == NULL)
67 if (connection_status(_sms_conn) == CON_STOPPED) {
68 register status = connection_errno(_sms_conn);
69 if (!status) status = SMS_CANT_CONNECT;
75 * stash hostname for later use
78 sms_server_host = strsave(server);
79 if (p = index(sms_server_host, ':'))
81 sms_server_host = canonicalize_hostname(sms_server_host);
88 _sms_conn = sever_connection(_sms_conn);
89 free(sms_server_host);
94 int sms_host(host, size)
100 /* If we are connected, sms_server_host points to a valid string. */
101 strncpy(host, sms_server_host, size);
109 struct sms_params *params = NULL;
110 struct sms_params *reply = NULL;
114 params->sms_version_no = sending_version_no;
115 params->sms_procno = SMS_NOOP;
116 params->sms_argc = 0;
117 params->sms_argl = NULL;
118 params->sms_argv = NULL;
120 if ((status = sms_do_call(params, &reply)) == 0)
121 status = reply->sms_status;
123 sms_destroy_reply(reply);