123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #include <stdlib.h>
- #include <stdint.h>
- #include <stdio.h>
- #include <string.h>
- #include <assert.h>
- #include <unistd.h>
- #include <errno.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <getopt.h>
- #include <sys/socket.h>
- #include <sys/un.h>
- #include <faux/faux.h>
- #include <faux/str.h>
- #include <faux/msg.h>
- #include <klish/ktp.h>
- #include <klish/ktp_session.h>
- #include "private.h"
- int main(int argc, char **argv)
- {
- int retval = -1;
- struct options *opts = NULL;
- int unix_sock = -1;
- ktp_session_t *session = NULL;
- faux_msg_t *msg = NULL;
- faux_net_t *net = NULL;
- // Parse command line options
- opts = opts_init();
- if (opts_parse(argc, argv, opts)) {
- fprintf(stderr, "Error: Can't parse command line options\n");
- goto err;
- }
- // Connect to server
- unix_sock = ktp_connect_unix(opts->unix_socket_path);
- if (unix_sock < 0) {
- fprintf(stderr, "Error: Can't connect to server\n");
- goto err;
- }
- session = ktp_session_new(unix_sock);
- assert(session);
- if (!session) {
- fprintf(stderr, "Error: Can't create klish session\n");
- goto err;
- }
- net = faux_net_new();
- faux_net_set_fd(net, ktp_session_fd(session));
- msg = faux_msg_new(KTP_MAGIC, KTP_MAJOR, KTP_MINOR);
- faux_msg_set_cmd(msg, KTP_AUTH);
- faux_msg_send(msg, net);
- // write(ktp_session_fd(session), "hello", 5);
- faux_msg_free(msg);
- faux_net_free(net);
- retval = 0;
- err:
- ktp_session_free(session);
- ktp_disconnect(unix_sock);
- opts_free(opts);
- return retval;
- }
|