2 * Copyright (c) 2021, 2022 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/ioctl.h>
20 #include <sys/types.h>
21 #include <sys/socket.h>
41 #include <readline/readline.h>
42 #include <readline/history.h>
46 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
54 #define TMPFSTR "/tmp/kamiftp.XXXXXXXXXX"
55 #define TMPFSTRLEN sizeof(TMPFSTR)
69 struct evbuffer *dirbuf;
73 volatile sig_atomic_t resized;
85 #define ASSERT_EMPTYBUF() assert(EVBUFFER_LENGTH(buf) == 0)
89 readline(const char *prompt)
91 char *ch, *line = NULL;
98 linelen = getline(&line, &linesize, stdin);
102 if ((ch = strchr(line, '\n')) != NULL)
108 add_history(const char *line)
115 read_line(const char *prompt)
120 if ((line = readline(prompt)) == NULL)
122 /* XXX: trim spaces? */
133 spawn(const char *argv0, ...)
138 const char *argv[16], *last;
141 memset(argv, 0, sizeof(argv));
145 for (i = 1; i < nitems(argv); ++i) {
146 last = va_arg(ap, const char *);
153 assert(last == NULL);
155 switch (pid = fork()) {
159 execvp(argv[0], (char *const *)argv);
162 waitpid(pid, &status, 0);
167 stdio_tls_write(void *arg, const char *buf, int len)
169 struct tls *ctx = arg;
173 ret = tls_write(ctx, buf, len);
174 } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT);
177 warn("tls_write: %s", tls_error(ctx));
183 stdio_tls_read(void *arg, char *buf, int len)
185 struct tls *ctx = arg;
189 ret = tls_read(ctx, buf, len);
190 } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT);
193 warn("tls_read: %s", tls_error(ctx));
199 stdio_tls_close(void *arg)
201 struct tls *ctx = arg;
205 ret = tls_close(ctx);
206 } while (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT);
212 tty_resized(int signo)
220 fprintf(stderr, "usage: %s [-c] [-C cert] [-K key] "
221 "host[:port] [path]\n", getprogname());
222 fprintf(stderr, "kamid suite version " KAMID_VERSION "\n");
243 hexdump("outgoing message", EVBUFFER_DATA(evb),
244 EVBUFFER_LENGTH(evb));
246 while (EVBUFFER_LENGTH(evb) != 0) {
247 r = fwrite(EVBUFFER_DATA(evb), 1, EVBUFFER_LENGTH(evb), fp);
249 fatalx("unexpected EOF");
250 evbuffer_drain(evb, r);
255 mustread(void *d, size_t len)
259 r = fread(d, 1, len, fp);
261 errx(1, "unexpected EOF");
271 r = fread(&len, 1, sizeof(len), fp);
272 if (r != sizeof(len))
273 errx(1, "unexpected EOF");
276 if (len < HEADERSIZE)
277 errx(1, "read message of invalid length %d", len);
279 len -= 4; /* skip the length just read */
282 l = MIN(len, sizeof(tmp));
284 r = fread(tmp, 1, l, fp);
286 errx(1, "unexpected EOF");
288 evbuffer_add(buf, tmp, r);
292 hexdump("incoming packet", EVBUFFER_DATA(buf),
293 EVBUFFER_LENGTH(buf));
297 np_read64(struct evbuffer *buf)
301 evbuffer_remove(buf, &n, sizeof(n));
306 np_read32(struct evbuffer *buf)
310 evbuffer_remove(buf, &n, sizeof(n));
315 np_read16(struct evbuffer *buf)
319 evbuffer_remove(buf, &n, sizeof(n));
324 np_read8(struct evbuffer *buf)
328 evbuffer_remove(buf, &n, sizeof(n));
333 np_readstr(struct evbuffer *buf)
338 len = np_read16(buf);
339 assert(EVBUFFER_LENGTH(buf) >= len);
341 if ((str = calloc(1, len+1)) == NULL)
343 evbuffer_remove(buf, str, len);
348 np_read_qid(struct evbuffer *buf, struct qid *qid)
350 assert(EVBUFFER_LENGTH(buf) >= QIDSIZE);
352 qid->type = np_read8(buf);
353 qid->vers = np_read32(buf);
354 qid->path = np_read64(buf);
358 np_read_stat(struct evbuffer *buf, struct np_stat *st)
362 memset(st, 0, sizeof(*st));
364 size = np_read16(buf);
365 if (size > EVBUFFER_LENGTH(buf))
368 st->type = np_read16(buf);
369 st->dev = np_read32(buf);
370 np_read_qid(buf, &st->qid);
371 st->mode = np_read32(buf);
372 st->atime = np_read32(buf);
373 st->mtime = np_read32(buf);
374 st->length = np_read64(buf);
375 st->name = np_readstr(buf);
376 st->uid = np_readstr(buf);
377 st->gid = np_readstr(buf);
378 st->muid = np_readstr(buf);
398 err = np_readstr(buf);
399 errx(1, "expected %s, got error %s",
400 pp_msg_type(type), err);
403 errx(1, "expected %s, got msg type %s",
404 pp_msg_type(type), pp_msg_type(t));
408 expect2(uint8_t type, uint16_t tag)
418 errx(1, "expected tag 0x%x, got 0x%x", tag, t);
422 check(uint8_t type, uint16_t tag)
427 rtype = np_read8(buf);
428 rtag = np_read16(buf);
431 errx(1, "expected tag 0x%x, got 0x%x", tag, rtag);
436 return np_readstr(buf);
438 errx(1, "expected %s, got msg type %s",
439 pp_msg_type(type), pp_msg_type(rtype));
447 tversion(VERSION9P, MSIZE9P);
450 expect2(Rversion, NOTAG);
452 msize = np_read32(buf);
453 version = np_readstr(buf);
455 if (msize > MSIZE9P || msize < 256)
456 errx(1, "got unexpected msize: %d", msize);
457 if (strcmp(version, VERSION9P))
458 errx(1, "unexpected 9p version: %s", version);
465 do_attach(const char *path)
472 tattach(pwdfid, NOFID, user, path);
475 expect2(Rattach, iota_tag);
476 np_read_qid(buf, &qid);
482 do_open(uint32_t fid, uint8_t mode)
490 expect2(Ropen, iota_tag);
492 np_read_qid(buf, &qid);
493 iounit = np_read32(buf);
501 do_create(uint32_t fid, const char *name, uint32_t perm, uint8_t mode)
506 tcreate(fid, name, perm, mode);
509 expect2(Rcreate, iota_tag);
511 np_read_qid(buf, &qid);
512 iounit = np_read32(buf);
520 do_clunk(uint32_t fid)
525 expect2(Rclunk, iota_tag);
531 dup_fid(int fid, int nfid)
536 twalk(fid, nfid, NULL, 0);
540 if ((errstr = check(Rwalk, iota_tag)) != NULL)
543 nwqid = np_read16(buf);
552 walk_path(int fid, int newfid, const char *path, int *missing,
555 char *wnames[MAXWELEM], *p, *t, *errstr;
559 if ((p = strdup(path)) == NULL)
563 /* strip initial ./ */
564 if (t[0] == '.' && t[1] == '/')
567 for (nwname = 0; nwname < nitems(wnames) &&
568 (wnames[nwname] = strsep(&t, "/")) != NULL;) {
569 if (*wnames[nwname] != '\0')
573 twalk(fid, newfid, (const char **)wnames, nwname);
578 if ((errstr = check(Rwalk, iota_tag)) != NULL) {
583 nwqid = np_read16(buf);
584 assert(nwqid <= nwname);
586 /* consume all qids */
587 for (i = 0; i < nwqid; ++i)
588 np_read_qid(buf, qid);
592 *missing = nwname - nwqid;
597 do_stat(int fid, struct np_stat *st)
602 expect2(Rstat, iota_tag);
604 /* eat up the first two byte length */
607 if (np_read_stat(buf, st) == -1)
608 errx(1, "invalid stat struct read");
614 do_wstat(int fid, const struct np_stat *st)
622 if ((errstr = check(Rwstat, iota_tag)) != NULL)
631 do_read(int fid, uint64_t off, uint32_t count, void *data)
635 tread(fid, off, count);
638 expect2(Rread, iota_tag);
641 assert(r == EVBUFFER_LENGTH(buf));
643 evbuffer_remove(buf, data, r);
651 do_write(int fid, uint64_t off, uint32_t count, void *data)
655 twrite(fid, off, data, count);
658 expect2(Rwrite, iota_tag);
669 draw_progress(const char *pre, const struct progress *p)
678 perc = 100.0 * p->done / p->max;
680 fprintf(stderr, "%s: %d%%\n", pre, (int)perc);
687 if (ioctl(0, TIOCGWINSZ, &ws) == -1)
689 tty_width = ws.ws_col;
694 ((l = printf("\r%s ", pre)) == -1 || l >= w))
697 w -= l + 2 + 5; /* 2 for |, 5 for percentage + \n */
699 printf("%4d%%\n", (int)perc);
705 l = w * MIN(100.0, perc) / 100.0;
706 for (i = 0; i < l; i++)
710 printf("|%4d%%", (int)perc);
716 fetch_fid(int fid, int fd, const char *name)
718 static char buf[MSIZE9P];
719 struct progress p = {0};
725 do_open(fid, KOREAD);
732 len = MIN(sizeof(buf), msize);
733 len -= IOHDRSZ; /* for the request' fields */
735 r = do_read(fid, p.done, len, buf);
739 for (off = 0; off < r; off += nw)
740 if ((nw = write(fd, buf + off, r - off)) == 0 ||
747 draw_progress(name, &p);
750 /* throttle, for debugging purpose */
752 struct timespec ts = { 0, 500000000 };
753 nanosleep(&ts, NULL);
766 send_fid(int fid, const char *fnam, int open_flags, int fd, const char *name)
768 static char buf[MSIZE9P];
769 struct progress p = {0};
774 if (fstat(fd, &sb) == -1)
778 do_create(fid, fnam, 0644, KOWRITE);
780 do_open(fid, open_flags | KOWRITE);
784 len = MIN(sizeof(buf), msize);
785 len -= HEADERSIZE + 4 + 4 + 8; /* for the request' fields */
787 r = read(fd, buf, len);
793 w = do_write(fid, p.done, r, buf);
796 draw_progress(name, &p);
799 /* throttle, for debugging purpose */
801 struct timespec ts = { 0, 500000000 };
802 nanosleep(&ts, NULL);
812 woc_file(int fd, const char *prompt, const char *path)
815 const char *n = NULL;
820 errstr = walk_path(pwdfid, nfid, path, &miss, &qid);
821 if (errstr != NULL && miss > 1) {
822 printf("%s: %s\n", path, errstr);
827 if (errstr != NULL || miss == 1) {
828 char p[PATH_MAX], *dn;
831 * If it's only one component missing (the file name), walk
832 * to the parent directory and try to create the file.
835 if (strlcpy(p, path, sizeof(p)) >= sizeof(p)) {
836 printf("path too long: %s\n", path);
841 if (!strcmp(dn, ".")) {
842 errstr = dup_fid(pwdfid, nfid);
845 errstr = walk_path(pwdfid, nfid, dn, &miss, &qid);
847 if (errstr != NULL) {
848 printf("%s: %s\n", dn, errstr);
854 printf("%s: not a directory\n", dn);
858 if ((n = strrchr(path, '/')) != NULL)
867 printf("can't create %s: missing %d path component(s)\n",
872 send_fid(nfid, n, KOTRUNC, fd, prompt);
877 dial(const char *host, const char *port)
879 struct addrinfo hints, *res, *res0;
880 int sock, error, saved_errno;
881 const char *cause = NULL;
883 memset(&hints, 0, sizeof(hints));
884 hints.ai_family = AF_UNSPEC;
885 hints.ai_socktype = SOCK_STREAM;
886 error = getaddrinfo(host, port, &hints, &res0);
888 errx(1, "%s", gai_strerror(error));
891 for (res = res0; res != NULL; res = res->ai_next) {
892 sock = socket(res->ai_family, res->ai_socktype|SOCK_CLOEXEC,
899 if (connect(sock, res->ai_addr, res->ai_addrlen) == -1) {
917 do_connect(const char *connspec, const char *path)
922 host = xstrdup(connspec);
923 if ((t = strchr(host, '@')) != NULL) {
925 errx(1, "invalid connection string: %s", connspec);
929 } else if ((user = getenv("USER")) == NULL)
930 errx(1, "USER not defined");
932 if ((t = strchr(host, ':')) != NULL) {
936 errx(1, "invalid connection string: %s", connspec);
940 printf("connecting to %s:%s...", host, port);
944 struct tls_config *conf;
948 if ((conf = tls_config_new()) == NULL)
949 fatalx("failed to create TLS config");
950 tls_config_insecure_noverifycert(conf);
951 tls_config_insecure_noverifyname(conf);
956 if (tls_config_set_keypair_file(conf, crtpath, keypath) == -1)
957 fatalx("failed to load certs: (%s, %s)", crtpath,
960 if ((ctx = tls_client()) == NULL)
961 fatalx("failed to create TLS client");
962 if (tls_configure(ctx, conf) == -1)
963 fatalx("failed to configure TLS client");
964 tls_config_free(conf);
966 if (tls_connect(ctx, host, port) == -1)
967 fatalx("failed to connect to %s:%s: %s", host, port,
971 r = tls_handshake(ctx);
972 } while (r == TLS_WANT_POLLIN || r == TLS_WANT_POLLOUT);
973 fp = funopen(ctx, stdio_tls_read, stdio_tls_write, NULL,
980 fd = dial(host, port);
981 if ((fp = fdopen(fd, "r+")) == NULL)
992 tmp_file(char sfn[TMPFSTRLEN])
996 strlcpy(sfn, TMPFSTR, TMPFSTRLEN);
997 if ((tmpfd = mkstemp(sfn)) == -1) {
998 warn("mkstemp %s", sfn);
1002 /* set the close-on-exec flag */
1003 if (fcntl(tmpfd, F_SETFD, FD_CLOEXEC) == -1) {
1012 static inline const char *
1033 /* unreachable, just for the compiler' happiness */
1039 prepare_wstat(struct np_stat *st)
1041 memset(st, 0xFF, sizeof(*st));
1049 cmd_bell(int argc, const char **argv)
1054 puts("bell mode enabled");
1056 puts("bell mode disabled");
1063 if (!strcmp(*argv, "on")) {
1065 puts("bell mode enabled");
1069 if (!strcmp(*argv, "off")) {
1071 puts("bell mode disabled");
1076 printf("bell [on | off]\n");
1080 cmd_bye(int argc, const char **argv)
1088 cmd_cd(int argc, const char **argv)
1095 printf("usage: cd remote-path\n");
1100 errstr = walk_path(pwdfid, nfid, argv[0], &miss, &qid);
1101 if (errstr != NULL) {
1102 printf("%s: %s\n", argv[0], errstr);
1107 if (miss != 0 || !(qid.type & QTDIR)) {
1108 printf("%s: not a directory\n", argv[0]);
1119 cmd_edit(int argc, const char **argv)
1122 int nfid, tmpfd, miss;
1123 char sfn[TMPFSTRLEN], p[PATH_MAX], *name, *errstr;
1127 puts("usage: edit file");
1131 if ((ed = getenv("VISUAL")) == NULL &&
1132 (ed = getenv("EDITOR")) == NULL)
1136 errstr = walk_path(pwdfid, nfid, *argv, &miss, &qid);
1137 if (errstr != NULL) {
1138 printf("%s: %s\n", *argv, errstr);
1143 if (miss != 0 || qid.type != 0) {
1144 printf("%s: not a file\n", *argv);
1150 if ((tmpfd = tmp_file(sfn)) == -1) {
1155 strlcpy(p, *argv, sizeof(p));
1158 if (fetch_fid(nfid, tmpfd, name)) {
1159 warn("failed fetch or can't write %s", sfn);
1164 spawn(ed, sfn, NULL);
1167 * Re-open the file because it's not guaranteed that the
1168 * file descriptor tmpfd is still associated with the file
1169 * pointed by sfn: it's not uncommon for editor to write
1170 * a backup file and then rename(2) it to the file name.
1172 if ((tmpfd = open(sfn, O_RDONLY)) == -1) {
1173 warn("can't open %s", sfn);
1177 woc_file(tmpfd, *argv, name);
1185 cmd_get(int argc, const char **argv)
1192 if (argc != 1 && argc != 2) {
1193 printf("usage: get remote-file [local-file]\n");
1199 else if ((l = strrchr(argv[0], '/')) != NULL)
1205 errstr = walk_path(pwdfid, nfid, argv[0], &miss, &qid);
1206 if (errstr != NULL) {
1207 printf("%s: %s\n", argv[0], errstr);
1212 if (miss != 0 || qid.type != 0) {
1213 printf("%s: not a file\n", argv[0]);
1219 if ((fd = open(l, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0644)) == -1) {
1220 warn("can't open %s", l);
1225 if (fetch_fid(nfid, fd, l) == -1)
1226 warn("write %s", l);
1231 cmd_hexdump(int argc, const char **argv)
1236 puts("hexdump mode enabled");
1238 puts("hexdump mode disabled");
1245 if (!strcmp(*argv, "on")) {
1247 puts("hexdump mode enabled");
1251 if (!strcmp(*argv, "off")) {
1253 puts("hexdump mode disabled");
1258 puts("usage: hexdump [on | off]");
1262 cmd_lcd(int argc, const char **argv)
1267 printf("usage: lcd [local-directory]\n");
1274 if (argc == 0 && (dir = getenv("HOME")) == NULL) {
1275 printf("HOME is not defined\n");
1279 if (chdir(dir) == -1)
1280 printf("cd: %s: %s\n", dir, strerror(errno));
1284 cmd_lpwd(int argc, const char **argv)
1286 char path[PATH_MAX];
1289 printf("usage: lpwd\n");
1293 if (getcwd(path, sizeof(path)) == NULL) {
1294 printf("lpwd: %s\n", strerror(errno));
1298 printf("%s\n", path);
1302 cmd_ls(int argc, const char **argv)
1311 char fmt[FMT_SCALED_STRSIZE], tim[13], *errstr;
1314 printf("ls don't take arguments (yet)\n");
1321 if ((errstr = dup_fid(pwdfid, nfid)) != NULL) {
1322 printf(".: %s\n", errstr);
1327 do_open(nfid, KOREAD);
1329 evbuffer_drain(dirbuf, EVBUFFER_LENGTH(dirbuf));
1332 tread(nfid, off, msize - IOHDRSZ);
1335 expect2(Rread, iota_tag);
1337 len = np_read32(buf);
1341 evbuffer_add_buffer(dirbuf, buf);
1347 while (EVBUFFER_LENGTH(dirbuf) != 0) {
1348 if (np_read_stat(dirbuf, &st) == -1)
1349 errx(1, "invalid stat struct read");
1351 if (fmt_scaled(st.length, fmt) == -1)
1352 strlcpy(fmt, "xxx", sizeof(fmt));
1356 if (now > mtime && (now - mtime) < 365/2 * 24 * 12 * 60)
1357 timfmt = "%b %e %R";
1359 timfmt = "%b %e %Y";
1361 if ((tm = localtime(&mtime)) == NULL ||
1362 strftime(tim, sizeof(tim), timfmt, tm) == 0)
1363 strlcpy(tim, "unknown", sizeof(tim));
1365 if (st.qid.type & QTDIR)
1369 printf("%s", pp_perm(st.mode >> 6));
1370 printf("%s", pp_perm(st.mode >> 3));
1371 printf("%s", pp_perm(st.mode));
1372 printf(" %8s %12s %s%s\n", fmt, tim, st.name,
1373 st.qid.type & QTDIR ? "/" : "");
1385 cmd_page(int argc, const char **argv)
1388 int nfid, tmpfd, miss, r;
1389 char sfn[TMPFSTRLEN], p[PATH_MAX], *name, *errstr;
1393 puts("usage: page file");
1397 if ((pager = getenv("PAGER")) == NULL)
1401 errstr = walk_path(pwdfid, nfid, *argv, &miss, &qid);
1402 if (errstr != NULL) {
1403 printf("%s: %s\n", *argv, errstr);
1408 if (miss != 0 || qid.type != 0) {
1409 printf("%s: not a file\n", *argv);
1415 if ((tmpfd = tmp_file(sfn)) == -1) {
1420 strlcpy(p, *argv, sizeof(p));
1422 if ((r = fetch_fid(nfid, tmpfd, name)) == -1)
1423 warn("write %s", sfn);
1426 spawn(pager, sfn, NULL);
1431 cmd_pipe(int argc, const char **argv)
1435 int nfid, tmpfd, miss, status;
1436 int filedes[2]; /* read end, write end */
1440 puts("usage: pipe remote-file cmd [args...]");
1445 errstr = walk_path(pwdfid, nfid, *argv, &miss, &qid);
1446 if (errstr != NULL) {
1447 printf("%s: %s\n", *argv, errstr);
1452 if (miss != 0 || qid.type != 0) {
1453 printf("%s: not a file\n", *argv);
1459 if (pipe(filedes) == -1)
1462 switch (pid = vfork()) {
1467 if (dup2(filedes[0], 0) == -1)
1469 execvp(argv[1], (char *const *)argv + 1);
1474 if (fetch_fid(nfid, filedes[1], *argv) == -1)
1475 warnx("failed to fetch all the file");
1478 waitpid(pid, &status, 0);
1482 cmd_put(int argc, const char **argv)
1488 if (argc != 1 && argc != 2) {
1489 printf("usage: put local-file [remote-file]\n");
1495 else if ((l = strrchr(argv[0], '/')) != NULL)
1500 if ((fd = open(argv[0], O_RDONLY)) == -1) {
1501 warn("%s", argv[0]);
1505 woc_file(fd, argv[0], l);
1510 cmd_rename(int argc, const char **argv)
1518 puts("usage: rename remote-file new-remote-name");
1523 errstr = walk_path(pwdfid, nfid, argv[0], &miss, &qid);
1524 if (errstr != NULL) {
1525 printf("%s: %s\n", argv[0], errstr);
1531 printf("%s: not such file or directory\n", argv[0]);
1536 st.name = (char *)argv[1];
1537 if ((errstr = do_wstat(nfid, &st)) != NULL) {
1538 printf("rename: %s\n", errstr);
1546 cmd_verbose(int argc, const char **argv)
1549 log_setverbose(!log_getverbose());
1550 if (log_getverbose())
1551 puts("verbose mode enabled");
1553 puts("verbose mode disabled");
1560 if (!strcmp(*argv, "on")) {
1562 puts("verbose mode enabled");
1566 if (!strcmp(*argv, "off")) {
1568 puts("verbose mode disabled");
1573 printf("verbose [on | off]\n");
1577 excmd(int argc, const char **argv)
1581 void (*fn)(int, const char **);
1588 {"hexdump", cmd_hexdump},
1596 {"rename", cmd_rename},
1597 {"verbose", cmd_verbose},
1603 for (i = 0; i < nitems(cmds); ++i) {
1604 if (!strcmp(cmds[i].name, *argv)) {
1605 cmds[i].fn(argc-1, argv+1);
1610 log_warnx("unknown command %s", *argv);
1614 main(int argc, char **argv)
1618 log_init(1, LOG_DAEMON);
1620 log_procinit(getprogname());
1622 while ((ch = getopt(argc, argv, "C:cK:")) != -1) {
1642 if (argc == 0 || (tls && crtpath == NULL))
1645 signal(SIGPIPE, SIG_IGN);
1649 signal(SIGWINCH, tty_resized);
1652 if ((evb = evbuffer_new()) == NULL)
1653 fatal("evbuffer_new");
1655 if ((buf = evbuffer_new()) == NULL)
1656 fatal("evbuffer_new");
1658 if ((dirbuf = evbuffer_new()) == NULL)
1659 fatal("evbuferr_new");
1661 do_connect(argv[0], argv[1]);
1665 char *line, *argv[16] = {0}, **ap;
1667 if ((line = read_line("kamiftp> ")) == NULL)
1670 for (argc = 0, ap = argv; ap < &argv[15] &&
1671 (*ap = strsep(&line, " \t")) != NULL;) {
1675 excmd(argc, (const char **)argv);