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.
29 int sms_connect(server)
35 if (!sms_inited) sms_init();
36 if (_sms_conn) return SMS_ALREADY_CONNECTED;
39 * XXX should do a hesiod call to find the sms machine name & service
43 if (!server || (strlen(server) == 0))
45 _sms_conn = start_server_connection(server, "");
46 if (_sms_conn == NULL)
48 if (connection_status(_sms_conn) == CON_STOPPED) {
49 register status = connection_errno(_sms_conn);
50 if (!status) status = SMS_CANT_CONNECT;
56 * stash hostname for later use
59 sms_server_host = strsave(server);
60 if (p = index(sms_server_host, ':'))
62 sms_server_host = canonicalize_hostname(sms_server_host);
69 _sms_conn = sever_connection(_sms_conn);
70 free(sms_server_host);
75 int sms_host(host, size)
81 /* If we are connected, sms_server_host points to a valid string. */
82 strncpy(host, sms_server_host, size);
90 struct sms_params *params = NULL;
91 struct sms_params *reply = NULL;
95 params->sms_version_no = sending_version_no;
96 params->sms_procno = SMS_NOOP;
98 params->sms_argl = NULL;
99 params->sms_argv = NULL;
101 if ((status = sms_do_call(params, &reply)) == 0)
102 status = reply->sms_status;
104 sms_destroy_reply(reply);