diff options
author | Bjoern A. Zeeb <bz@FreeBSD.org> | 2008-05-26 10:40:09 +0000 |
---|---|---|
committer | Bjoern A. Zeeb <bz@FreeBSD.org> | 2008-05-26 10:40:09 +0000 |
commit | 2e598474fa6a089cf784ae7a0dfd29f0af0b1a50 (patch) | |
tree | ce6d26c22aa5ab44c23fab794efd22c6b5bc9c39 /usr.sbin/i4b/isdnmonitor | |
parent | 50715949692e09308fab9ba413a424e9aeb8d4f5 (diff) |
Remove ISDN4BSD (I4B) from HEAD as it is not MPSAFE and
parts relied on the now removed NET_NEEDS_GIANT.
Most of I4B has been disconnected from the build
since July 2007 in HEAD/RELENG_7.
This is what was removed:
- configuration in /etc/isdn
- examples
- man pages
- kernel configuration
- sys/i4b (drivers, layers, include files)
- user space tools
- i4b support from ppp
- further documentation
Discussed with: rwatson, re
Notes
Notes:
svn path=/head/; revision=179315
Diffstat (limited to 'usr.sbin/i4b/isdnmonitor')
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/Makefile | 17 | ||||
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/curses.c | 624 | ||||
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/isdnmonitor.8 | 178 | ||||
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/main.c | 1196 | ||||
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/monitor.h | 299 | ||||
-rw-r--r-- | usr.sbin/i4b/isdnmonitor/monprivate.h | 210 |
6 files changed, 0 insertions, 2524 deletions
diff --git a/usr.sbin/i4b/isdnmonitor/Makefile b/usr.sbin/i4b/isdnmonitor/Makefile deleted file mode 100644 index ed241c16afb4..000000000000 --- a/usr.sbin/i4b/isdnmonitor/Makefile +++ /dev/null @@ -1,17 +0,0 @@ -# $FreeBSD$ - -PROG= isdnmonitor -MAN= isdnmonitor.8 -SRCS= main.c curses.c - -# compile debug support -CFLAGS+= -DDEBUG - -# avoid wacky merging of string constants from -# source code with compile-time timestamp -CFLAGS+= -fno-merge-constants - -DPADD= ${LIBCURSES} -LDADD= -lcurses - -.include <bsd.prog.mk> diff --git a/usr.sbin/i4b/isdnmonitor/curses.c b/usr.sbin/i4b/isdnmonitor/curses.c deleted file mode 100644 index 1e7eec15b68d..000000000000 --- a/usr.sbin/i4b/isdnmonitor/curses.c +++ /dev/null @@ -1,624 +0,0 @@ -/* - * Copyright (c) 1999 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - *--------------------------------------------------------------------------- - * - * i4b daemon - curses fullscreen output - * ------------------------------------- - * - * $Id: curses.c,v 1.10 1999/12/13 21:25:25 hm Exp $ - * - * $FreeBSD$ - * - * last edit-date: [Mon Dec 13 21:51:47 1999] - * - *---------------------------------------------------------------------------*/ - -#include "monprivate.h" - -#ifndef WIN32 - -static void display_bell(void); -static void display_chans(void); - -/*---------------------------------------------------------------------------* - * program exit - *---------------------------------------------------------------------------*/ -void -do_exit(int exitval) -{ - if(curses_ready) - endwin(); - exit(exitval); -} - -/*---------------------------------------------------------------------------* - * init curses fullscreen display - *---------------------------------------------------------------------------*/ -void -init_screen(void) -{ - char buffer[512]; - int uheight, lheight; - int i, j; - - initscr(); /* curses init */ - - if((COLS < 80) || (LINES < 24)) - { - endwin(); - fprintf(stderr, "ERROR, minimal screensize must be 80x24, is %dx%d, terminating!",COLS, LINES); - exit(1); - } - - noecho(); - raw(); - - uheight = nctrl * 2; /* cards * b-channels */ - lheight = LINES - uheight - 6 + 1; /* rest of display */ - - if((upper_w = newwin(uheight, COLS, UPPER_B, 0)) == NULL) - { - endwin(); - fprintf(stderr, "ERROR, curses init upper window, terminating!"); - exit(1); - } - - if((mid_w = newwin(1, COLS, UPPER_B+uheight+1, 0)) == NULL) - { - endwin(); - fprintf(stderr, "ERROR, curses init mid window, terminating!"); - exit(1); - } - - if((lower_w = newwin(lheight, COLS, UPPER_B+uheight+3, 0)) == NULL) - { - endwin(); - fprintf(stderr, "ERROR, curses init lower window, LINES = %d, lheight = %d, uheight = %d, terminating!", LINES, lheight, uheight); - exit(1); - } - - scrollok(lower_w, 1); - - sprintf(buffer, "----- isdn controller channel state ------------- isdnmonitor %02d.%02d.%d -", VERSION, REL, STEP); - - while(strlen(buffer) < COLS) - strcat(buffer, "-"); - - move(0, 0); - standout(); - addstr(buffer); - standend(); - - move(1, 0); - /* 01234567890123456789012345678901234567890123456789012345678901234567890123456789 */ - addstr("c tei b remote iface dir outbytes obps inbytes ibps units"); - - if(hostname) - sprintf(buffer, "----- isdn userland interface state ------------- %s:%d -", hostname, portno); - else - sprintf(buffer, "----- isdn userland interface state ------------- %s -", sockpath); - - while(strlen(buffer) < COLS) - strcat(buffer, "-"); - - move(uheight+2, 0); - standout(); - addstr(buffer); - standend(); - - sprintf(buffer, "----- isdnd logfile display --------------------------------------------------"); - while(strlen(buffer) < COLS) - strcat(buffer, "-"); - - move(uheight+4, 0); - standout(); - addstr(buffer); - standend(); - - refresh(); - - for(i=0, j=0; i <= nctrl; i++, j+=2) - { - mvwprintw(upper_w, j, H_CNTL, "%d --- 1 ", i); /*TEI*/ - mvwprintw(upper_w, j+1, H_CNTL, " L12 2 "); - } - wrefresh(upper_w); - -#ifdef NOTDEF - for(i=0, j=0; i < nentries; i++) /* walk thru all entries */ - { - p = &cfg_entry_tab[i]; /* get ptr to enry */ - - mvwprintw(mid_w, 0, j, "%s%d ", bdrivername(p->usrdevicename), p->usrdeviceunit); - - p->fs_position = j; - - j += ((strlen(bdrivername(p->usrdevicename)) + (p->usrdeviceunit > 9 ? 2 : 1) + 1)); - } -#else - mvwprintw(mid_w, 0, 0, "%s", devbuf); -#endif - wrefresh(mid_w); - - wmove(lower_w, 0, 0); - wrefresh(lower_w); - - curses_ready = 1; -} - -/*---------------------------------------------------------------------------* - * display the charge in units - *---------------------------------------------------------------------------*/ -void -display_charge(int pos, int charge) -{ - mvwprintw(upper_w, pos, H_UNITS, "%d", charge); - wclrtoeol(upper_w); - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * display the calculated charge in units - *---------------------------------------------------------------------------*/ -void -display_ccharge(int pos, int units) -{ - mvwprintw(upper_w, pos, H_UNITS, "(%d)", units); - wclrtoeol(upper_w); - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * display accounting information - *---------------------------------------------------------------------------*/ -void -display_acct(int pos, int obyte, int obps, int ibyte, int ibps) -{ - mvwprintw(upper_w, pos, H_OUT, "%-10d", obyte); - mvwprintw(upper_w, pos, H_OUTBPS, "%-4d", obps); - mvwprintw(upper_w, pos, H_IN, "%-10d", ibyte); - mvwprintw(upper_w, pos, H_INBPS, "%-4d", ibps); - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * erase line at disconnect time - *---------------------------------------------------------------------------*/ -void -display_disconnect(int pos) -{ - wmove(upper_w, pos, H_TELN); - wclrtoeol(upper_w); - wrefresh(upper_w); - - if(do_bell) - display_bell(); -} - -/*---------------------------------------------------------------------------* - * display interface up/down information - *---------------------------------------------------------------------------*/ -void -display_updown(int pos, int updown, char *device) -{ - if(updown) - wstandend(mid_w); - else - wstandout(mid_w); - - mvwprintw(mid_w, 0, pos, "%s ", device); - - wstandend(mid_w); - wrefresh(mid_w); -} - -/*---------------------------------------------------------------------------* - * display interface up/down information - *---------------------------------------------------------------------------*/ -void -display_l12stat(int controller, int layer, int state) -{ - if(controller > nctrl) - return; - - if(!(layer == 1 || layer == 2)) - return; - - if(state) - wstandout(upper_w); - else - wstandend(upper_w); - - if(layer == 1) - { - mvwprintw(upper_w, (controller*2)+1, H_TEI+1, "1"); - - if(!state) - mvwprintw(upper_w, (controller*2)+1, H_TEI+2, "2"); - } - else if(layer == 2) - { - mvwprintw(upper_w, (controller*2)+1, H_TEI+2, "2"); - if(state) - mvwprintw(upper_w, (controller*2)+1, H_TEI+1, "1"); - } - - wstandend(upper_w); - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * display TEI - *---------------------------------------------------------------------------*/ -void -display_tei(int controller, int tei) -{ - if(controller > nctrl) - return; - - if(tei == -1) - mvwprintw(upper_w, controller*2, H_TEI, "---"); - else - mvwprintw(upper_w, controller*2, H_TEI, "%3d", tei); - - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * display bell :-) - *---------------------------------------------------------------------------*/ -static void -display_bell(void) -{ - static char bell[1] = { 0x07 }; - write(STDOUT_FILENO, &bell[0], 1); -} - -/*---------------------------------------------------------------------------* - * curses menu for fullscreen command mode - *---------------------------------------------------------------------------*/ -void -do_menu(void) -{ - static char *menu[WMITEMS] = - { - "1 - (D)isplay refresh", - "2 - (H)angup (choose a channel)", - "3 - (R)eread config file", - "4 - (Q)uit the program", - }; - - WINDOW *menu_w; - int c; - int mpos; - fd_set set; - struct timeval timeout; - - /* create a new window in the lower screen area */ - - if((menu_w = newwin(WMENU_HGT, WMENU_LEN, WMENU_POSLN, WMENU_POSCO )) == NULL) - { - return; - } - - /* create a border around the window */ - - box(menu_w, '|', '-'); - - /* add a title */ - - wstandout(menu_w); - mvwaddstr(menu_w, 0, (WMENU_LEN / 2) - (strlen(WMENU_TITLE) / 2), WMENU_TITLE); - wstandend(menu_w); - - /* fill the window with the menu options */ - - for(mpos=0; mpos <= (WMITEMS-1); mpos++) - mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]); - - /* highlight the first menu option */ - - mpos = 0; - wstandout(menu_w); - mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]); - wstandend(menu_w); - - /* input loop */ - - for(;;) - { - wrefresh(menu_w); - - FD_ZERO(&set); - FD_SET(STDIN_FILENO, &set); - timeout.tv_sec = WMTIMEOUT; - timeout.tv_usec = 0; - - /* if no char is available within timeout, exit menu*/ - - if((select(STDIN_FILENO + 1, &set, NULL, NULL, &timeout)) <= 0) - goto mexit; - - c = wgetch(menu_w); - - switch(c) - { - case ' ': - case '\t': /* hilite next option */ - mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]); - mpos++; - if(mpos >= WMITEMS) - mpos = 0; - wstandout(menu_w); - mvwaddstr(menu_w, mpos + 2, 2, menu[mpos]); - wstandend(menu_w); - break; - - case ('0'+WREFRESH+1): /* display refresh */ - case 'D': - case 'd': - wrefresh(curscr); - goto mexit; - - case ('0'+WQUIT+1): /* quit program */ - case 'Q': - case 'q': - do_exit(0); - goto mexit; - - - case ('0'+WHANGUP+1): /* hangup connection */ - case 'H': - case 'h': - display_chans(); - goto mexit; - - case ('0'+WREREAD+1): /* reread config file */ - case 'R': - case 'r': - reread(); - goto mexit; - - case '\n': - case '\r': /* exec highlighted option */ - switch(mpos) - { - case WREFRESH: - wrefresh(curscr); - break; - - case WQUIT: - do_exit(0); - break; - - case WHANGUP: - display_chans(); - break; - - case WREREAD: - reread(); - break; - } - goto mexit; - break; - - default: - goto mexit; - break; - } - } - -mexit: - /* delete the menu window */ - - delwin(menu_w); - - /* re-display the original lower window contents */ - - touchwin(lower_w); - wrefresh(lower_w); -} - -/*---------------------------------------------------------------------------* - * display connect information - *---------------------------------------------------------------------------*/ -void -display_connect(int pos, int dir, char *name, char *remtel, char *dev) -{ - char buffer[256]; - - /* remote telephone number */ - - sprintf(buffer, "%s/%s", name, remtel); - - buffer[H_IFN - H_TELN - 1] = '\0'; - - mvwprintw(upper_w, pos, H_TELN, "%s", buffer); - - /* interface */ - - mvwprintw(upper_w, pos, H_IFN, "%s ", dev); - - mvwprintw(upper_w, pos, H_IO, dir ? "out" : "in"); - - mvwprintw(upper_w, pos, H_OUT, "-"); - mvwprintw(upper_w, pos, H_OUTBPS, "-"); - mvwprintw(upper_w, pos, H_IN, "-"); - mvwprintw(upper_w, pos, H_INBPS, "-"); - - if(do_bell) - display_bell(); - - wrefresh(upper_w); -} - -/*---------------------------------------------------------------------------* - * display channel information for shutdown - *---------------------------------------------------------------------------*/ -static void -display_chans(void) -{ - char buffer[80]; - int i; - int cnt = 0; - WINDOW *chan_w; - int nlines, ncols, pos_x, pos_y; - fd_set set; - struct timeval timeout; - - /* need this later to close the connection */ - struct ctlr_chan { - int cntl; - int chn; - } *cc = NULL; - - for(i = 0; i < nctrl; i++) - { - if(remstate[i].ch1state) - cnt++; - if(remstate[i].ch2state) - cnt++; - } - - if(cnt > 0) - { - if ((cc = (struct ctlr_chan *)malloc (cnt * - sizeof (struct ctlr_chan))) == NULL) - { - return; - } - nlines = cnt + 4; - ncols = 60; - } - else - { - nlines = 5; - ncols = 22; - } - - pos_y = WMENU_POSLN + 4; - pos_x = WMENU_POSCO + 10; - - /* create a new window in the lower screen area */ - - if((chan_w = newwin(nlines, ncols, pos_y, pos_x )) == NULL) - { - if (cnt > 0) - free(cc); - return; - } - - /* create a border around the window */ - - box(chan_w, '|', '-'); - - /* add a title */ - - wstandout(chan_w); - mvwaddstr(chan_w, 0, (ncols / 2) - (strlen("Channels") / 2), "Channels"); - wstandend(chan_w); - - /* no active channels */ - if (cnt == 0) - { - mvwaddstr(chan_w, 2, 2, "No active channels"); - wrefresh(chan_w); - sleep(1); - - /* delete the channels window */ - - delwin(chan_w); - return; - } - - nlines = 2; - ncols = 1; - - for (i = 0; i < nctrl; i++) - { - if(remstate[i].ch1state) - { - sprintf(buffer, "%d - Controller %d channel %s", ncols, i, "B1"); - mvwaddstr(chan_w, nlines, 2, buffer); - cc[ncols - 1].cntl = i; - cc[ncols - 1].chn = CHAN_B1; - nlines++; - ncols++; - } - if(remstate[i].ch2state) - { - sprintf(buffer, "%d - Controller %d channel %s", ncols, i, "B2"); - mvwaddstr(chan_w, nlines, 2, buffer); - cc[ncols - 1].cntl = i; - cc[ncols - 1].chn = CHAN_B2; - nlines++; - ncols++; - } - } - - for(;;) - { - wrefresh(chan_w); - - FD_ZERO(&set); - FD_SET(STDIN_FILENO, &set); - timeout.tv_sec = WMTIMEOUT; - timeout.tv_usec = 0; - - /* if no char is available within timeout, exit menu*/ - - if((select(STDIN_FILENO + 1, &set, NULL, NULL, &timeout)) <= 0) - break; - - ncols = wgetch(chan_w); - - if (!(isdigit(ncols))) - { - display_bell(); - continue; - } - - nlines = ncols - '0'; - - if ((nlines == 0) || (nlines > cnt)) - { - display_bell(); - continue; - } - - hangup(cc[nlines-1].cntl, cc[nlines-1].chn); - break; - } - - free(cc); - - /* delete the channels window */ - - delwin(chan_w); -} - -#endif /* !WIN32*/ - -/* EOF */ diff --git a/usr.sbin/i4b/isdnmonitor/isdnmonitor.8 b/usr.sbin/i4b/isdnmonitor/isdnmonitor.8 deleted file mode 100644 index 46e1a377f92a..000000000000 --- a/usr.sbin/i4b/isdnmonitor/isdnmonitor.8 +++ /dev/null @@ -1,178 +0,0 @@ -.\" -.\" Copyright (c) 1999 Hellmuth Michaelis. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" $Id: isdnmonitor.8,v 1.8 1999/12/13 22:11:55 hm Exp $ -.\" -.\" $FreeBSD$ -.\" -.\" last edit-date: [Mon Dec 13 23:04:25 1999] -.\" -.Dd September 25, 1999 -.Dt ISDNMONITOR 8 -.Os -.Sh NAME -.Nm isdnmonitor -.Nd isdn4bsd / isdnd remote monitoring tool -.Sh SYNOPSIS -.Nm -.Op Fl c -.Op Fl d Ar debuglevel -.Op Fl f Ar filename -.Op Fl h Ar hostspec -.Op Fl l Ar pathname -.Op Fl p Ar portspec -.Sh DESCRIPTION -The -.Nm -utility is used to remotely monitor the operation of the isdn daemon, -.Xr isdnd 8 , -which manages all ISDN related connection and disconnection of ISDN -devices supported by the isdn4bsd package. -.Pp -The options are as follows: -.Bl -tag -width Ds -.It Fl c -Switch to (curses-) fullscreen mode of operation. -In this mode, -.Nm -behaves nearly exactly as -.Xr isdnd 8 -in fullscreen mode. -In fullscreen mode, entering the control character -.Em Control-L -causes the display to be refreshed and entering -.Em Carriage-Return -or -.Em Enter -will pop-up a command window. -Because -.Nm -will not listen to messages while the command window is active, -this command window will disappear automatically after 5 seconds without -any command key press. -.Pp -While the command window is active, -.Em Tab -or -.Em Space -advances to the next menu item. -To execute a command, press -.Em Return -or -.Em Enter -for the highlighted menu item, or enter the number corresponding to the -item to be executed or enter the capitalized character in the menu item -description. -.It Fl d -If debugging support is compiled into -.Nm -this option is used to specify the debugging level. -.\" The debugging level is the sum of the -.\" following values: -.\" .Pp -.\" .Bl -tag -width Ds -compact -offset indent -.\" .It Ar 0x001 -.\" general debugging. -.\" .It Ar 0x002 -.\" rates calculation. -.\" .It Ar 0x004 -.\" timing calculations. -.\" .It Ar 0x008 -.\" state transitions. -.\" .It Ar 0x010 -.\" retry handling. -.\" .It Ar 0x020 -.\" dialing. -.\" .It Ar 0x040 -.\" process handling. -.\" .It Ar 0x080 -.\" isdn4bsd kernel i/o calls. -.\" .It Ar 0x100 -.\" controller and channel busy/free messages. -.\" .It Ar 0x200 -.\" isdnmonitor.rc configuration file processing. -.\" .El -.\" .Pp -.\" The value can be specified in any number base supported by the -.\" .Xr sscanf 3 -.\" library routine. -.Pp -In addition, this option accepts also the character 'n' as an argument to -disable displaying debug messages on the full-screen display. -.Pp -.It Fl f -Specifying this option causes -.Nm -to write its normal output and - if enabled - debugging output to a file -which name is specified as the argument. -.It Fl l -is used to specify a Unix local domain socket name to be used for communication -between -.Xr isdnd 8 -and -.Nm . -.It Fl h -is used to specify a hostname or a dotted-quad IP address of a machine -where an -.Xr isdnd 8 -is running which should be monitored. -.It Fl p -This option may be used to specify a remote port number in conjunction -with the -.Fl h -option. -.El -.Sh ENVIRONMENT -The following environment variables affect the execution of -.Nm : -.Bl -tag -width Ds -.It Ev TERM -The terminal type when running in full-screen display mode. -See -.Xr environ 7 -for more information. -.El -.Sh EXIT STATUS -Exit status is 0 on success, 1 on error. -.Sh EXAMPLES -For a first try, the following command should be used to start -.Nm -to monitor a locally running isdnd: -.Bd -literal -offset indent -isdnmonitor -h localhost -.Ed -.Sh SEE ALSO -.Xr isdnd 8 -.Sh AUTHORS -.An -nosplit -The -.Nm -utility was written by -.An Martin Husemann -and -.An Hellmuth Michaelis Aq hm@kts.org . -This manual page was written by -.An Hellmuth Michaelis . -.Sh BUGS -Still one (or) more left. diff --git a/usr.sbin/i4b/isdnmonitor/main.c b/usr.sbin/i4b/isdnmonitor/main.c deleted file mode 100644 index 65ddb5b9c10e..000000000000 --- a/usr.sbin/i4b/isdnmonitor/main.c +++ /dev/null @@ -1,1196 +0,0 @@ -/* - * Copyright (c) 1998,1999 Martin Husemann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * 4. Altered versions must be plainly marked as such, and must not be - * misrepresented as being the original software and/or documentation. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - *--------------------------------------------------------------------------- - * - * i4b daemon - network monitor client - * ----------------------------------- - * - * $Id: main.c,v 1.35 2000/08/24 11:48:57 hm Exp $ - * - * $FreeBSD$ - * - * last edit-date: [Mon Dec 13 21:52:11 1999] - * - *---------------------------------------------------------------------------*/ - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <signal.h> -#include <time.h> -#include <errno.h> -#ifndef WIN32 -#include <unistd.h> -#include <netdb.h> -#endif -#include <sys/types.h> -#ifndef WIN32 -#include <sys/socket.h> -#include <sys/ioctl.h> -#include <sys/un.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#else -#include <stdarg.h> -#include <windows.h> -extern char *optarg; -int getopt(int nargc, char * const nargv[], const char *ostr); -#define close(f) closesocket(f) -#define sleep(s) Sleep(s*1000) -#define vsnprintf _vsnprintf -#define ssize_t long -#endif -#ifdef ERROR -#undef ERROR -#endif -#ifdef __FreeBSD__ -#include <osreldate.h> -#endif - -#define MAIN -#include "monprivate.h" -#undef MAIN - -#ifndef AF_LOCAL -#define AF_LOCAL AF_UNIX -#endif - -#ifdef DEBUG -#include <ctype.h> -#endif - -#include "monitor.h" - -/* - * Local function prototypes - */ -static int connect_local(char *sockpath); -static int connect_remote(char *host, int portno); -static void usage(); -static void mloop(); -static void handle_input(); -static void print_menu(); -static void print_logevent(time_t tstamp, int prio, char * what, char * msg); -static void print_charge(time_t tstamp, int controller, int channel, int units, int estimated); -static void print_connect(time_t tstamp, int dir, int controller, int channel, char * cfgname, char * devname, char * remphone, char * locphone); -static void print_disconnect(time_t tstamp, int controller, int channel); -static void print_updown(time_t tstamp, int contoller, int channel, int isup); -static void handle_event(u_int8_t *msg, int len); -#ifdef DEBUG -static void dump_event(u_int8_t *msg, int len, int readflag); -#endif - -static ssize_t sock_read(int fd, void *buf, size_t nbytes); -static ssize_t sock_write(int fd, void *buf, size_t nbytes); - -static void mprintf(char *fmt, ...); - -/* - * Global variables - */ -static int debug = 0; -#define DBG_DUMPALL 0x01 -#define DBG_PSEND 0x02 - -static int monsock = -1; -static int state = ST_INIT; -static int sub_state = 0; -static int sub_state_count = 0; - -static int isdn_major = 0; -static int isdn_minor = 0; -static u_int32_t rights = 0; - -static char *logfilename = NULL; -static FILE *lfp = NULL; - -/*--------------------------------------------------------------------------- - * Display usage and exit - *---------------------------------------------------------------------------*/ -static void -usage() -{ - fprintf(stderr, "\n"); - fprintf(stderr, "isdnmonitor - version %02d.%02d.%d, (protocol %02d.%02d)\n", VERSION, REL, STEP, MPROT_VERSION, MPROT_REL); -#ifdef FOREIGN - fprintf(stderr, " usage: isdnmonitor [-c] [-d val] [-f name] [-h host] [-p port]\n"); -#else - fprintf(stderr, " usage: isdnmonitor [-c] [-d val] [-f name] [-h host] [-l path] [-p port]\n"); -#endif - fprintf(stderr, " -c switch to curses fullscreen output\n"); - fprintf(stderr, " -d <val> debug flags (see source ...)\n"); - fprintf(stderr, " -dn no debug output on fullscreen display\n"); - fprintf(stderr, " -f <name> filename to log output to\n"); - fprintf(stderr, " -h <host> hostname/address to connect to\n"); -#ifndef FOREIGN - fprintf(stderr, " -l <path> pathname to local domain socket to connect to\n"); -#endif - fprintf(stderr, " -p <port> portnumber to use to connect to remote host\n"); - exit(1); -} - -/*--------------------------------------------------------------------------- - * Parse command line, startup monitor client - *---------------------------------------------------------------------------*/ -int main(int argc, char **argv) -{ - int i; - -#ifdef WIN32 - WSADATA wsCaps; - WSAStartup(MAKEWORD(2, 0), &wsCaps); -#endif - - portno = DEF_MONPORT; - devbuf[0] = '\0'; - -#ifndef FOREIGN - while((i = getopt(argc, argv, "cd:f:h:p:l:")) != -1) -#else - while((i = getopt(argc, argv, "cd:f:h:p:")) != -1) -#endif - { - switch(i) - { - case 'c': - fullscreen = 1; - break; - case 'd': - if(*optarg == 'n') - { - debug_noscreen = 1; - } - else - { - if((sscanf(optarg, "%i", &debug)) != 1) - usage(); - } - break; - case 'f': - logfilename = optarg; - break; - case 'h': - hostname = optarg; - break; -#ifndef FOREIGN - case 'l': - sockpath = optarg; - break; -#endif - case 'p': - if((sscanf(optarg, "%i", &portno)) != 1) - usage(); - break; - default: - usage(); - break; - } - } - -#ifndef FOREIGN - if(hostname && sockpath) - { - fprintf(stderr, "Error: can not use local socket path on remote machine\n" - "conflicting options -h and -l!\n"); - return 1; - } - - if(sockpath) - { - monsock = connect_local(sockpath); - } - else if(hostname) -#else - if(hostname) -#endif - - { - monsock = connect_remote(hostname, portno); - } - else - { - usage(); - } - - if(monsock == -1) - { - fprintf(stderr, "Could not connect to i4b isdn daemon.\n"); - return 1; - } - - if(logfilename != NULL) - { - if((lfp = fopen(logfilename, "w")) == NULL) - { - fprintf(stderr, "could not open logfile [%s], %s\n", logfilename, strerror(errno)); - exit(1); - } - } - -#ifndef WIN32 - signal(SIGPIPE, SIG_IGN); -#endif - - mloop(); - - close(monsock); - - return 0; -} - -/*--------------------------------------------------------------------------- - * Connect via tcp/ip. - * Return socket if successfull, -1 on error. - ---------------------------------------------------------------------------*/ -static int -connect_remote(char *host, int portno) -{ - struct sockaddr_in sa; - struct hostent *h; - int remotesockfd; - - h = gethostbyname(host); - - if(!h) - { - fprintf(stderr, "could not resolve hostname '%s'\n", host); - exit(1); - } - - remotesockfd = socket(AF_INET, SOCK_STREAM, 0); - - if(remotesockfd == -1) - { - fprintf(stderr, "could not create remote monitor socket: %s\n", strerror(errno)); - exit(1); - } - - memset(&sa, 0, sizeof(sa)); - -#ifdef BSD4_4 - sa.sin_len = sizeof(sa); -#endif - sa.sin_family = AF_INET; - sa.sin_port = htons(portno); - - memcpy(&sa.sin_addr.s_addr, h->h_addr_list[0], sizeof(sa.sin_addr.s_addr)); - - if(connect(remotesockfd, (struct sockaddr *)&sa, sizeof(sa)) == -1) - { - fprintf(stderr, "could not connect remote monitor: %s\n", strerror(errno)); - exit(1); - } - - return remotesockfd; -} - -#ifndef FOREIGN -/*--------------------------------------------------------------------------- - * Connect local. - * Return socket on success, -1 on failure. - *---------------------------------------------------------------------------*/ -static int -connect_local(char *sockpath) -{ - int s; - struct sockaddr_un sa; - - /* check path length */ - if(strlen(sockpath) >= sizeof(sa.sun_path)) - { - fprintf(stderr, "pathname to long for local socket: %s\n", - sockpath); - exit(1); - } - - /* create and setup socket */ - s = socket(AF_LOCAL, SOCK_STREAM, 0); - - if(s == -1) - { - fprintf(stderr, "could not create local monitor socket:%s\n", strerror(errno)); - exit(1); - } - - memset(&sa, 0, sizeof(sa)); - - sa.sun_len = sizeof(sa); - sa.sun_family = AF_LOCAL; - strcpy(sa.sun_path, sockpath); - - if(connect(s, (struct sockaddr *)&sa, sizeof(sa))) - { - fprintf(stderr, "could not connect local monitor socket [%s]: %s\n", sockpath, strerror(errno)); - } - - return s; -} -#endif - -/*---------------------------------------------------------------------------* - * data from keyboard available, read and process it - *---------------------------------------------------------------------------*/ -#ifndef WIN32 -static void -kbdrdhdl(void) -{ - int ch = getch(); - - switch(ch) - { - case 0x0c: /* control L */ - wrefresh(curscr); - break; - - case '\n': - case '\r': - do_menu(); - break; - } -} -#endif - -/*--------------------------------------------------------------------------- - * main event loop - *---------------------------------------------------------------------------*/ -static void -mloop() -{ - for(;;) - { - fd_set rd, wr, ex; - - FD_ZERO(&rd); - FD_ZERO(&wr); - FD_ZERO(&ex); - FD_SET(fileno(stdin), &rd); - FD_SET(monsock, &rd); - - select(monsock+1, &rd, &wr, &ex, NULL); - - if(FD_ISSET(fileno(stdin), &rd)) - { -#ifndef WIN32 - if(fullscreen && curses_ready) - kbdrdhdl(); - else -#endif - if(!fullscreen) - handle_input(); - else - getchar(); - } - - if(FD_ISSET(monsock, &rd)) - { - u_int8_t buf[8192]; - int bytes, ret; - - /* Network transfer may deliver two or more packets concatenated. - * Peek at the header and read only one event at a time... */ - - bytes = recv(monsock, buf, I4B_MON_EVNT_HDR, MSG_PEEK); - - if(bytes == 0) - { - close(monsock); - -#ifndef WIN32 - if(curses_ready) - { - endwin(); - curses_ready = 0; - } -#endif - - mprintf("remote isdnd has closed our connection\n"); - exit(0); - } - else if(bytes < 0) - { - fprintf(stderr, "recv error: %s\n", strerror(errno)); - close(monsock); - exit(1); - } - - if (bytes < I4B_MON_EVNT_HDR) - continue; /* errh? something must be wrong... */ - - bytes = I4B_GET_2B(buf, I4B_MON_EVNT_LEN); - - if(bytes >= sizeof(buf)) - { - fprintf(stderr, "mloop: socket recv buffer overflow %d!\n", bytes); - break; - } - - /* now we know the size, it fits, so lets read it! */ - - ret = sock_read(monsock, buf, bytes); - - if(ret == 0) - { - close(monsock); -#ifndef WIN32 - if(curses_ready) - endwin(); -#endif - mprintf("remote isdnd has closed our connection\n"); - exit(0); - } - else if(ret < 0) - { - mprintf("error reading from isdnd: %s", strerror(errno)); - break; - } -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(buf, ret, 1); -#endif - handle_event(buf, ret); - } - } -} - -#ifdef DEBUG -/* - * Dump a complete event packet. - */ -static void dump_event(u_int8_t *msg, int len, int read) -{ - int i; - - if(read) - mprintf("read from socket:"); - else - mprintf("write to socket:"); - - for(i = 0; i < len; i++) - { - if(i % 8 == 0) - mprintf("\n%02d: ", i); - mprintf("0x%02x %c ", msg[i], isprint(msg[i]) ? msg[i] : '.'); - } - mprintf("\n"); -} -#endif - -static void -print_logevent(time_t tstamp, int prio, char * what, char * msg) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - mprintf("log: %s prio %d what=%s msg=%s\n", buf, prio, what, msg); - -#ifndef WIN32 - if(fullscreen) - { - if((!debug_noscreen) || (debug_noscreen && (((strcmp(what, "DBG"))) != 0))) - { -/* - * FreeBSD-current integrated ncurses. Since then it is no longer possible - * to write to the last column in the logfilewindow without causing an - * automatic newline to occur resulting in a blank line in that window. - */ -#if defined(__FreeBSD_version) && __FreeBSD_version >= 400009 -#warning "FreeBSD ncurses is buggy: write to last column = auto newline!" - wprintw(lower_w, "%s %s %-.*s\n", buf, what, - COLS-((strlen(buf))+(strlen(what))+3), msg); -#else - wprintw(lower_w, "%s %s %-.*s\n", buf, what, - (int)(COLS-((strlen(buf))+(strlen(what))+2)), msg); -#endif - wrefresh(lower_w); - } - } -#endif -} - -static void -print_charge(time_t tstamp, int controller, int channel, int units, int estimated) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - mprintf("%s: controller %d, channel %d, charge = %d%s\n", - buf, controller, channel, units, estimated ? " (estimated)" : ""); -#ifndef WIN32 - if(fullscreen) - { - if(estimated) - display_ccharge(CHPOS(controller, channel), units); - else - display_charge(CHPOS(controller, channel), units); - } -#endif -} - -/* - * Print a connect event. - * A real monitor would allocate state info for "channel" on this - * event. - */ -static void print_connect( - time_t tstamp, /* server time of event */ - int outgoing, /* 0 = incoming, 1 = outgoing */ - int controller, /* controller number */ - int channel, /* channel no, used to identify this connection until disconnect */ - char * cfgname, /* name of config entry/connection */ - char * devname, /* device used (e.g. isp0) */ - char * remphone, /* phone no of remote side */ - char * locphone) /* local phone no */ -{ - char buf[256]; - - if(channel == 0) - remstate[controller].ch1state = 1; - else - remstate[controller].ch2state = 1; - - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - - if(outgoing) - mprintf("%s: calling out to '%s' [from msn: '%s']", - buf, remphone, locphone); - else - mprintf("%s: incoming call from '%s' [to msn: '%s']", - buf, remphone, locphone); - mprintf(", controller %d, channel %d, config '%s' on device '%s'\n", - controller, channel, cfgname, devname); - -#ifndef WIN32 - if(fullscreen) - display_connect(CHPOS(controller, channel), outgoing, cfgname, remphone, devname); -#endif -} - -/* - * Print a disconnect event. - * A real monitor could free the "per connection" state - * for this channel now - */ -static void -print_disconnect(time_t tstamp, int controller, int channel) -{ - char buf[256]; - - if(channel == 0) - remstate[controller].ch1state = 0; - else - remstate[controller].ch2state = 0; - - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - - mprintf("%s: controller %d, channel %d disconnected\n", - buf, controller, channel); - -#ifndef WIN32 - if(fullscreen) - display_disconnect(CHPOS(controller, channel)); -#endif -} - -/* - * Print an up- or down event - */ -static void -print_updown(time_t tstamp, int controller, int channel, int isup) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - mprintf("%s: channel %d is %s\n", - buf, channel, isup ? "up" : "down"); -} - -/* - * Print l1 / l2 status - */ -static void -print_l12stat(time_t tstamp, int controller, int layer, int state) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - - mprintf("%s: layer %d change on controller %d: %s\n", - buf, layer, controller, state ? "up" : "down"); -#ifndef WIN32 - if(fullscreen) - display_l12stat(controller, layer, state); -#endif -} - -/* - * Print TEI - */ -static void -print_tei(time_t tstamp, int controller, int tei) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - - mprintf("%s: controller %d, TEI is %d\n", - buf, controller, tei); - -#ifndef WIN32 - if(fullscreen) - display_tei(controller, tei); -#endif -} - -/* - * Print accounting information - */ -static void -print_acct(time_t tstamp, int controller, int channel, int obytes, int obps, - int ibytes, int ibps) -{ - char buf[256]; - strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp)); - - mprintf("%s: controller %d, channel %d: %d obytes, %d obps, %d ibytes, %d ibps\n", - buf, controller, channel, obytes, obps, ibytes, ibps); -#ifndef WIN32 - if(fullscreen) - display_acct(CHPOS(controller, channel), obytes, obps, ibytes, ibps); -#endif -} - -static void -print_initialization(void) -{ -#ifndef WIN32 - if(fullscreen) - { - if(curses_ready == 0) - init_screen(); - } - else -#endif - { - print_menu(); - } -} - -/* - * Dispatch one message received from the daemon. - */ -static void -handle_event(u_int8_t *msg, int len) -{ - u_int8_t cmd[I4B_MON_ICLIENT_SIZE]; - int local; - u_int32_t net; - u_int32_t mask; - u_int32_t who; - static int first = 1; - - switch(state) - { - case ST_INIT: /* initial data */ - - isdn_major = I4B_GET_2B(msg, I4B_MON_IDATA_VERSMAJOR); - isdn_minor = I4B_GET_2B(msg, I4B_MON_IDATA_VERSMINOR); - nctrl = I4B_GET_2B(msg, I4B_MON_IDATA_NUMCTRL); - nentries = I4B_GET_2B(msg, I4B_MON_IDATA_NUMENTR); - rights = I4B_GET_4B(msg, I4B_MON_IDATA_CLACCESS); - - mprintf("remote protocol version is %02d.%02d\n", isdn_major, isdn_minor); - - if(isdn_major != MPROT_VERSION || isdn_minor != MPROT_REL) - { - fprintf(stderr, "ERROR, remote protocol version mismatch:\n"); - fprintf(stderr, "\tremote major version is %02d, local major version is %02d\n", isdn_major, MPROT_VERSION); - fprintf(stderr, "\tremote minor version is %02d, local minor version is %02d\n", isdn_minor, MPROT_REL); - exit(1); - } - - mprintf("our rights = 0x%x\n", rights); - - sub_state = 0; - first = 1; - - if(nctrl > 0) - { - state = ST_ICTRL; - } - else if(nentries > 0) - { - state = ST_IDEV; - } - else - { - state = ST_ANYEV; - sleep(2); - print_initialization(); - } - - /* set maximum event mask */ - I4B_PREP_CMD(cmd, I4B_MON_CCMD_SETMASK); - I4B_PUT_2B(cmd, I4B_MON_ICLIENT_VERMAJOR, MPROT_VERSION); - I4B_PUT_2B(cmd, I4B_MON_ICLIENT_VERMINOR, MPROT_REL); - I4B_PUT_4B(cmd, I4B_MON_ICLIENT_EVENTS, ~0U); - -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, sizeof(cmd), 0); -#endif - - if((sock_write(monsock, cmd, sizeof(cmd))) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } - break; - - case ST_ICTRL: /* initial controller list */ - if(first) - { - first = 0; - mprintf("%d controller(s) found:\n", nctrl); - } - mprintf("\tcontroller %d: %s\n", sub_state++, msg+I4B_MON_ICTRL_NAME); - - if(sub_state >= nctrl) - { - sub_state = 0; - first = 1; - if(nentries > 0) - { - state = ST_IDEV; /* end of list reached */ - } - else - { - state = ST_ANYEV; - sleep(2); - print_initialization(); - } - } - break; - - case ST_IDEV: /* initial entry devicename list */ - if(first) - { - first = 0; - mprintf("%d entries found:\n", nentries); - } - - mprintf("\tentry %d: device %s\n", sub_state++, msg+I4B_MON_IDEV_NAME); - - strcat(devbuf, msg+I4B_MON_IDEV_NAME); - /* strcat(devbuf, " "); */ - - if(sub_state >= nentries) - { - first = 1; - state = ST_ANYEV; /* end of list reached */ - sub_state = 0; - sleep(2); - print_initialization(); - } - break; - - case ST_ANYEV: /* any event */ - switch(I4B_GET_2B(msg, I4B_MON_EVNT)) - { - case I4B_MON_DRINI_CODE: - state = ST_RIGHT; /* list of rights entries will follow */ - sub_state = 0; - sub_state_count = I4B_GET_2B(msg, I4B_MON_DRINI_COUNT); - mprintf("monitor rights:\n"); - break; - - case I4B_MON_DCINI_CODE: - state = ST_CONNS; - sub_state = 0; - sub_state_count = I4B_GET_2B(msg, I4B_MON_DCINI_COUNT); - mprintf("monitor connections:\n"); - break; - - case I4B_MON_LOGEVNT_CODE: - print_logevent(I4B_GET_4B(msg, I4B_MON_LOGEVNT_TSTAMP), - I4B_GET_4B(msg, I4B_MON_LOGEVNT_PRIO), - msg+I4B_MON_LOGEVNT_WHAT, - msg+I4B_MON_LOGEVNT_MSG); - break; - - case I4B_MON_CHRG_CODE: - print_charge(I4B_GET_4B(msg, I4B_MON_CHRG_TSTAMP), - I4B_GET_4B(msg, I4B_MON_CHRG_CTRL), - I4B_GET_4B(msg, I4B_MON_CHRG_CHANNEL), - I4B_GET_4B(msg, I4B_MON_CHRG_UNITS), - I4B_GET_4B(msg, I4B_MON_CHRG_ESTIMATED)); - break; - - case I4B_MON_CONNECT_CODE: - print_connect( - I4B_GET_4B(msg, I4B_MON_CONNECT_TSTAMP), - I4B_GET_4B(msg, I4B_MON_CONNECT_DIR), - I4B_GET_4B(msg, I4B_MON_CONNECT_CTRL), - I4B_GET_4B(msg, I4B_MON_CONNECT_CHANNEL), - msg+I4B_MON_CONNECT_CFGNAME, - msg+I4B_MON_CONNECT_DEVNAME, - msg+I4B_MON_CONNECT_REMPHONE, - msg+I4B_MON_CONNECT_LOCPHONE); - break; - - case I4B_MON_DISCONNECT_CODE: - print_disconnect( - I4B_GET_4B(msg, I4B_MON_DISCONNECT_TSTAMP), - I4B_GET_4B(msg, I4B_MON_DISCONNECT_CTRL), - I4B_GET_4B(msg, I4B_MON_DISCONNECT_CHANNEL)); - break; - - case I4B_MON_UPDOWN_CODE: - print_updown( - I4B_GET_4B(msg, I4B_MON_UPDOWN_TSTAMP), - I4B_GET_4B(msg, I4B_MON_UPDOWN_CTRL), - I4B_GET_4B(msg, I4B_MON_UPDOWN_CHANNEL), - I4B_GET_4B(msg, I4B_MON_UPDOWN_ISUP)); - break; - case I4B_MON_L12STAT_CODE: - print_l12stat( - I4B_GET_4B(msg, I4B_MON_L12STAT_TSTAMP), - I4B_GET_4B(msg, I4B_MON_L12STAT_CTRL), - I4B_GET_4B(msg, I4B_MON_L12STAT_LAYER), - I4B_GET_4B(msg, I4B_MON_L12STAT_STATE)); - break; - case I4B_MON_TEI_CODE: - print_tei( - I4B_GET_4B(msg, I4B_MON_TEI_TSTAMP), - I4B_GET_4B(msg, I4B_MON_TEI_CTRL), - I4B_GET_4B(msg, I4B_MON_TEI_TEI)); - break; - case I4B_MON_ACCT_CODE: - print_acct( - I4B_GET_4B(msg, I4B_MON_ACCT_TSTAMP), - I4B_GET_4B(msg, I4B_MON_ACCT_CTRL), - I4B_GET_4B(msg, I4B_MON_ACCT_CHAN), - I4B_GET_4B(msg, I4B_MON_ACCT_OBYTES), - I4B_GET_4B(msg, I4B_MON_ACCT_OBPS), - I4B_GET_4B(msg, I4B_MON_ACCT_IBYTES), - I4B_GET_4B(msg, I4B_MON_ACCT_IBPS)); - break; - default: - mprintf("unknown event code: %d\n", I4B_GET_2B(msg, I4B_MON_EVNT)); - } - break; - - case ST_RIGHT: /* one record in a list of monitor rights */ - rights = I4B_GET_4B(msg, I4B_MON_DR_RIGHTS); - net = I4B_GET_4B(msg, I4B_MON_DR_NET); - mask = I4B_GET_4B(msg, I4B_MON_DR_MASK); - local = I4B_GET_1B(msg, I4B_MON_DR_LOCAL); - - if(local) - { - mprintf("\tlocal: rights = %x\n", rights); - } - else - { - mprintf("\tfrom: %d.%d.%d.%d, mask %d.%d.%d.%d, rights = %x\n", - (net >> 24) & 0x00ff, (net >> 16) & 0x00ff, (net >> 8) & 0x00ff, net & 0x00ff, - (mask >> 24) & 0x00ff, (mask >> 16) & 0x00ff, (mask >> 8) & 0x00ff, mask & 0x00ff, - rights); - } - - sub_state++; - - if(sub_state >= sub_state_count) - { - state = ST_ANYEV; - print_initialization(); - } - break; - - case ST_CONNS: - who = I4B_GET_4B(msg, I4B_MON_DC_WHO); - rights = I4B_GET_4B(msg, I4B_MON_DC_RIGHTS); - - mprintf("\tfrom: %d.%d.%d.%d, rights = %x\n", - (who >> 24) & 0x00ff, (who >> 16) & 0x00ff, (who >> 8) & 0x00ff, who & 0x00ff, - rights); - - sub_state++; - - if(sub_state >= sub_state_count) - { - state = ST_ANYEV; - print_initialization(); - } - break; - - default: - mprintf("unknown event from remote: local state = %d, evnt = %x, len = %d\n", - state, I4B_GET_2B(msg, I4B_MON_EVNT), len); - } -} - -/* - * Process input from user - */ -static void -handle_input() -{ - char buf[1024]; - int channel, controller; - - fgets(buf, sizeof(buf), stdin); - - switch(atoi(buf)) - { - case 1: - { - u_int8_t cmd[I4B_MON_DUMPRIGHTS_SIZE]; - I4B_PREP_CMD(cmd, I4B_MON_DUMPRIGHTS_CODE); -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_DUMPRIGHTS_SIZE, 0); -#endif - - if((sock_write(monsock, cmd, I4B_MON_DUMPRIGHTS_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } - } - break; - - case 2: - { - u_int8_t cmd[I4B_MON_DUMPMCONS_SIZE]; - I4B_PREP_CMD(cmd, I4B_MON_DUMPMCONS_CODE); -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_DUMPMCONS_CODE, 0); -#endif - - if((sock_write(monsock, cmd, I4B_MON_DUMPMCONS_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } - } - break; - - case 3: - { - u_int8_t cmd[I4B_MON_CFGREREAD_SIZE]; - I4B_PREP_CMD(cmd, I4B_MON_CFGREREAD_CODE); -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_CFGREREAD_CODE, 0); -#endif - - if((sock_write(monsock, cmd, I4B_MON_CFGREREAD_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } - } - break; - - case 4: - { - u_int8_t cmd[I4B_MON_HANGUP_SIZE]; - I4B_PREP_CMD(cmd, I4B_MON_HANGUP_CODE); - - printf("Which controller you wish to hangup? "); - fgets(buf, sizeof(buf), stdin); - controller = atoi(buf); - I4B_PUT_4B(cmd, I4B_MON_HANGUP_CTRL, controller); - - printf("Which channel do you wish to hangup? "); - fgets(buf, sizeof(buf), stdin); - channel = atoi(buf); - I4B_PUT_4B(cmd, I4B_MON_HANGUP_CHANNEL, channel); - -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_HANGUP_CHANNEL, 0); -#endif - - if((sock_write(monsock, cmd, I4B_MON_HANGUP_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } - } - break; - - case 9: - close(monsock); - exit(0); - break; - - default: - print_menu(); - break; - } -} - -void -reread(void) -{ - u_int8_t cmd[I4B_MON_CFGREREAD_SIZE]; - I4B_PREP_CMD(cmd, I4B_MON_CFGREREAD_CODE); -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_CFGREREAD_CODE, 0); -#endif - if((sock_write(monsock, cmd, I4B_MON_CFGREREAD_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } -} - -void -hangup(int ctrl, int chan) -{ - u_int8_t cmd[I4B_MON_HANGUP_SIZE]; - - I4B_PREP_CMD(cmd, I4B_MON_HANGUP_CODE); - I4B_PUT_4B(cmd, I4B_MON_HANGUP_CTRL, ctrl); - I4B_PUT_4B(cmd, I4B_MON_HANGUP_CHANNEL, chan); - -#ifdef DEBUG - if(debug & DBG_DUMPALL) - dump_event(cmd, I4B_MON_HANGUP_CHANNEL, 0); -#endif - - if((sock_write(monsock, cmd, I4B_MON_HANGUP_SIZE)) == -1) - { - fprintf(stderr, "sock_write failed: %s\n", strerror(errno)); - exit(1); - } -} - -/* - * Display menu - */ -static void -print_menu() -{ - if(!fullscreen) - { - printf("Menu: <1> display rights, <2> display monitor connections,\n"); - printf(" <3> reread config file, <4> hangup \n"); - printf(" <9> quit isdnmonitor\n"); - fflush(stdout); - } -} - -static ssize_t -sock_read(int fd, void *buf, size_t nbytes) -{ - size_t nleft; - ssize_t nread; - unsigned char *ptr; - - ptr = buf; - nleft = nbytes; - - while(nleft > 0) - { - if((nread = read(fd, ptr, nleft)) < 0) - { - if(errno == EINTR) - { - nread = 0; - } - else - { - return(-1); - } - } - else if(nread == 0) - { - break; /* EOF */ - } - - nleft -= nread; - ptr += nread; - } - return(nbytes - nleft); -} - -static ssize_t -sock_write(int fd, void *buf, size_t nbytes) -{ - size_t nleft; - ssize_t nwritten; - unsigned char *ptr; - - ptr = buf; - nleft = nbytes; - - while(nleft > 0) - { - if((nwritten = write(fd, ptr, nleft)) <= 0) - { - if(errno == EINTR) - { - nwritten = 0; - } - else - { - return(-1); - } - } - - nleft -= nwritten; - ptr += nwritten; - } - return(nbytes); -} - -static void -mprintf(char *fmt, ...) -{ -#define PRBUFLEN 1024 - char buffer[PRBUFLEN]; - va_list ap; - - va_start(ap, fmt); - vsnprintf(buffer, PRBUFLEN-1, fmt, ap); - va_end(ap); - - if(!fullscreen || (fullscreen && (!curses_ready))) - printf("%s", buffer); - - if(logfilename != NULL) - { - fprintf(lfp, "%s", buffer); - fflush(lfp); - } -} - -/* EOF */ diff --git a/usr.sbin/i4b/isdnmonitor/monitor.h b/usr.sbin/i4b/isdnmonitor/monitor.h deleted file mode 100644 index 4862c4835e3a..000000000000 --- a/usr.sbin/i4b/isdnmonitor/monitor.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright (c) 1998,1999 Martin Husemann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * 4. Altered versions must be plainly marked as such, and must not be - * misrepresented as being the original software and/or documentation. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - *--------------------------------------------------------------------------- - * - * i4b daemon - network monitor protocol definition - * ------------------------------------------------ - * - * $Id: monitor.h,v 1.16 1999/12/13 21:25:26 hm Exp $ - * - * $FreeBSD$ - * - * last edit-date: [Mon Dec 13 21:52:18 1999] - * - *---------------------------------------------------------------------------*/ - -#ifndef _MONITOR_H_ -#define _MONITOR_H_ - -#define DEF_MONPORT 451 /* default monitor TCP port */ - -#ifdef __hpux -#define u_int8_t ubit8 -#define u_int32_t ubit32 -#endif -#ifdef WIN32 -#define u_int8_t BYTE -#define u_int32_t DWORD -#endif - -/* - * The monitor client connects to the isdnd daemon process via a tcp/ip - * connection from a remote machine or via a local (unix domain) socket. - * The daemon accepts multiple connections and verifies access rights. - * On connection establishment the daemon sends initial data telling - * the client the current configuration: number and type of available - * controllers, current connections, channel and interface states - * and the clients access privileges. The client sends an event mask - * telling the daemon which events it is interested in. If the client - * has appropriate rights he may send commands to the daemon. - * - * All multi-byte values are in network byte order! - */ - -/* All data packets transfered are declared as arrays of u_int8_t */ - -/* max stringlength used in this protocol */ -#define I4B_MAX_MON_STRING 256 - -/* max command size from client to server */ -#define I4B_MAX_MON_CLIENT_CMD 16 - -/* Version of the monitor protocol described here */ -#define MPROT_VERSION 0 /* major version no */ -#define MPROT_REL 5 /* release no */ - -/* - * Client access rights - */ -#define I4B_CA_COMMAND_FULL 1 /* may send any command */ -#define I4B_CA_COMMAND_RESTRICTED 2 /* may send 'harmless' commands */ -#define I4B_CA_EVNT_CHANSTATE 16 /* may watch b-channel states */ -#define I4B_CA_EVNT_CALLIN 32 /* may watch incoming calls */ -#define I4B_CA_EVNT_CALLOUT 64 /* may watch outgoing calls */ -#define I4B_CA_EVNT_I4B 128 /* may watch isdnd actions */ - -/* - * General layout of a command packet. All commands have this common - * prefix. It is prepared by the macro I4B_PREP_CMD (s.b.) - */ -#define I4B_MON_CMD 0 /* 2 byte: command code */ -#define I4B_MON_CMD_LEN 2 /* 2 byte: packet length */ -#define I4B_MON_CMD_HDR 4 /* size of header */ - -/* - * Currently events look the same as commands. We do not make - * any guarantee this will remain the same, so a different set - * of macros is used when describing events. Events are prepared - * by I4B_PREP_EVNT (s.b.) - */ -#define I4B_MON_EVNT 0 /* 2 byte: event code */ -#define I4B_MON_EVNT_LEN 2 /* 2 byte: packet length */ -#define I4B_MON_EVNT_HDR 4 /* size of header */ - -/* Initial data send by daemon after connection is established */ -#define I4B_MON_IDATA_SIZE I4B_MON_EVNT_HDR+12 -#define I4B_MON_IDATA_CODE 0 /* event code */ -#define I4B_MON_IDATA_VERSMAJOR I4B_MON_EVNT_HDR+0 /* 2 byte: isdnd major version */ -#define I4B_MON_IDATA_VERSMINOR I4B_MON_EVNT_HDR+2 /* 2 byte: isdnd minor version */ -#define I4B_MON_IDATA_NUMCTRL I4B_MON_EVNT_HDR+4 /* 2 byte: number of controllers */ -#define I4B_MON_IDATA_NUMENTR I4B_MON_EVNT_HDR+6 /* 2 byte: number of controllers */ -#define I4B_MON_IDATA_CLACCESS I4B_MON_EVNT_HDR+8 /* 4 byte: client rights */ - -/* followed by this for every controller */ -#define I4B_MON_ICTRL_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+8 -#define I4B_MON_ICTRL_CODE 1 /* event code */ -#define I4B_MON_ICTRL_NAME I4B_MON_EVNT_HDR+0 /* string: name of controller */ -#define I4B_MON_ICTRL_BUSID I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: isdn bus id (reservered) */ -#define I4B_MON_ICTRL_FLAGS I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2 /* 4 byte: controller flags (not yet defined) */ -#define I4B_MON_ICTRL_NCHAN I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+6 /* 2 byte: number of b channels on this controller */ - -/* followed by this for every entry */ -#define I4B_MON_IDEV_SIZE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+2 -#define I4B_MON_IDEV_CODE 2 /* event code */ -#define I4B_MON_IDEV_NAME I4B_MON_EVNT_HDR+0 /* string: name of device */ -#define I4B_MON_IDEV_STATE I4B_MON_EVNT_HDR+I4B_MAX_MON_STRING+0 /* 2 byte: state of device */ - -/* - * The client sets it's protocol version and event mask (usually once after - * connection establishement) - */ -#define I4B_MON_CCMD_SETMASK 0x7e /* command code */ -#define I4B_MON_ICLIENT_SIZE I4B_MON_CMD_HDR+8 -#define I4B_MON_ICLIENT_VERMAJOR I4B_MON_CMD_HDR+0 /* 2 byte: protocol major version (always 0 for now) */ -#define I4B_MON_ICLIENT_VERMINOR I4B_MON_CMD_HDR+2 /* 2 byte: protocol minor version (always 0 for now) */ -#define I4B_MON_ICLIENT_EVENTS I4B_MON_CMD_HDR+4 /* 4 byte: client event mask */ - -/* The client requests a list of monitor rights */ -#define I4B_MON_DUMPRIGHTS_CODE 1 -#define I4B_MON_DUMPRIGHTS_SIZE I4B_MON_CMD_HDR /* no parameters */ - -/* - * In response to an I4B_MON_DUMPRIGHTS_CODE command, the daemon sends - * this event: - */ -#define I4B_MON_DRINI_CODE 2 /* event code */ -#define I4B_MON_DRINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */ -#define I4B_MON_DRINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */ - -/* followed by this for each record anounced above */ -#define I4B_MON_DR_CODE 3 -#define I4B_MON_DR_SIZE I4B_MON_EVNT_HDR+13 -#define I4B_MON_DR_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */ -#define I4B_MON_DR_NET I4B_MON_EVNT_HDR+4 /* 4 byte: network address */ -#define I4B_MON_DR_MASK I4B_MON_EVNT_HDR+8 /* 4 byte: network mask */ -#define I4B_MON_DR_LOCAL I4B_MON_EVNT_HDR+12 /* 1 byte: non-zero if local socket */ - -/* The client requests a list of monitor connections */ -#define I4B_MON_DUMPMCONS_CODE 2 -#define I4B_MON_DUMPMCONS_SIZE I4B_MON_CMD_HDR /* no parameters */ - -/* - * In response to an I4B_MON_DUMPMCONS_CODE command, the daemon sends - * this event: - */ -#define I4B_MON_DCINI_CODE 4 /* event code */ -#define I4B_MON_DCINI_SIZE I4B_MON_EVNT_HDR+2 /* size of packet */ -#define I4B_MON_DCINI_COUNT I4B_MON_EVNT_HDR+0 /* 2 byte: number of records */ - -/* followed by this for each record anounced above */ -#define I4B_MON_DC_CODE 5 -#define I4B_MON_DC_SIZE I4B_MON_EVNT_HDR+8 -#define I4B_MON_DC_RIGHTS I4B_MON_EVNT_HDR+0 /* 4 byte: rights mask */ -#define I4B_MON_DC_WHO I4B_MON_EVNT_HDR+4 /* 4 byte: network address */ - -/* The client requests a config file rescan */ -#define I4B_MON_CFGREREAD_CODE 3 -#define I4B_MON_CFGREREAD_SIZE I4B_MON_CMD_HDR /* no parameters */ - -/* The client requests to hangup a connection */ -#define I4B_MON_HANGUP_CODE 4 -#define I4B_MON_HANGUP_SIZE I4B_MON_CMD_HDR+8 -#define I4B_MON_HANGUP_CTRL I4B_MON_CMD_HDR+0 /* controller */ -#define I4B_MON_HANGUP_CHANNEL I4B_MON_CMD_HDR+4 /* channel */ - -/* The daemon sends a logfile event */ -#define I4B_MON_LOGEVNT_CODE 6 -#define I4B_MON_LOGEVNT_SIZE I4B_MON_EVNT_HDR+8+2*I4B_MAX_MON_STRING -#define I4B_MON_LOGEVNT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */ -#define I4B_MON_LOGEVNT_PRIO I4B_MON_EVNT_HDR+4 /* 4 byte: syslog priority */ -#define I4B_MON_LOGEVNT_WHAT I4B_MON_EVNT_HDR+8 /* followed by 2 strings: 'what' and 'message' */ -#define I4B_MON_LOGEVNT_MSG I4B_MON_EVNT_HDR+8+I4B_MAX_MON_STRING - -/* The daemon sends a charge event */ -#define I4B_MON_CHRG_CODE 7 -#define I4B_MON_CHRG_SIZE I4B_MON_EVNT_HDR+20 -#define I4B_MON_CHRG_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: timestamp */ -#define I4B_MON_CHRG_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel charged */ -#define I4B_MON_CHRG_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel charged */ -#define I4B_MON_CHRG_UNITS I4B_MON_EVNT_HDR+12 /* 4 byte: new charge value */ -#define I4B_MON_CHRG_ESTIMATED I4B_MON_EVNT_HDR+16 /* 4 byte: 0 = charge by network, 1 = calculated estimate */ - -/* The daemon sends a connect event */ -#define I4B_MON_CONNECT_CODE 8 -#define I4B_MON_CONNECT_SIZE I4B_MON_EVNT_HDR+16+4*I4B_MAX_MON_STRING -#define I4B_MON_CONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_CONNECT_DIR I4B_MON_EVNT_HDR+4 /* 4 byte: direction (0 = incoming, 1 = outgoing) */ -#define I4B_MON_CONNECT_CTRL I4B_MON_EVNT_HDR+8 /* 4 byte: channel connected */ -#define I4B_MON_CONNECT_CHANNEL I4B_MON_EVNT_HDR+12 /* 4 byte: channel connected */ -#define I4B_MON_CONNECT_CFGNAME I4B_MON_EVNT_HDR+16 /* name of config entry */ -#define I4B_MON_CONNECT_DEVNAME I4B_MON_EVNT_HDR+16+I4B_MAX_MON_STRING /* name of device used for connection */ -#define I4B_MON_CONNECT_REMPHONE I4B_MON_EVNT_HDR+16+2*I4B_MAX_MON_STRING /* remote phone no. */ -#define I4B_MON_CONNECT_LOCPHONE I4B_MON_EVNT_HDR+16+3*I4B_MAX_MON_STRING /* local phone no. */ - -/* The daemon sends a disconnect event */ -#define I4B_MON_DISCONNECT_CODE 9 -#define I4B_MON_DISCONNECT_SIZE I4B_MON_EVNT_HDR+12 -#define I4B_MON_DISCONNECT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_DISCONNECT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */ -#define I4B_MON_DISCONNECT_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */ - -/* The daemon sends an up/down event */ -#define I4B_MON_UPDOWN_CODE 10 -#define I4B_MON_UPDOWN_SIZE I4B_MON_EVNT_HDR+16 -#define I4B_MON_UPDOWN_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_UPDOWN_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: channel disconnected */ -#define I4B_MON_UPDOWN_CHANNEL I4B_MON_EVNT_HDR+8 /* 4 byte: channel disconnected */ -#define I4B_MON_UPDOWN_ISUP I4B_MON_EVNT_HDR+12 /* 4 byte: interface is up */ - -/* The daemon sends a L1/L2 status change event */ -#define I4B_MON_L12STAT_CODE 11 -#define I4B_MON_L12STAT_SIZE I4B_MON_EVNT_HDR+16 -#define I4B_MON_L12STAT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_L12STAT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */ -#define I4B_MON_L12STAT_LAYER I4B_MON_EVNT_HDR+8 /* 4 byte: layer */ -#define I4B_MON_L12STAT_STATE I4B_MON_EVNT_HDR+12 /* 4 byte: state */ - -/* The daemon sends a TEI change event */ -#define I4B_MON_TEI_CODE 12 -#define I4B_MON_TEI_SIZE I4B_MON_EVNT_HDR+12 -#define I4B_MON_TEI_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_TEI_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */ -#define I4B_MON_TEI_TEI I4B_MON_EVNT_HDR+8 /* 4 byte: tei */ - -/* The daemon sends an accounting message event */ -#define I4B_MON_ACCT_CODE 13 -#define I4B_MON_ACCT_SIZE I4B_MON_EVNT_HDR+28 -#define I4B_MON_ACCT_TSTAMP I4B_MON_EVNT_HDR+0 /* 4 byte: time stamp */ -#define I4B_MON_ACCT_CTRL I4B_MON_EVNT_HDR+4 /* 4 byte: controller */ -#define I4B_MON_ACCT_CHAN I4B_MON_EVNT_HDR+8 /* 4 byte: channel */ -#define I4B_MON_ACCT_OBYTES I4B_MON_EVNT_HDR+12 /* 4 byte: outbytes */ -#define I4B_MON_ACCT_OBPS I4B_MON_EVNT_HDR+16 /* 4 byte: outbps */ -#define I4B_MON_ACCT_IBYTES I4B_MON_EVNT_HDR+20 /* 4 byte: inbytes */ -#define I4B_MON_ACCT_IBPS I4B_MON_EVNT_HDR+24 /* 4 byte: inbps */ - -/* macros for setup/decoding of protocol packets */ - -/* clear a record */ -#define I4B_CLEAR(r) memset(&(r), 0, sizeof(r)); - -/* prepare a record as event or command */ -#define I4B_PREP_EVNT(r, e) { \ - I4B_CLEAR(r); \ - I4B_PUT_2B(r, I4B_MON_EVNT, e); \ - I4B_PUT_2B(r, I4B_MON_EVNT_LEN, sizeof(r)); \ -} -#define I4B_PREP_CMD(r, c) { \ - I4B_CLEAR(r); \ - I4B_PUT_2B(r, I4B_MON_CMD, c); \ - I4B_PUT_2B(r, I4B_MON_CMD_LEN, sizeof(r)); \ -} - -/* put 1, 2 or 4 bytes in network byte order into a record at offset off */ -#define I4B_PUT_1B(r, off, val) { ((u_int8_t*)(r))[off] = (val) & 0x00ff; } -#define I4B_PUT_2B(r, off, val) { I4B_PUT_1B(r, off, val >> 8); I4B_PUT_1B(r, off+1, val); } -#define I4B_PUT_4B(r, off, val) { I4B_PUT_1B(r, off, val >> 24); I4B_PUT_1B(r, off+1, val >> 16); I4B_PUT_1B(r, off+2, val >> 8); I4B_PUT_1B(r, off+3, val); } - -/* get 1, 2 or 4 bytes in network byte order from a record at offset off */ -#define I4B_GET_1B(r, off) (((u_int8_t*)(r))[off]) -#define I4B_GET_2B(r, off) ((((u_int8_t*)(r))[off]) << 8) | (((u_int8_t*)(r))[off+1]) -#define I4B_GET_4B(r, off) ((((u_int8_t*)(r))[off]) << 24) | ((((u_int8_t*)(r))[off+1]) << 16) | ((((u_int8_t*)(r))[off+2]) << 8) | (((u_int8_t*)(r))[off+3]) - -/* - * put a string into record r at offset off, make sure it's not to long - * and proper terminate it - */ -#define I4B_PUT_STR(r, off, str) { \ - strncpy((r)+(off), (str), I4B_MAX_MON_STRING); \ - (r)[(off)+I4B_MAX_MON_STRING-1] = (u_int8_t)0; } - -#endif /* _MONITOR_H_ */ - diff --git a/usr.sbin/i4b/isdnmonitor/monprivate.h b/usr.sbin/i4b/isdnmonitor/monprivate.h deleted file mode 100644 index d6763449c898..000000000000 --- a/usr.sbin/i4b/isdnmonitor/monprivate.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 1999 Hellmuth Michaelis. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - *--------------------------------------------------------------------------- - * - * i4b remote monitor - private header - * ----------------------------------- - * - * $Id: monprivate.h,v 1.10 1999/12/13 21:25:26 hm Exp $ - * - * $FreeBSD$ - * - * last edit-date: [Mon Dec 13 21:52:25 1999] - * - *---------------------------------------------------------------------------*/ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <ctype.h> -#include <errno.h> -#include <signal.h> - -#ifndef WIN32 -#include <unistd.h> -#include <syslog.h> -#include <regex.h> -#include <curses.h> -#include <fcntl.h> - -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/types.h> -#include <sys/ioctl.h> -#endif - -/*---------------------------------------------------------------------------* - * definitions in i4b_ioctl.h, do something for other systems - *---------------------------------------------------------------------------*/ -#if defined (__FreeBSD__) || defined(__NetBSD__) || \ - defined (__OpenBSD__) || defined(__bsdi__) - -#include <i4b/i4b_ioctl.h> - -#else - -#define FOREIGN 1 /* we are running on a "foreign" OS */ - -#define I4B_TIME_FORMAT "%d.%m.%Y %H:%M:%S" -#define VERSION 0 -#define REL 0 -#define STEP 0 - -#endif - -/*---------------------------------------------------------------------------* - * some general definitions - *---------------------------------------------------------------------------*/ -#define GOOD 0 /* general "good" or "ok" return*/ -#define ERROR (-1) /* general error return */ -#define WARNING (-2) /* warning return */ -#define INVALID (-1) /* an invalid integer */ - -/*---------------------------------------------------------------------------* - * state definitions - *---------------------------------------------------------------------------*/ -#define ST_INIT 0 /* initial data */ -#define ST_ICTRL 1 /* initial controller list */ -#define ST_IDEV 2 /* initial entry devicename list */ -#define ST_ANYEV 3 /* any event */ -#define ST_RIGHT 4 /* one record in a list of monitor rights */ -#define ST_CONNS 5 /* monitor connections */ - -/*---------------------------------------------------------------------------* - * curses fullscreen display definitions - *---------------------------------------------------------------------------*/ -/* window dimensions */ -#define UPPER_B 2 /* upper window start */ - -/* horizontal positions for upper window */ -#define H_CNTL 0 /* controller */ -#define H_TEI 2 /* TEI */ -#define H_CHAN (H_TEI+4) /* channel */ -#define H_TELN (H_CHAN+2) /* telephone number */ -#define H_IFN (H_TELN+23) /* interfacename */ -#define H_IO (H_IFN+7) /* incoming or outgoing */ -#define H_OUT (H_IO+4) /* # of bytes out */ -#define H_OUTBPS (H_OUT+11) /* bytes per second out */ -#define H_IN (H_OUTBPS+5) /* # of bytes in */ -#define H_INBPS (H_IN+11) /* bytes per second in */ -#define H_UNITS (H_INBPS+6) /* # of charging units */ - -/* fullscreen mode menu window */ -#define WMENU_LEN 35 /* width of menu window */ -#define WMENU_TITLE "Command" /* title string */ -#define WMENU_POSLN 10 /* menu position, line */ -#define WMENU_POSCO 5 /* menu position, col */ -#define WMITEMS 4 /* no of menu items */ -#define WMENU_HGT (WMITEMS + 4) /* menu window height */ - -#define WREFRESH 0 -#define WHANGUP 1 -#define WREREAD 2 -#define WQUIT 3 - -#define WMTIMEOUT 5 /* timeout in seconds */ - -/*---------------------------------------------------------------------------* - * misc - *---------------------------------------------------------------------------*/ -#define CHPOS(uctlr, uchan) (((uctlr)*2) + (uchan)) - -/*---------------------------------------------------------------------------* - * remote state - *---------------------------------------------------------------------------*/ - -#define MAX_CTRL 4 - -typedef struct remstate { - int ch1state; - int ch2state; -} remstate_t; - -/*---------------------------------------------------------------------------* - * global variables - *---------------------------------------------------------------------------*/ -#ifdef MAIN - -remstate_t remstate[MAX_CTRL]; - -int nctrl = 0; /* # of controllers available */ -int curses_ready = 0; /* curses initialized */ -int do_bell = 0; -int nentries = 0; -int fullscreen = 0; -int debug_noscreen = 0; - -#ifndef WIN32 -WINDOW *upper_w; /* curses upper window pointer */ -WINDOW *mid_w; /* curses mid window pointer */ -WINDOW *lower_w; /* curses lower window pointer */ -#endif - -char devbuf[256]; - -char *sockpath = NULL; -char *hostname = NULL; -int portno; - -#else /* !MAIN */ - -remstate_t remstate[MAX_CTRL]; - -int nctrl; -int curses_ready; -int do_bell; -int nentries; -int fullscreen; -int debug_noscreen; - -WINDOW *upper_w; -WINDOW *mid_w; -WINDOW *lower_w; - -char devbuf[256]; - -char *sockpath; -char *hostname; -int portno; - -#endif - -extern void do_exit ( int exitval ); -extern void do_menu ( void ); -extern void init_screen ( void ); -extern void display_charge ( int pos, int charge ); -extern void display_ccharge ( int pos, int units ); -extern void display_connect(int pos, int dir, char *name, char *remtel, char *dev); -extern void display_acct ( int pos, int obyte, int obps, int ibyte, int ibps ); -extern void display_disconnect ( int pos ); -extern void display_updown ( int pos, int updown, char *device ); -extern void display_l12stat ( int controller, int layer, int state ); -extern void display_tei ( int controller, int tei ); - -extern void reread(void); -extern void hangup(int ctrl, int chan); - - |