2 * Copyright (c) 1998,1999 Martin Husemann. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the author nor the names of any co-contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 * 4. Altered versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software and/or documentation.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 *---------------------------------------------------------------------------
33 * i4b daemon - network monitor client
34 * -----------------------------------
36 * $Id: main.c,v 1.35 2000/08/24 11:48:57 hm Exp $
38 * $FreeBSD: src/usr.sbin/i4b/isdnmonitor/main.c,v 1.7.2.1 2001/08/01 17:45:06 obrien Exp $
40 * last edit-date: [Mon Dec 13 21:52:11 1999]
42 *---------------------------------------------------------------------------*/
55 #include <sys/types.h>
57 #include <sys/socket.h>
58 #include <sys/ioctl.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
66 int getopt(int nargc, char * const nargv[], const char *ostr);
67 #define close(f) closesocket(f)
68 #define sleep(s) Sleep(s*1000)
69 #define vsnprintf _vsnprintf
77 #include "monprivate.h"
81 #define AF_LOCAL AF_UNIX
91 * Local function prototypes
93 static int connect_local(char *sockpath);
94 static int connect_remote(char *host, int portno);
97 static void handle_input();
98 static void print_menu();
99 static void print_logevent(time_t tstamp, int prio, char * what, char * msg);
100 static void print_charge(time_t tstamp, int controller, int channel, int units, int estimated);
101 static void print_connect(time_t tstamp, int dir, int controller, int channel, char * cfgname, char * devname, char * remphone, char * locphone);
102 static void print_disconnect(time_t tstamp, int controller, int channel);
103 static void print_updown(time_t tstamp, int contoller, int channel, int isup);
104 static void handle_event(u_int8_t *msg, int len);
106 static void dump_event(u_int8_t *msg, int len, int readflag);
109 static ssize_t sock_read(int fd, void *buf, size_t nbytes);
110 static ssize_t sock_write(int fd, void *buf, size_t nbytes);
112 static void mprintf(char *fmt, ...);
117 static int debug = 0;
118 #define DBG_DUMPALL 0x01
119 #define DBG_PSEND 0x02
121 static int monsock = -1;
122 static int state = ST_INIT;
123 static int sub_state = 0;
124 static int sub_state_count = 0;
126 static int isdn_major = 0;
127 static int isdn_minor = 0;
128 static u_int32_t rights = 0;
130 static char *logfilename = NULL;
131 static FILE *lfp = NULL;
133 /*---------------------------------------------------------------------------
134 * Display usage and exit
135 *---------------------------------------------------------------------------*/
139 fprintf(stderr, "\n");
140 fprintf(stderr, "isdnmonitor - version %02d.%02d.%d, %s %s (protocol %02d.%02d)\n", VERSION, REL, STEP, __DATE__, __TIME__, MPROT_VERSION, MPROT_REL);
142 fprintf(stderr, " usage: isdnmonitor [-c] [-d val] [-f name] [-h host] [-p port]\n");
144 fprintf(stderr, " usage: isdnmonitor [-c] [-d val] [-f name] [-h host] [-l path] [-p port]\n");
146 fprintf(stderr, " -c switch to curses fullscreen output\n");
147 fprintf(stderr, " -d <val> debug flags (see source ...)\n");
148 fprintf(stderr, " -dn no debug output on fullscreen display\n");
149 fprintf(stderr, " -f <name> filename to log output to\n");
150 fprintf(stderr, " -h <host> hostname/address to connect to\n");
152 fprintf(stderr, " -l <path> pathname to local domain socket to connect to\n");
154 fprintf(stderr, " -p <port> portnumber to use to connect to remote host\n");
158 /*---------------------------------------------------------------------------
159 * Parse command line, startup monitor client
160 *---------------------------------------------------------------------------*/
161 int main(int argc, char **argv)
167 WSAStartup(MAKEWORD(2, 0), &wsCaps);
170 portno = DEF_MONPORT;
174 while((i = getopt(argc, argv, "cd:f:h:p:l:")) != -1)
176 while((i = getopt(argc, argv, "cd:f:h:p:")) != -1)
191 if((sscanf(optarg, "%i", &debug)) != 1)
196 logfilename = optarg;
207 if((sscanf(optarg, "%i", &portno)) != 1)
217 if(hostname && sockpath)
219 fprintf(stderr, "Error: can not use local socket path on remote machine\n"
220 "conflicting options -h and -l!\n");
226 monsock = connect_local(sockpath);
234 monsock = connect_remote(hostname, portno);
243 fprintf(stderr, "Could not connect to i4b isdn daemon.\n");
247 if(logfilename != NULL)
249 if((lfp = fopen(logfilename, "w")) == NULL)
251 fprintf(stderr, "could not open logfile [%s], %s\n", logfilename, strerror(errno));
257 signal(SIGPIPE, SIG_IGN);
267 /*---------------------------------------------------------------------------
268 * Connect via tcp/ip.
269 * Return socket if successfull, -1 on error.
270 ---------------------------------------------------------------------------*/
272 connect_remote(char *host, int portno)
274 struct sockaddr_in sa;
278 h = gethostbyname(host);
282 fprintf(stderr, "could not resolve hostname '%s'\n", host);
286 remotesockfd = socket(AF_INET, SOCK_STREAM, 0);
288 if(remotesockfd == -1)
290 fprintf(stderr, "could not create remote monitor socket: %s\n", strerror(errno));
294 memset(&sa, 0, sizeof(sa));
297 sa.sin_len = sizeof(sa);
299 sa.sin_family = AF_INET;
300 sa.sin_port = htons(portno);
302 memcpy(&sa.sin_addr.s_addr, h->h_addr_list[0], sizeof(sa.sin_addr.s_addr));
304 if(connect(remotesockfd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
306 fprintf(stderr, "could not connect remote monitor: %s\n", strerror(errno));
314 /*---------------------------------------------------------------------------
316 * Return socket on success, -1 on failure.
317 *---------------------------------------------------------------------------*/
319 connect_local(char *sockpath)
322 struct sockaddr_un sa;
324 /* check path length */
325 if(strlen(sockpath) >= sizeof(sa.sun_path))
327 fprintf(stderr, "pathname to long for local socket: %s\n",
332 /* create and setup socket */
333 s = socket(AF_LOCAL, SOCK_STREAM, 0);
337 fprintf(stderr, "could not create local monitor socket:%s\n", strerror(errno));
341 memset(&sa, 0, sizeof(sa));
343 sa.sun_len = sizeof(sa);
344 sa.sun_family = AF_LOCAL;
345 strcpy(sa.sun_path, sockpath);
347 if(connect(s, (struct sockaddr *)&sa, sizeof(sa)))
349 fprintf(stderr, "could not connect local monitor socket [%s]: %s\n", sockpath, strerror(errno));
356 /*---------------------------------------------------------------------------*
357 * data from keyboard available, read and process it
358 *---------------------------------------------------------------------------*/
367 case 0x0c: /* control L */
379 /*---------------------------------------------------------------------------
381 *---------------------------------------------------------------------------*/
392 FD_SET(fileno(stdin), &rd);
393 FD_SET(monsock, &rd);
395 select(monsock+1, &rd, &wr, &ex, NULL);
397 if(FD_ISSET(fileno(stdin), &rd))
400 if(fullscreen && curses_ready)
410 if(FD_ISSET(monsock, &rd))
415 /* Network transfer may deliver two or more packets concatenated.
416 * Peek at the header and read only one event at a time... */
418 bytes = recv(monsock, buf, I4B_MON_EVNT_HDR, MSG_PEEK);
432 mprintf("remote isdnd has closed our connection\n");
437 fprintf(stderr, "recv error: %s\n", strerror(errno));
442 if (bytes < I4B_MON_EVNT_HDR)
443 continue; /* errh? something must be wrong... */
445 bytes = I4B_GET_2B(buf, I4B_MON_EVNT_LEN);
447 if(bytes >= sizeof(buf))
449 fprintf(stderr, "mloop: socket recv buffer overflow %d!\n", bytes);
453 /* now we know the size, it fits, so lets read it! */
455 ret = sock_read(monsock, buf, bytes);
464 mprintf("remote isdnd has closed our connection\n");
469 mprintf("error reading from isdnd: %s", strerror(errno));
473 if(debug & DBG_DUMPALL)
474 dump_event(buf, ret, 1);
476 handle_event(buf, ret);
483 * Dump a complete event packet.
485 static void dump_event(u_int8_t *msg, int len, int read)
490 mprintf("read from socket:");
492 mprintf("write to socket:");
494 for(i = 0; i < len; i++)
497 mprintf("\n%02d: ", i);
498 mprintf("0x%02x %c ", msg[i], isprint(msg[i]) ? msg[i] : '.');
505 print_logevent(time_t tstamp, int prio, char * what, char * msg)
508 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
509 mprintf("log: %s prio %d what=%s msg=%s\n", buf, prio, what, msg);
514 if((!debug_noscreen) || (debug_noscreen && (((strcmp(what, "DBG"))) != 0)))
517 * FreeBSD-current integrated ncurses. Since then it is no longer possible
518 * to write to the last column in the logfilewindow without causing an
519 * automatic newline to occur resulting in a blank line in that window.
522 #include <osreldate.h>
524 #if defined(__FreeBSD_version) && __FreeBSD_version >= 400009
525 #warning "FreeBSD ncurses is buggy: write to last column = auto newline!"
526 wprintw(lower_w, "%s %s %-.*s\n", buf, what,
527 COLS-((strlen(buf))+(strlen(what))+3), msg);
529 wprintw(lower_w, "%s %s %-.*s\n", buf, what,
530 (int)(COLS-((strlen(buf))+(strlen(what))+2)), msg);
539 print_charge(time_t tstamp, int controller, int channel, int units, int estimated)
542 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
543 mprintf("%s: controller %d, channel %d, charge = %d%s\n",
544 buf, controller, channel, units, estimated ? " (estimated)" : "");
549 display_ccharge(CHPOS(controller, channel), units);
551 display_charge(CHPOS(controller, channel), units);
557 * Print a connect event.
558 * A real monitor would allocate state info for "channel" on this
561 static void print_connect(
562 time_t tstamp, /* server time of event */
563 int outgoing, /* 0 = incoming, 1 = outgoing */
564 int controller, /* controller number */
565 int channel, /* channel no, used to identify this connection until disconnect */
566 char * cfgname, /* name of config entry/connection */
567 char * devname, /* device used (e.g. isp0) */
568 char * remphone, /* phone no of remote side */
569 char * locphone) /* local phone no */
574 remstate[controller].ch1state = 1;
576 remstate[controller].ch2state = 1;
578 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
581 mprintf("%s: calling out to '%s' [from msn: '%s']",
582 buf, remphone, locphone);
584 mprintf("%s: incoming call from '%s' [to msn: '%s']",
585 buf, remphone, locphone);
586 mprintf(", controller %d, channel %d, config '%s' on device '%s'\n",
587 controller, channel, cfgname, devname);
591 display_connect(CHPOS(controller, channel), outgoing, cfgname, remphone, devname);
596 * Print a disconnect event.
597 * A real monitor could free the "per connection" state
598 * for this channel now
601 print_disconnect(time_t tstamp, int controller, int channel)
606 remstate[controller].ch1state = 0;
608 remstate[controller].ch2state = 0;
610 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
612 mprintf("%s: controller %d, channel %d disconnected\n",
613 buf, controller, channel);
617 display_disconnect(CHPOS(controller, channel));
622 * Print an up- or down event
625 print_updown(time_t tstamp, int controller, int channel, int isup)
628 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
629 mprintf("%s: channel %d is %s\n",
630 buf, channel, isup ? "up" : "down");
634 * Print l1 / l2 status
637 print_l12stat(time_t tstamp, int controller, int layer, int state)
640 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
642 mprintf("%s: layer %d change on controller %d: %s\n",
643 buf, layer, controller, state ? "up" : "down");
646 display_l12stat(controller, layer, state);
654 print_tei(time_t tstamp, int controller, int tei)
657 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
659 mprintf("%s: controller %d, TEI is %d\n",
660 buf, controller, tei);
664 display_tei(controller, tei);
669 * Print accounting information
672 print_acct(time_t tstamp, int controller, int channel, int obytes, int obps,
673 int ibytes, int ibps)
676 strftime(buf, sizeof(buf), I4B_TIME_FORMAT, localtime(&tstamp));
678 mprintf("%s: controller %d, channel %d: %d obytes, %d obps, %d ibytes, %d ibps\n",
679 buf, controller, channel, obytes, obps, ibytes, ibps);
682 display_acct(CHPOS(controller, channel), obytes, obps, ibytes, ibps);
687 print_initialization(void)
692 if(curses_ready == 0)
703 * Dispatch one message received from the daemon.
706 handle_event(u_int8_t *msg, int len)
708 u_int8_t cmd[I4B_MON_ICLIENT_SIZE];
713 static int first = 1;
717 case ST_INIT: /* initial data */
719 isdn_major = I4B_GET_2B(msg, I4B_MON_IDATA_VERSMAJOR);
720 isdn_minor = I4B_GET_2B(msg, I4B_MON_IDATA_VERSMINOR);
721 nctrl = I4B_GET_2B(msg, I4B_MON_IDATA_NUMCTRL);
722 nentries = I4B_GET_2B(msg, I4B_MON_IDATA_NUMENTR);
723 rights = I4B_GET_4B(msg, I4B_MON_IDATA_CLACCESS);
725 mprintf("remote protocol version is %02d.%02d\n", isdn_major, isdn_minor);
727 if(isdn_major != MPROT_VERSION || isdn_minor != MPROT_REL)
729 fprintf(stderr, "ERROR, remote protocol version mismatch:\n");
730 fprintf(stderr, "\tremote major version is %02d, local major version is %02d\n", isdn_major, MPROT_VERSION);
731 fprintf(stderr, "\tremote minor version is %02d, local minor version is %02d\n", isdn_minor, MPROT_REL);
735 mprintf("our rights = 0x%x\n", rights);
744 else if(nentries > 0)
752 print_initialization();
755 /* set maximum event mask */
756 I4B_PREP_CMD(cmd, I4B_MON_CCMD_SETMASK);
757 I4B_PUT_2B(cmd, I4B_MON_ICLIENT_VERMAJOR, MPROT_VERSION);
758 I4B_PUT_2B(cmd, I4B_MON_ICLIENT_VERMINOR, MPROT_REL);
759 I4B_PUT_4B(cmd, I4B_MON_ICLIENT_EVENTS, ~0U);
762 if(debug & DBG_DUMPALL)
763 dump_event(cmd, sizeof(cmd), 0);
766 if((sock_write(monsock, cmd, sizeof(cmd))) == -1)
768 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
773 case ST_ICTRL: /* initial controller list */
777 mprintf("%d controller(s) found:\n", nctrl);
779 mprintf("\tcontroller %d: %s\n", sub_state++, msg+I4B_MON_ICTRL_NAME);
781 if(sub_state >= nctrl)
787 state = ST_IDEV; /* end of list reached */
793 print_initialization();
798 case ST_IDEV: /* initial entry devicename list */
802 mprintf("%d entries found:\n", nentries);
805 mprintf("\tentry %d: device %s\n", sub_state++, msg+I4B_MON_IDEV_NAME);
807 strcat(devbuf, msg+I4B_MON_IDEV_NAME);
808 /* strcat(devbuf, " "); */
810 if(sub_state >= nentries)
813 state = ST_ANYEV; /* end of list reached */
816 print_initialization();
820 case ST_ANYEV: /* any event */
821 switch(I4B_GET_2B(msg, I4B_MON_EVNT))
823 case I4B_MON_DRINI_CODE:
824 state = ST_RIGHT; /* list of rights entries will follow */
826 sub_state_count = I4B_GET_2B(msg, I4B_MON_DRINI_COUNT);
827 mprintf("monitor rights:\n");
830 case I4B_MON_DCINI_CODE:
833 sub_state_count = I4B_GET_2B(msg, I4B_MON_DCINI_COUNT);
834 mprintf("monitor connections:\n");
837 case I4B_MON_LOGEVNT_CODE:
838 print_logevent(I4B_GET_4B(msg, I4B_MON_LOGEVNT_TSTAMP),
839 I4B_GET_4B(msg, I4B_MON_LOGEVNT_PRIO),
840 msg+I4B_MON_LOGEVNT_WHAT,
841 msg+I4B_MON_LOGEVNT_MSG);
844 case I4B_MON_CHRG_CODE:
845 print_charge(I4B_GET_4B(msg, I4B_MON_CHRG_TSTAMP),
846 I4B_GET_4B(msg, I4B_MON_CHRG_CTRL),
847 I4B_GET_4B(msg, I4B_MON_CHRG_CHANNEL),
848 I4B_GET_4B(msg, I4B_MON_CHRG_UNITS),
849 I4B_GET_4B(msg, I4B_MON_CHRG_ESTIMATED));
852 case I4B_MON_CONNECT_CODE:
854 I4B_GET_4B(msg, I4B_MON_CONNECT_TSTAMP),
855 I4B_GET_4B(msg, I4B_MON_CONNECT_DIR),
856 I4B_GET_4B(msg, I4B_MON_CONNECT_CTRL),
857 I4B_GET_4B(msg, I4B_MON_CONNECT_CHANNEL),
858 msg+I4B_MON_CONNECT_CFGNAME,
859 msg+I4B_MON_CONNECT_DEVNAME,
860 msg+I4B_MON_CONNECT_REMPHONE,
861 msg+I4B_MON_CONNECT_LOCPHONE);
864 case I4B_MON_DISCONNECT_CODE:
866 I4B_GET_4B(msg, I4B_MON_DISCONNECT_TSTAMP),
867 I4B_GET_4B(msg, I4B_MON_DISCONNECT_CTRL),
868 I4B_GET_4B(msg, I4B_MON_DISCONNECT_CHANNEL));
871 case I4B_MON_UPDOWN_CODE:
873 I4B_GET_4B(msg, I4B_MON_UPDOWN_TSTAMP),
874 I4B_GET_4B(msg, I4B_MON_UPDOWN_CTRL),
875 I4B_GET_4B(msg, I4B_MON_UPDOWN_CHANNEL),
876 I4B_GET_4B(msg, I4B_MON_UPDOWN_ISUP));
878 case I4B_MON_L12STAT_CODE:
880 I4B_GET_4B(msg, I4B_MON_L12STAT_TSTAMP),
881 I4B_GET_4B(msg, I4B_MON_L12STAT_CTRL),
882 I4B_GET_4B(msg, I4B_MON_L12STAT_LAYER),
883 I4B_GET_4B(msg, I4B_MON_L12STAT_STATE));
885 case I4B_MON_TEI_CODE:
887 I4B_GET_4B(msg, I4B_MON_TEI_TSTAMP),
888 I4B_GET_4B(msg, I4B_MON_TEI_CTRL),
889 I4B_GET_4B(msg, I4B_MON_TEI_TEI));
891 case I4B_MON_ACCT_CODE:
893 I4B_GET_4B(msg, I4B_MON_ACCT_TSTAMP),
894 I4B_GET_4B(msg, I4B_MON_ACCT_CTRL),
895 I4B_GET_4B(msg, I4B_MON_ACCT_CHAN),
896 I4B_GET_4B(msg, I4B_MON_ACCT_OBYTES),
897 I4B_GET_4B(msg, I4B_MON_ACCT_OBPS),
898 I4B_GET_4B(msg, I4B_MON_ACCT_IBYTES),
899 I4B_GET_4B(msg, I4B_MON_ACCT_IBPS));
902 mprintf("unknown event code: %d\n", I4B_GET_2B(msg, I4B_MON_EVNT));
906 case ST_RIGHT: /* one record in a list of monitor rights */
907 rights = I4B_GET_4B(msg, I4B_MON_DR_RIGHTS);
908 net = I4B_GET_4B(msg, I4B_MON_DR_NET);
909 mask = I4B_GET_4B(msg, I4B_MON_DR_MASK);
910 local = I4B_GET_1B(msg, I4B_MON_DR_LOCAL);
914 mprintf("\tlocal: rights = %x\n", rights);
918 mprintf("\tfrom: %d.%d.%d.%d, mask %d.%d.%d.%d, rights = %x\n",
919 (net >> 24) & 0x00ff, (net >> 16) & 0x00ff, (net >> 8) & 0x00ff, net & 0x00ff,
920 (mask >> 24) & 0x00ff, (mask >> 16) & 0x00ff, (mask >> 8) & 0x00ff, mask & 0x00ff,
926 if(sub_state >= sub_state_count)
929 print_initialization();
934 who = I4B_GET_4B(msg, I4B_MON_DC_WHO);
935 rights = I4B_GET_4B(msg, I4B_MON_DC_RIGHTS);
937 mprintf("\tfrom: %d.%d.%d.%d, rights = %x\n",
938 (who >> 24) & 0x00ff, (who >> 16) & 0x00ff, (who >> 8) & 0x00ff, who & 0x00ff,
943 if(sub_state >= sub_state_count)
946 print_initialization();
951 mprintf("unknown event from remote: local state = %d, evnt = %x, len = %d\n",
952 state, I4B_GET_2B(msg, I4B_MON_EVNT), len);
957 * Process input from user
963 int channel, controller;
965 fgets(buf, sizeof(buf), stdin);
971 u_int8_t cmd[I4B_MON_DUMPRIGHTS_SIZE];
972 I4B_PREP_CMD(cmd, I4B_MON_DUMPRIGHTS_CODE);
974 if(debug & DBG_DUMPALL)
975 dump_event(cmd, I4B_MON_DUMPRIGHTS_SIZE, 0);
978 if((sock_write(monsock, cmd, I4B_MON_DUMPRIGHTS_SIZE)) == -1)
980 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
988 u_int8_t cmd[I4B_MON_DUMPMCONS_SIZE];
989 I4B_PREP_CMD(cmd, I4B_MON_DUMPMCONS_CODE);
991 if(debug & DBG_DUMPALL)
992 dump_event(cmd, I4B_MON_DUMPMCONS_CODE, 0);
995 if((sock_write(monsock, cmd, I4B_MON_DUMPMCONS_SIZE)) == -1)
997 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
1005 u_int8_t cmd[I4B_MON_CFGREREAD_SIZE];
1006 I4B_PREP_CMD(cmd, I4B_MON_CFGREREAD_CODE);
1008 if(debug & DBG_DUMPALL)
1009 dump_event(cmd, I4B_MON_CFGREREAD_CODE, 0);
1012 if((sock_write(monsock, cmd, I4B_MON_CFGREREAD_SIZE)) == -1)
1014 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
1022 u_int8_t cmd[I4B_MON_HANGUP_SIZE];
1023 I4B_PREP_CMD(cmd, I4B_MON_HANGUP_CODE);
1025 printf("Which controller you wish to hangup? ");
1026 fgets(buf, sizeof(buf), stdin);
1027 controller = atoi(buf);
1028 I4B_PUT_4B(cmd, I4B_MON_HANGUP_CTRL, controller);
1030 printf("Which channel do you wish to hangup? ");
1031 fgets(buf, sizeof(buf), stdin);
1032 channel = atoi(buf);
1033 I4B_PUT_4B(cmd, I4B_MON_HANGUP_CHANNEL, channel);
1036 if(debug & DBG_DUMPALL)
1037 dump_event(cmd, I4B_MON_HANGUP_CHANNEL, 0);
1040 if((sock_write(monsock, cmd, I4B_MON_HANGUP_SIZE)) == -1)
1042 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
1062 u_int8_t cmd[I4B_MON_CFGREREAD_SIZE];
1063 I4B_PREP_CMD(cmd, I4B_MON_CFGREREAD_CODE);
1065 if(debug & DBG_DUMPALL)
1066 dump_event(cmd, I4B_MON_CFGREREAD_CODE, 0);
1068 if((sock_write(monsock, cmd, I4B_MON_CFGREREAD_SIZE)) == -1)
1070 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
1076 hangup(int ctrl, int chan)
1078 u_int8_t cmd[I4B_MON_HANGUP_SIZE];
1080 I4B_PREP_CMD(cmd, I4B_MON_HANGUP_CODE);
1081 I4B_PUT_4B(cmd, I4B_MON_HANGUP_CTRL, ctrl);
1082 I4B_PUT_4B(cmd, I4B_MON_HANGUP_CHANNEL, chan);
1085 if(debug & DBG_DUMPALL)
1086 dump_event(cmd, I4B_MON_HANGUP_CHANNEL, 0);
1089 if((sock_write(monsock, cmd, I4B_MON_HANGUP_SIZE)) == -1)
1091 fprintf(stderr, "sock_write failed: %s\n", strerror(errno));
1104 printf("Menu: <1> display rights, <2> display monitor connections,\n");
1105 printf(" <3> reread config file, <4> hangup \n");
1106 printf(" <9> quit isdnmonitor\n");
1112 sock_read(int fd, void *buf, size_t nbytes)
1123 if((nread = read(fd, ptr, nleft)) < 0)
1142 return(nbytes - nleft);
1146 sock_write(int fd, void *buf, size_t nbytes)
1157 if((nwritten = write(fd, ptr, nleft)) <= 0)
1176 mprintf(char *fmt, ...)
1178 #define PRBUFLEN 1024
1179 char buffer[PRBUFLEN];
1183 vsnprintf(buffer, PRBUFLEN-1, fmt, ap);
1186 if(!fullscreen || (fullscreen && (!curses_ready)))
1187 printf("%s", buffer);
1189 if(logfilename != NULL)
1191 fprintf(lfp, "%s", buffer);