http://www.azstarnet.com/~ymg/files/slsnif-0.4.0.tar.gz
[slsnif.git] / src / slsnif.h
1
2 /*  slsnif.h
3  *  Copyright (C) 2001 Yan "Warrior" Gurtovoy (ymg@azstarnet.com)
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <ctype.h>
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <errno.h>
26 #include <signal.h>
27 #include <wait.h>
28 #include <sys/stat.h>
29 #include <sys/types.h>
30 #ifdef HAVE_GETOPT_H
31 #include <getopt.h>
32 #endif
33 #ifdef HAVE_SYS_TIMEB_H
34 #include <sys/timeb.h>
35 #endif
36 #ifdef HAVE_TIME_H
37 #include <time.h>
38 #endif
39 #include "common.h"
40
41 #define OPTSTR      "bnhtp:l:s:" /* list of short options for getopt_long() */
42 #define PORT_OUT    "\nHost   --> "
43 #define PORT_IN     "\nDevice --> "
44 #define DEFPTRNAME  "/dev/pty??"
45 #define TOTALBYTES  "Total bytes transmitted:"
46 #define MEMFAIL     "Memory allocation failed"
47 #define PTYFAIL     "Failed to open a pty"
48 #define PORTFAIL    "Failed to open port"
49 #define LOGFAIL     "Failed to open log file, defaulting to stdout"
50 #define SELFAIL     "`Select` failed"
51 #define RPORTFAIL   "Error reading from port"
52 #define RPTYFAIL    "Error reading from pty"
53 #define CLOSEFAIL   "Failed to close file - data loss may occur"
54 #define RAWFAIL     "Failed to switch into raw mode"
55 #define SYNCFAIL    "Failed to syncronize ttys"
56 #define PIPEFAIL    "Failed to create pipe"
57 #define FORKFAIL    "Failed to create child process"
58 #define RPIPEFAIL   "Error reading from pipe"
59
60 #define max(x,y)        ((x) > (y) ? (x) : (y))
61
62 #define BUFFSIZE    32
63 #define PRFXSIZE    12
64 #define DEFBAUDRATE B9600
65 #define WHITE       7
66 #define PORTNAMELEN 11
67
68 static tty_struct   tty_data;
69 static pid_t        pid = -1;
70
71 /* baudrates */
72 typedef struct _spd_struct {
73     speed_t speed;
74     char    *spdstr;
75 } spd_struct;
76
77 static spd_struct baudrates[] = {
78     {B50,         "50"}, {B75,         "75"}, {B110,         "110"},
79     {B134,       "134"}, {B150,       "150"}, {B200,         "200"},
80     {B300,       "300"}, {B600,       "600"}, {B1200,       "1200"},
81     {B1800,     "1800"}, {B2400,     "2400"}, {B4800,       "4800"},
82     {B9600,     "9600"}, {B19200,   "19200"}, {B38400,     "38400"},
83     {B57600,   "57600"}, {B115200, "115200"}, {0,             NULL}
84 };
85
86 static clr_struct colors[] = {
87     {"black",         "\033[0;30m"},
88     {"red",           "\033[0;31m"},
89     {"green",         "\033[0;32m"},
90     {"yellow",        "\033[0;33m"},
91     {"blue",          "\033[0;34m"},
92     {"magenta",       "\033[0;35m"},
93     {"cyan",          "\033[0;36m"},
94     {"white",         "\033[0;37m"},
95     {"brightblack",   "\033[1;30m"},
96     {"brightred",     "\033[1;31m"},
97     {"brightgreen",   "\033[1;32m"},
98     {"brightyellow",  "\033[1;33m"},
99     {"brightblue",    "\033[1;34m"},
100     {"brightmagenta", "\033[1;35m"},
101     {"brightcyan",    "\033[1;36m"},
102     {"brightwhite",   "\033[1;37m"},
103     {NULL,            NULL        }
104 };
105
106 /* function prototypes */
107 pid_t dev_getlock(char *dev);
108 pid_t dev_setlock(char *dev);
109 int dev_unlock(char *dev);
110 void readRC(tty_struct *ptr);