main.c
changeset 88 a7f546938313
parent 87 be4ee314545c
child 90 f172b95795d8
equal deleted inserted replaced
87:be4ee314545c 88:a7f546938313
    23 int app_stdout;
    23 int app_stdout;
    24 int app_stderr;
    24 int app_stderr;
    25 
    25 
    26 struct Command_line command_line;
    26 struct Command_line command_line;
    27 
    27 
    28 static const char version[] = "0.4.1";
    28 static const char version[] = "0.5";
    29 
    29 
    30 static int showhelp(const char *pname)
    30 static int showhelp(const char *pname)
    31 {
    31 {
    32     printf("tm v%s - terminal mixer,  Copyright (C) 2007  "
    32     printf("tm v%s - terminal mixer,  Copyright (C) 2007  "
    33             "Lluis Batlle i Rossell\n",
    33             "Lluis Batlle i Rossell\n",
    51     printf(" -p NUM Listen to tcp port NUM for 'telnet', and not listen to "
    51     printf(" -p NUM Listen to tcp port NUM for 'telnet', and not listen to "
    52             "any\n"
    52             "any\n"
    53            "        Unix socket.\n");
    53            "        Unix socket.\n");
    54     printf(" -E     Echo remote input to the server terminal.\n");
    54     printf(" -E     Echo remote input to the server terminal.\n");
    55 #ifdef linux
    55 #ifdef linux
    56     printf(" -e dev Also serve/connect using raw ethernet, device 'dev'.\n");
    56     printf(" -e dev[:port] Also serve/connect using raw ethernet, device 'dev'.\n");
    57     printf(" -c adr Connect to address (MAC if eth).\n");
    57     printf(" -c adr Connect to address (MAC if eth).\n");
    58 #endif /* linux */
    58 #endif /* linux */
    59     printf(" -x     Send xterm's resize control string to clients.\n");
    59     printf(" -x     Send xterm's resize control string to clients.\n");
    60     return 0;
    60     return 0;
    61 }
    61 }
    78     else
    78     else
    79         snprintf(getopt_env, sizeof getopt_env, "POSIXLY_CORRECT=%s",
    79         snprintf(getopt_env, sizeof getopt_env, "POSIXLY_CORRECT=%s",
    80                 old_getopt_env);
    80                 old_getopt_env);
    81 
    81 
    82     return res;
    82     return res;
       
    83 }
       
    84 
       
    85 static void parse_eth_device(char *str)
       
    86 {
       
    87     char *p;
       
    88     for (p = str; *p != 0 && *p != ':'; ++p);
       
    89     if (*p == ':')
       
    90     {
       
    91         *p = '\0'; /* We want only the eth device name in str */
       
    92         ++p;
       
    93         command_line.eth_port = atoi(p);
       
    94     }
       
    95 
       
    96     /* The string will not have any colon or port. */
       
    97     command_line.eth_device = strdup(str);
    83 }
    98 }
    84 
    99 
    85 static void default_command_line()
   100 static void default_command_line()
    86 {
   101 {
    87     command_line.is_server = 0;
   102     command_line.is_server = 0;
    97     command_line.s_param.echo_in_local_terminal = 0;
   112     command_line.s_param.echo_in_local_terminal = 0;
    98     command_line.s_param.send_xterm_resize = 0;
   113     command_line.s_param.send_xterm_resize = 0;
    99     command_line.s_param.serve_eth = 0;
   114     command_line.s_param.serve_eth = 0;
   100 
   115 
   101     command_line.tcp_port = 40000; /* Arbitrary */
   116     command_line.tcp_port = 40000; /* Arbitrary */
       
   117     command_line.eth_port = 100;   /* Arbitrary */
   102     command_line.buffer_size = 4096; /* Arbitrary */
   118     command_line.buffer_size = 4096; /* Arbitrary */
   103     command_line.eth_device = 0;
   119     command_line.eth_device = 0;
   104     get_unix_path(); /* for command_line.unix_path */
   120     get_unix_path(); /* for command_line.unix_path */
   105 
   121 
   106     command_line.c_param.transport = UNIX;
   122     command_line.c_param.transport = UNIX;
   171                 should_dump = 1;
   187                 should_dump = 1;
   172                 break;
   188                 break;
   173             case 'e':
   189             case 'e':
   174                 command_line.s_param.serve_eth = 1;
   190                 command_line.s_param.serve_eth = 1;
   175                 command_line.s_param.serve_unix = 0;
   191                 command_line.s_param.serve_unix = 0;
   176                 command_line.eth_device = strdup(optarg);
   192                 parse_eth_device(optarg);
   177                 command_line.c_param.transport = ETHERNET;
   193                 command_line.c_param.transport = ETHERNET;
   178                 break;
   194                 break;
   179             case '?':
   195             case '?':
   180                 error("Wrong option %c.\n", optopt);
   196                 error("Wrong option %c.\n", optopt);
   181         }
   197         }