main.c
author Lluís Batlle <viric@viric.name>
Thu, 20 Mar 2014 16:33:27 +0100
changeset 97 eea77d5a624c
parent 94 330324fc7c20
permissions -rw-r--r--
Merging the savefile branch. I hope it works; I even don't remember it.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
     1
/*
53
07500c5c53cb Adding license and web html.
viric@llimona
parents: 50
diff changeset
     2
    Terminal Mixer - multi-point multi-user access to terminal applications
12
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
     3
    Copyright (C) 2007  LluĂ­s Batlle i Rossell
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
     4
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
     5
    Please find the license in the provided COPYING file.
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
     6
*/
0
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
     7
#include <stdio.h>
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
     8
#include <stdlib.h>
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
     9
#include <sys/types.h>
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
    10
#include <unistd.h>
5
5ed1654fe407 Better client.
viric@llimona
parents: 3
diff changeset
    11
#include <errno.h>
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    12
#include <string.h>
23
b3e6c6ffc69c Moving the client out.
viric@llimona
parents: 21
diff changeset
    13
#include <sys/select.h>
0
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
    14
3
909bca647298 Renaming now correct.
viric@llimona
parents: 2
diff changeset
    15
#include "main.h"
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    16
#include "handlers.h"
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    17
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    18
extern char *optarg;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    19
extern int optind, opterr, optopt;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    20
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    21
/* From main.h given external */
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    22
int app_stdin;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    23
int app_stdout;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    24
int app_stderr;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    25
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
    26
struct Command_line command_line;
0
3bbacfe6797a Something bare.
viric@llimona
parents:
diff changeset
    27
90
f172b95795d8 Moving to version 0.4.1
viric@mandarina
parents: 88
diff changeset
    28
static const char version[] = "0.4.1";
12
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
    29
6
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    30
static int showhelp(const char *pname)
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    31
{
31
c8d6b46dae2e Changing 'st' Swiss Terminal, to 'tm', terminal mixer
lbatlle@npdl268.bpo.hp.com
parents: 29
diff changeset
    32
    printf("tm v%s - terminal mixer,  Copyright (C) 2007  "
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    33
            "Lluis Batlle i Rossell\n",
12
6a372f8b4b8a Ignore, license and version.
viric@llimona
parents: 9
diff changeset
    34
            version);
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    35
    printf("usage: %s [opts] [appcommand] [param1] [param2] ...\n", pname);
6
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    36
    printf(" If you give _appcommand_, it starts the application and\n");
40
da3ea7f666e3 Fixed env vars and paths for the unix socket.
viric@llimona
parents: 38
diff changeset
    37
    printf(" serves it through a Unix socket on $TM_SOCKET or "
da3ea7f666e3 Fixed env vars and paths for the unix socket.
viric@llimona
parents: 38
diff changeset
    38
            "/tmp/tm-socket.UID,\n");
38
f1e581c862d5 Improved help. Moving to 0.2.
viric@llimona
parents: 37
diff changeset
    39
    printf(" unless '-p' is used.\n");
f1e581c862d5 Improved help. Moving to 0.2.
viric@llimona
parents: 37
diff changeset
    40
    printf(" Without _appcomand_, starts a the Unix socket client.\n");
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    41
    printf("options: \n");
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
    42
    printf(" -h     Show help.\n");
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
    43
    printf(" -P     Run the child as connected to a pipe (default).\n");
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    44
    printf(" -t     Run the child as connected to a terminal (raw mode in "
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
    45
        "client).\n");
41
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
    46
    printf(" -n     Unlink the program from the terminal (as 'nohup').\n");
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
    47
    printf(" -N MAX Serve at most MAX sockets for each transport (1 default)."
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
    48
            "\n");
32
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
    49
    printf(" -w     The remote clients can write to the application.\n");
50
2c88b9d375d7 Going to 0.3.
viric@llimona
parents: 49
diff changeset
    50
    printf(" -C     The remote clients end will close app's stdin.\n");
38
f1e581c862d5 Improved help. Moving to 0.2.
viric@llimona
parents: 37
diff changeset
    51
    printf(" -p NUM Listen to tcp port NUM for 'telnet', and not listen to "
f1e581c862d5 Improved help. Moving to 0.2.
viric@llimona
parents: 37
diff changeset
    52
            "any\n"
f1e581c862d5 Improved help. Moving to 0.2.
viric@llimona
parents: 37
diff changeset
    53
           "        Unix socket.\n");
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
    54
    printf(" -E     Echo remote input to the server terminal.\n");
49
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
    55
#ifdef linux
88
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    56
    printf(" -e dev[:port] Also serve/connect using raw ethernet, device 'dev'.\n");
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
    57
    printf(" -c adr Connect to address (MAC if eth).\n");
94
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
    58
    printf(" -s fil Save the child stdin/stdout to the filename 'fil'.\n");
49
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
    59
#endif /* linux */
50
2c88b9d375d7 Going to 0.3.
viric@llimona
parents: 49
diff changeset
    60
    printf(" -x     Send xterm's resize control string to clients.\n");
6
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    61
    return 0;
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    62
}
4fe857c0b12a Help message.
viric@llimona
parents: 5
diff changeset
    63
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    64
static int my_getopt(int argc, char * argv[], const char *optstring)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    65
{
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    66
    char *old_getopt_env;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    67
    static char getopt_env[100] = "POSIXLY_CORRECT=YES";
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    68
    int res;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    69
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    70
    old_getopt_env = getenv("POSIXLY_CORRECT");
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    71
    putenv(getopt_env);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    72
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    73
    res = getopt(argc, argv, optstring);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    74
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    75
    if (old_getopt_env == 0)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    76
    {
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    77
        putenv("POSIXLY_CORRECT");
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    78
    }
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    79
    else
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    80
        snprintf(getopt_env, sizeof getopt_env, "POSIXLY_CORRECT=%s",
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    81
                old_getopt_env);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    82
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    83
    return res;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    84
}
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
    85
88
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    86
static void parse_eth_device(char *str)
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    87
{
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    88
    char *p;
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    89
    for (p = str; *p != 0 && *p != ':'; ++p);
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    90
    if (*p == ':')
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    91
    {
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    92
        *p = '\0'; /* We want only the eth device name in str */
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    93
        ++p;
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    94
        command_line.eth_port = atoi(p);
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    95
    }
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    96
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    97
    /* The string will not have any colon or port. */
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    98
    command_line.eth_device = strdup(str);
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
    99
}
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
   100
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   101
static void default_command_line()
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   102
{
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   103
    command_line.is_server = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   104
    command_line.s_param.use_blocking_sockets = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   105
    command_line.s_param.run_in_subterminal = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   106
    command_line.s_param.max_served = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   107
    command_line.s_param.serve_unix = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   108
    command_line.s_param.serve_tcp = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   109
    command_line.s_param.send_xterm_resize = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   110
    command_line.s_param.client_may_close_app_stdin = 0;
41
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
   111
    command_line.s_param.nohup = 0;
32
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   112
    command_line.s_param.client_can_write = 0;
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
   113
    command_line.s_param.echo_in_local_terminal = 0;
37
b0588bddef91 Option for xterm resizing. Over max connections, close() at once.
viric@llimona
parents: 36
diff changeset
   114
    command_line.s_param.send_xterm_resize = 0;
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   115
    command_line.s_param.serve_eth = 0;
94
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
   116
    command_line.s_param.savefile = 0;
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   117
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   118
    command_line.tcp_port = 40000; /* Arbitrary */
88
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
   119
    command_line.eth_port = 100;   /* Arbitrary */
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   120
    command_line.buffer_size = 4096; /* Arbitrary */
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   121
    command_line.eth_device = 0;
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   122
    get_unix_path(); /* for command_line.unix_path */
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   123
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   124
    command_line.c_param.transport = UNIX;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   125
    command_line.c_param.wait_until_char = -1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   126
    command_line.c_param.raw_mode = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   127
    command_line.c_param.server_address = 0; /* TODO: free it */
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   128
}
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   129
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   130
static int parse_opts(int argc, char * argv[])
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   131
{
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   132
    int c;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   133
    extern char *optarg;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   134
    extern int optind, opterr, optopt;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   135
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   136
    while(1) {
94
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
   137
        c = my_getopt(argc, argv, "s:tp:nBxdPN:hwCED"
49
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
   138
#ifdef linux
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
   139
                "c:e:"
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
   140
#endif /* linux */
1cead94cfd99 Fixing a few bugs. The program runs well in Linux and Mac OS X.
viric@llimona
parents: 43
diff changeset
   141
                );
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   142
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   143
        if (c == -1)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   144
            break;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   145
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   146
        switch(c)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   147
        {
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   148
            case 't':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   149
                command_line.s_param.run_in_subterminal = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   150
                command_line.c_param.raw_mode = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   151
                break;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   152
            case 'P':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   153
                command_line.s_param.run_in_subterminal = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   154
                break;
41
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
   155
            case 'B':
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   156
                command_line.s_param.use_blocking_sockets = 0;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   157
                break;
41
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
   158
            case 'n':
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
   159
                command_line.s_param.nohup = 1;
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   160
                break;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   161
            case 'p':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   162
                command_line.tcp_port = atoi(optarg);
33
010af11f521e Raw implementation for tcp.
lbatlle@npdl268.bpo.hp.com
parents: 32
diff changeset
   163
                command_line.s_param.serve_tcp = 1;
010af11f521e Raw implementation for tcp.
lbatlle@npdl268.bpo.hp.com
parents: 32
diff changeset
   164
                command_line.s_param.serve_unix = 0;
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   165
                break;
41
954941c6e40a Added 'nohup' option -n.
viric@llimona
parents: 40
diff changeset
   166
            case 'N':
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   167
                command_line.s_param.max_served = atoi(optarg);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   168
                break;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   169
            case 'c':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   170
                command_line.c_param.server_address = strdup(optarg);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   171
                break;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   172
            case 'h':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   173
                showhelp(argv[0]);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   174
                exit(0);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   175
                break;
32
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   176
            case 'w':
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   177
                command_line.s_param.client_can_write = 1;
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   178
                break;
50
2c88b9d375d7 Going to 0.3.
viric@llimona
parents: 49
diff changeset
   179
            case 'C':
32
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   180
                command_line.s_param.client_may_close_app_stdin = 1;
df110f784648 Added read-only clients, added stdin-close option to clients.
lbatlle@npdl268.bpo.hp.com
parents: 31
diff changeset
   181
                break;
50
2c88b9d375d7 Going to 0.3.
viric@llimona
parents: 49
diff changeset
   182
            case 'x':
37
b0588bddef91 Option for xterm resizing. Over max connections, close() at once.
viric@llimona
parents: 36
diff changeset
   183
                command_line.s_param.send_xterm_resize = 1;
b0588bddef91 Option for xterm resizing. Over max connections, close() at once.
viric@llimona
parents: 36
diff changeset
   184
                break;
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   185
            case 'E':
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   186
                command_line.s_param.echo_in_local_terminal = 1;
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   187
                break;
75
525a97517dc7 command line dump setting -D
viric@llimona
parents: 53
diff changeset
   188
            case 'D':
525a97517dc7 command line dump setting -D
viric@llimona
parents: 53
diff changeset
   189
                should_dump = 1;
525a97517dc7 command line dump setting -D
viric@llimona
parents: 53
diff changeset
   190
                break;
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
   191
            case 'e':
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   192
                command_line.s_param.serve_eth = 1;
87
be4ee314545c Making client and server use different ethernet protocols
viric@llimona
parents: 84
diff changeset
   193
                command_line.s_param.serve_unix = 0;
88
a7f546938313 Adding port number on the ethernet protocol.
viric@llimona
parents: 87
diff changeset
   194
                parse_eth_device(optarg);
43
625794738afc Added first attempt for an ethernet protocol. Even not tried.
viric@llimona
parents: 41
diff changeset
   195
                command_line.c_param.transport = ETHERNET;
36
da427c23d755 Added dumps, telnet_filter, applied filters in tm, improved telnet experience.
viric@llimona
parents: 34
diff changeset
   196
                break;
94
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
   197
            case 's':
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
   198
                command_line.s_param.savefile = strdup(optarg);
330324fc7c20 Adding a feature: save all stdin/stdout traffic of the server into a file.
viric <viriketo@gmail.com>
parents: 90
diff changeset
   199
                break;
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   200
            case '?':
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   201
                error("Wrong option %c.\n", optopt);
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   202
        }
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   203
    }
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   204
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   205
    if (command_line.s_param.use_blocking_sockets == 0)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   206
        not_implemented("Not using blocking sockets.");
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   207
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   208
    if (optind < argc)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   209
    {
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   210
        command_line.is_server = 1;
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   211
        command_line.s_param.command = &argv[optind];
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   212
    }
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   213
    return 0;
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   214
}
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   215
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   216
int main(int argc, char * argv[])
1
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   217
{
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   218
    int res;
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   219
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   220
    default_command_line();
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   221
    parse_opts(argc, argv);
34
7486e269b794 Added filter engine, xterm resize.
viric@mandarina
parents: 33
diff changeset
   222
    init_stream_buffers();
21
a82c88322eb5 Big change, from stdinmix to multiterminal.
viric@llimona
parents: 15
diff changeset
   223
29
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   224
    if (command_line.is_server)
91286c3ecebc Added getopt, and some things got based on parameters.
viric@llimona
parents: 23
diff changeset
   225
        res = server();
1
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   226
    else
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   227
        res = client();
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   228
    return res;
473a340551e3 Basic functionality.
viric@llimona
parents: 0
diff changeset
   229
}