From 85a37e7488181d3aac11c6f067ab20699f1063cd Mon Sep 17 00:00:00 2001 From: Detlef Wengorz Date: Sun, 7 Nov 1999 22:04:05 +0000 Subject: [PATCH] add dwabc-udpinfo-utilitys in isdnctrl --- isdnctrl/Makefile.in | 25 +++++ isdnctrl/configure | 2 + isdnctrl/configure.in | 2 + isdnctrl/isdn_dwabclib.c | 199 +++++++++++++++++++++++++++++++++++++++ isdnctrl/isdn_dwabclib.h | 28 ++++++ isdnctrl/isdnctrl.c | 92 ++++++++++++++++++ scripts/config.in | 3 + 7 files changed, 351 insertions(+) create mode 100644 isdnctrl/isdn_dwabclib.c create mode 100644 isdnctrl/isdn_dwabclib.h diff --git a/isdnctrl/Makefile.in b/isdnctrl/Makefile.in index 00a83cc0..768bb3ee 100644 --- a/isdnctrl/Makefile.in +++ b/isdnctrl/Makefile.in @@ -35,10 +35,26 @@ MODULES += ctrltimru.o MANPAGES += .isdnctrl_timru.8 endif +ifeq (@CONFIG_ISDNCTRL_DWABC_UDP_INFO@,y) +COPTS += -DI4L_DWABC_UDPINFO +ABCLIBDIR = /usr/lib +ABCICLDIR = /usr/include +endif + .SUFFIXES: .SUFFIXES: .c .o +ifeq (@CONFIG_ISDNCTRL_DWABC_UDP_INFO@,y) +all: libisdnudp.a $(PROGRAMM) + +LDFLAGS += libisdnudp.a + +libisdnudp.a: isdn_dwabclib.o + ar rs libisdnudp.a isdn_dwabclib.o + ranlib libisdnudp.a +else all: $(PROGRAM) +endif %.o: %.c Makefile $(CC) $(CFLAGS) $(INCLUDES) $(DEFS) $(COPTS) -c -o $@ $< @@ -80,6 +96,12 @@ install-man: $(MANPAGES) install: $(PROGRAM) install-man $(INSTALL) -d $(DESTDIR)$(SBINDIR) $(INSTALL_PROGRAM) $(PROGRAM) $(DESTDIR)$(SBINDIR)/$(PROGRAM) +ifeq (@CONFIG_ISDNCTRL_DWABC_UDP_INFO@,y) + $(INSTALL) -d $(ABCLIBDIR) + $(INSTALL) -d $(ABCICLDIR) + $(INSTALL_MAN) libisdnudp.a $(ABCLIBDIR)/libisdnudp.a + $(INSTALL_MAN) isdn_dwabclib.h $(ABCICLDIR)/isdn_dwabclib.h +endif install-strip: $(PROGRAM) $(INSTALL) -d $(DESTDIR)$(SBINDIR) @@ -88,6 +110,9 @@ install-strip: $(PROGRAM) uninstall: rm -f $(DESTDIR)$(SBINDIR)/$(PROGRAM) for i in $(MANPAGES) ; do rm $(DESTDIR)$(MAN8DIR)/$$i ; done +ifeq (@CONFIG_ISDNCTRL_DWABC_UDP_INFO@,y) + rm -f $(ABCLIBDIR)/libisdnudp.a $(ABCICLDIR)/isdn_dwabclib.h +endif clean: rm -f *.o *~ $(PROGRAM) *.man *.8 .*.man .*.8 diff --git a/isdnctrl/configure b/isdnctrl/configure index c0df0c8d..39ace287 100755 --- a/isdnctrl/configure +++ b/isdnctrl/configure @@ -542,6 +542,7 @@ CONFIG_SBINDIR=${CONFIG_SBINDIR:-"/sbin"} CONFIG_MANDIR=${CONFIG_MANDIR:-"/usr/man"} CONFIG_ISDNCTRL_CONF=${CONFIG_ISDNCTRL_CONF:-"n"} CONFIG_ISDNCTRL_TIMRU=${CONFIG_ISDNCTRL_TIMRU:-"n"} +CONFIG_ISDNCTRL_DWABC_UDP_INFO=${CONFIG_ISDNCTRL_DWABC_UDP_INFO:-"n"} MANDATE=`grep CHECKIN isdnctrl.man.in | awk '{print $4}'` ac_aux_dir= @@ -1700,6 +1701,7 @@ s%@CONFIG_ISDNCTRL_CONF@%$CONFIG_ISDNCTRL_CONF%g s%@CONFIG_ISDNCTRL_TIMRU@%$CONFIG_ISDNCTRL_TIMRU%g s%@CONFIG_SBINDIR@%$CONFIG_SBINDIR%g s%@CONFIG_MANDIR@%$CONFIG_MANDIR%g +s%@CONFIG_ISDNCTRL_DWABC_UDP_INFO@%$CONFIG_ISDNCTRL_DWABC_UDP_INFO%g CEOF EOF diff --git a/isdnctrl/configure.in b/isdnctrl/configure.in index 7ff097f6..5a7a4e1b 100644 --- a/isdnctrl/configure.in +++ b/isdnctrl/configure.in @@ -10,6 +10,7 @@ CONFIG_SBINDIR=${CONFIG_SBINDIR:-"/sbin"} CONFIG_MANDIR=${CONFIG_MANDIR:-"/usr/man"} CONFIG_ISDNCTRL_CONF=${CONFIG_ISDNCTRL_CONF:-"n"} CONFIG_ISDNCTRL_TIMRU=${CONFIG_ISDNCTRL_TIMRU:-"n"} +CONFIG_ISDNCTRL_DWABC_UDP_INFO=${CONFIG_ISDNCTRL_DWABC_UDP_INFO:-"n"} MANDATE=`grep CHECKIN isdnctrl.man.in | awk '{print $4}'` dnl Checks for programs. @@ -80,6 +81,7 @@ AC_SUBST(I4LCONFFILE) AC_SUBST(I4LVERSION) AC_SUBST(CONFIG_ISDNCTRL_CONF) AC_SUBST(CONFIG_ISDNCTRL_TIMRU) +AC_SUBST(CONFIG_ISDNCTRL_DWABC_UDP_INFO) AC_SUBST(CONFIG_KERNELDIR) AC_SUBST(CONFIG_SBINDIR) AC_SUBST(CONFIG_MANDIR) diff --git a/isdnctrl/isdn_dwabclib.c b/isdnctrl/isdn_dwabclib.c new file mode 100644 index 00000000..0fd8b4dc --- /dev/null +++ b/isdnctrl/isdn_dwabclib.c @@ -0,0 +1,199 @@ +/* $Id$ + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Log$ + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define RXRSZ 1500 + + +static int txrx_udp_socket(char *dest,char *em,char *buf,int bytes) +/***************************************************************** + + sizeof(*em) must be >= 1500 bytes + + returns: + + >= 0 readed bytes from isdn-link-level peer + < 0 -errno + +*******************************************************************/ +{ + struct hostent *he = NULL; + short po = 0; + int sock = -1; + struct sockaddr_in SooooK, *ms; + + ms = &SooooK; + + if(dest == NULL || em == NULL) { + + sprintf(em,"No Destination-Addr or error-pointer defined"); + return(-9999); + } + + if((he = gethostbyname(dest)) == NULL) { + + sprintf(em,"gethostbyaddr(%s) failt errno %d",dest,errno); +err:; + + if(sock > -1) + close(sock); + + if(errno < sys_nerr) + sprintf(em + strlen(em)," (%s)",sys_errlist[errno]); + + return(-errno); + } + + if((sock = socket(AF_INET,SOCK_DGRAM,0)) < 0) { + + sprintf(em,"socket creat faild errno %d",errno); + goto err; + } + + memset((void *)ms,0,sizeof(*ms)); + ms->sin_family = he->h_addrtype; + + errno = 8888; + + for(po = 3999; po >= 0; po--) { + + ms->sin_port = htons(20000+po); + + if(!bind(sock,ms,sizeof(*ms))) + break; + } + + if(po < 0) { + + sprintf(em,"cannot bind socket to (23999-20000)"); + goto err; + } + + memset((void *)ms,0,sizeof(*ms)); + ms->sin_family = he->h_addrtype; + ms->sin_port = htons(25001); + memcpy(&ms->sin_addr.s_addr,*(he->h_addr_list),he->h_length); + + if(sendto(sock,buf,bytes,0,ms,sizeof(*ms)) != bytes) { + + sprintf(em,"sendto <%s> failt errno %d",dest,errno); + goto err; + } + + { + fd_set rs; + struct timeval tv; + + memset(&rs,0,sizeof(rs)); + FD_SET(sock,&rs); + + bytes = 0; + tv.tv_sec = 3; + tv.tv_usec = 0; + + if((bytes = select(sock+1,&rs,NULL,NULL,&tv)) > 0) { + + if(FD_ISSET(sock,&rs)) { + + if((bytes = read(sock,em,RXRSZ)) < 0) { + + sprintf(em,"read from socket failt errno %d",errno); + goto err; + } + } + + } else if(bytes < 0) { + + sprintf(em,"select failt errno %d",errno); + goto err; + } + } + + close(sock); + return(bytes); +} + + +static int do_udp(char *dest,char **errm,int todo) +{ + int r = 0; + char em[RXRSZ]; + char sb[2]; + + sb[0] = sb[1] = todo; + todo++; + + if((r = txrx_udp_socket(dest,em,sb,2)) >= 2) { + + if(em[0] == todo && em[1] == todo) + return(1); + + } else if(r < 0) { + + if(errm != NULL) { + + if((*errm = (char *)malloc(strlen(em)+1)) != NULL) + strcpy(*errm,em); + } + + return(-r); + } + + return(0); +} + + + +int isdn_udp_isisdn(char *dest, char **errm) +{ + return(do_udp(dest,errm,0x28)); +} + +int isdn_udp_online(char *dest, char **errm) +{ + return(do_udp(dest,errm,0x30)); +} + +int isdn_udp_dial(char *dest, char **errm) +{ + return(do_udp(dest,errm,0x32)); +} + +int isdn_udp_hangup(char *dest, char **errm) +{ + return(do_udp(dest,errm,0x2a)); +} + +int isdn_udp_clear_ggau(char *dest, char **errm) +{ + return(do_udp(dest,errm,0x11)); +} diff --git a/isdnctrl/isdn_dwabclib.h b/isdnctrl/isdn_dwabclib.h new file mode 100644 index 00000000..72ee18ef --- /dev/null +++ b/isdnctrl/isdn_dwabclib.h @@ -0,0 +1,28 @@ +/* $Id$ + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Log$ + */ + +#ifndef ISDN_DWABCLIB_H +#define ISDN_DWABCLIB_H 1 +extern int isdn_udp_isisdn(char *dest, char **errm); +extern int isdn_udp_online(char *dest, char **errm); +extern int isdn_udp_dial(char *dest, char **errm); +extern int isdn_udp_hangup(char *dest, char **errm); +extern int isdn_udp_clear_ggau(char *dest, char **errm); +#endif diff --git a/isdnctrl/isdnctrl.c b/isdnctrl/isdnctrl.c index 59bfc6bd..4a580d6a 100644 --- a/isdnctrl/isdnctrl.c +++ b/isdnctrl/isdnctrl.c @@ -21,6 +21,9 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Log$ + * Revision 1.36 1999/11/02 20:41:21 keil + * make phonenumber ioctl compatible for ctrlconf too + * * Revision 1.35 1999/10/27 14:36:19 keil * make the phone number struct compatible between NET_DV 5 and 6 * @@ -225,6 +228,9 @@ #include #include +#ifdef I4L_DWABC_UDPINFO +#include +#endif /* fix version skew between 2.0 and 2.1 kernels (structs are identical) */ #if (NET_DV == 0x04) # undef NET_DV @@ -381,6 +387,12 @@ void usage(void) fprintf(stderr,"Note: TIMRU Kernel Support enabled\n"); #else fprintf(stderr,"Note: TIMRU Kernel Support disabled\n"); +#endif +#ifdef I4L_DWABC_UDPINFO + fprintf(stderr," -udpisisdn destination-host or ip-number\n"); + fprintf(stderr," -udponline destination-host or ip-number\n"); + fprintf(stderr," -udphangup destination-host or ip-number\n"); + fprintf(stderr," -udpdial destination-host or ip-number\n"); #endif exit(-2); } @@ -1744,6 +1756,86 @@ int main(int argc, char **argv) check_version(1); exit(0); } +#ifdef I4L_DWABC_UDPINFO + { + int art = 0; + char *p = argv[1]; + + if(!strcmp(p,"-udpisisdn")) { + art = 1; + } else if(!strcmp(p,"-udponline")) { + art = 2; + } else if(!strcmp(p,"-udphangup")) { + art = 3; + } else if(!strcmp(p,"-udpdial")) { + art = 4; + } + + if(art) { + + char *err = NULL; + int retw = 0; + p = argv[2]; + + if(argc != 3) { + + usage(); + exit(1); + } + + switch(art) { + case 1: retw = isdn_udp_isisdn(p,&err); break; + case 2: retw = isdn_udp_online(p,&err); break; + case 3: retw = isdn_udp_hangup(p,&err); break; + case 4: retw = isdn_udp_dial(p,&err); break; + } + + if(err != NULL) { + + fprintf(stderr,"%s\n",err); + free(err); + err = NULL; + } + + if(!retw) { + + switch(art) { + case 1: + printf("destination %s is NOT over i4l routed\n",p); + break; + case 2: + printf("destination %s is NOT online\n",p); + break; + case 3: + printf("destination %s CANNOT hangup the line\n",p); + break; + case 4: + printf("destination %s CANNOT dialing\n",p); + break; + } + + } else { + + switch(art) { + case 1: + printf("destination %s is over i4l routed\n",p); + break; + case 2: + printf("destination %s is online\n",p); + break; + case 3: + printf("destination %s trigger hangup \n",p); + break; + case 4: + printf("destination %s trigger dialing\n",p); + break; + } + } + + exit(!retw); + } + } +#endif check_version(0); fd = open("/dev/isdnctrl", O_RDWR); diff --git a/scripts/config.in b/scripts/config.in index 053e9c32..e34182f2 100644 --- a/scripts/config.in +++ b/scripts/config.in @@ -54,6 +54,9 @@ if [ "$CONFIG_ISDNCTRL" = "y" ]; then # bool 'Enable isdnctrl debug-option' CONFIG_ISDNCTRL_DEBUG bool 'Enable configfile-option (uses dbm lib)' CONFIG_ISDNCTRL_CONF bool 'Enable timru-controls' CONFIG_ISDNCTRL_TIMRU + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then + bool 'Enable udp-info-controls' CONFIG_ISDNCTRL_DWABC_UDP_INFO + fi fi bool 'iprofd' CONFIG_IPROFD bool 'divertctrl' CONFIG_DIVERTCTRL