Annotation of OpenXM/src/oxc/oxc.c, Revision 1.1
1.1 ! ohara 1: /* -*- mode: C -*- */
! 2: /* $OpenXM$ */
! 3:
! 4: #include <stdio.h>
! 5: #include <stdlib.h>
! 6: #include <unistd.h>
! 7: #include <string.h>
! 8: #include "mysocket.h"
! 9: #include "ox_toolkit.h"
! 10: #include "sm.h"
! 11:
! 12: /* oxc -c password -p port -h hostname */
! 13: static char *remote_host = "";
! 14: static short port = 0;
! 15: static char *password = "";
! 16:
! 17: int oxf_connect_dup(char *remote, short port)
! 18: {
! 19: int fd = mysocketOpen(remote, port);
! 20: /* Here do we need to confirm? */
! 21: dup2(fd, 3);
! 22: dup2(fd, 4); /* is it necessary? maybe fd == 4. */
! 23: return fd;
! 24: }
! 25:
! 26: int lf_oxc_open_main(char *cmd, short port)
! 27: {
! 28: int pid = 0;
! 29: if (cmd != NULL && (pid = fork()) == 0) {
! 30: oxf_connect_dup(remote_host, port);
! 31: fprintf(stderr, "oxc: oxc_open(%s, %d)\n", cmd, port);
! 32: execlp(cmd, cmd, NULL);
! 33: }
! 34: fprintf(stderr, "oxc: cannnot oxc_open(%s, %d).\n", cmd, port);
! 35: return pid; /* if error, pid == 0 */
! 36: }
! 37:
! 38: OXFILE *connection()
! 39: {
! 40: OXFILE *oxfp = oxf_connect_active(remote_host, port);
! 41: if (oxfp != NULL) {
! 42: oxf_confirm_server(oxfp, password);
! 43: oxf_determine_byteorder_server(oxfp);
! 44: }
! 45: return oxfp;
! 46: }
! 47:
! 48: int main(int argc, char *argv[])
! 49: {
! 50: OXFILE *oxfp;
! 51: int c;
! 52: while ((c = getopt(argc, argv, "c:p:h:")) != -1) {
! 53: switch(c) {
! 54: case 'h':
! 55: remote_host = optarg;
! 56: break;
! 57: case 'c':
! 58: password = optarg;
! 59: break;
! 60: case 'p':
! 61: port = atoi(optarg);
! 62: break;
! 63: default:
! 64: }
! 65: }
! 66: argc -= optind;
! 67: argv += optind;
! 68:
! 69: fprintf(stderr, "start connection!\n");
! 70: if (strlen(remote_host) == 0 || strlen(password) == 0 || port == 0) {
! 71: fprintf(stderr, "oxc: invalid arguments.\n");
! 72: fprintf(stderr, "usage: oxc -p port -h host -c password.\n");
! 73: }else if ((oxfp = connection()) == NULL) {
! 74: fprintf(stderr, "oxc: cannot connect.\n");
! 75: }else {
! 76: fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd);
! 77: mathcap_sysinfo_set(20001006, "v2000.10.06", "oxc");
! 78: sm(oxfp);
! 79: }
! 80: return 0;
! 81: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>