Set the Phone line to what you want! (UNIX PC source)

Lenny Tropiano lenny at icus.UUCP
Mon Apr 4 11:10:27 AEST 1988


-----------------------------------------------------------------------
Prerequisite:  Must be running the 3.51 release of the Operating System
-----------------------------------------------------------------------

This source will allow you to set the phone line (that you use for both
VOICE and DATA) to what you want.  Unlike, phtoggle, which just toggles the
setting, this program supplied with the argument of either VOICE or DATA,
will set the line to that.  This can be use within a cron script, or
a /etc/rc startup script to set the line to the particular setting depending
on the time.

Edit the Makefile if and add -DSINGLE_LINE to the CFLAGS definition if you
are using only /dev/ph0 for VOICE and DATA.  Otherwise just type:  make install
as root.

--- cut here --- --- cut here --- --- cut here --- --- cut here ---

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  Makefile phset.c
# Wrapped by lenny at icus on Sun Apr  3 21:06:03 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(653 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile to compile phset.c  (Phone Set)
X# By Lenny Tropiano
X# (c)1988 ICUS Computer Group     UUCP:  ...icus!lenny
X#
X# add -DSINGLE_LINE to CFLAGS if using only /dev/ph0 as the line to toggle, 
X#                   else leave undefined.
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
XDEST=/usr/lbin/
X#
Xphset.o:
X	$(CC) $(CFLAGS) -c phset.c
X#
Xphset:  phset.o
X	@echo "Loading ..."
X	$(LD) $(LDFLAGS) -o phset phset.o $(LIBS) 
X#
X# Need to be root for this
X#
X/usr/lbin:
X	mkdir /usr/lbin
X#
Xinstall: phset /usr/lbin
X	cp phset ${DEST}
X	chown root ${DEST}/phset
X	chgrp bin  ${DEST}/phset
X	chmod 4755 ${DEST}/phset
X#
Xclean:
X	rm -f phset *.o *.shar
END_OF_Makefile
if test 653 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f phset.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phset.c\"
else
echo shar: Extracting \"phset.c\" \(3497 characters\)
sed "s/^X//" >phset.c <<'END_OF_phset.c'
X/************************************************************************\
X**                                                                      **
X** Program name: phset.c (Phone line set)                               **
X** Programmer:   Lenny Tropiano            UUCP: ...icus!lenny          **
X** Organization: ICUS Computer Group       (c)1988                      **
X** Date:         April 3, 1988                                          **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Program use:  Program is run to set the phone line to a specific     **
X**               setting.  This checks the phone line status to         **
X**               see what the line is set at currently, and calls       **
X**               /usr/bin/phtoggle if necessary.  This will solve the   **
X**               problems inherent in using phtoggle in your crontab    **
X**               to adjust the line status.  If the status gets to the  **
X**               wrong setting you'll be toggling to the wrong setting. **
X**                                                                      **
X**************************************************************************
X** Permission is granted to distribute this program by any means as     **
X** long as credit is given for my work.     I would also like to see    **
X** any modifications or enhancements to this program.                   **
X\************************************************************************/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ph.h>
X#include <sys/phone.h>
X#include <nlist.h>
X
X#define PHNDEF	0
X#define	UNIX	"/unix"
X#define	KMEM	"/dev/kmem"
X
X#ifdef	SINGLE_LINE			/* if defined, then check ph0 */
X# 	define	OFFSET	0
X#else					/* else, then check ph1       */
X#	define	OFFSET	sizeof(struct phdef)
X#endif
X
Xstruct nlist unixsym[] = {		/* /unix name list of symbols */
X    { "phndef", },
X    { NULL, },
X};
X
Xmain(argc,argv)
Xint   argc;
Xchar *argv[];
X{
X	void	read_kmem();
X	struct  phdef   phblock;
X	int 	kmem; 
X	ushort	phone_mode;
X
X	if (argc != 2) {
X		printf("usage: %s [VOICE|DATA]\n", argv[0]);
X		exit(1);
X	}
X
X	if (strcmp(argv[1],"VOICE") != 0 &&
X	    strcmp(argv[1],"DATA") != 0) {
X		printf("usage: %s [VOICE|DATA]\n", argv[0]);
X		exit(1);
X	}
X
X	/*
X	 * Open unix namelist.
X	 */
X
X	if (nlist(UNIX, unixsym) < 0) {
X		fprintf(stderr, "%s: no namelist.\n", UNIX);
X		exit(1);
X	}
X
X	/*
X	 * Open kernel memory.
X	 */
X
X	if ((kmem = open(KMEM, 0)) < 0) {
X		perror(KMEM);
X		exit(1);
X	}
X
X	/*
X	 * Read memory location out of /dev/kmem.
X	 */
X
X   	read_kmem(kmem, &phblock, 
X		 (unixsym[PHNDEF].n_value + OFFSET), 
X		 (long)sizeof (struct phdef));
X
X	if (phblock.p_lineparam & DATA) {         /* check to see if DATA     */
X		if (strcmp(argv[1],"DATA") == 0)  /* do you want it this way? */
X			exit(0);
X	} else {			          /* it must be VOICE then    */
X		if (strcmp(argv[1],"VOICE") == 0) /* do you want it this way? */
X			exit(0);
X	}
X
X	/* if not set, call phtoggle, to change mode */
X
X	putenv("IFS=\" \n\t\"");	/* prevent any security breaches */
X
X	execl("/usr/bin/phtoggle","phtoggle", 0);
X
X	perror("execl() failed");
X
X}
X
Xvoid read_kmem(fd, caddr, kaddr, nbytes)
Xint  fd;
Xchar *caddr;
Xlong kaddr;
Xlong nbytes;
X{
X	if (lseek(fd, kaddr, 0)<0L ||
X	    read(fd, caddr, (unsigned)nbytes) != nbytes ) 
X	      perror("can't read /dev/kmem");
X}
X
END_OF_phset.c
if test 3497 -ne `wc -c <phset.c`; then
    echo shar: \"phset.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
US MAIL  : Lenny Tropiano, ICUS Computer Group        IIIII  CCC U   U  SSS
           PO Box 1                                     I   C    U   U S
	   Islip Terrace, New York  11752               I   C    U   U  SS 
PHONE    : (516) 968-8576 [H] (516) 582-5525 [W]        I   C    U   U    S
TELEX    : 154232428 [ICUS]                           IIIII  CCC  UUU  SSS 
AT&T MAIL: ...attmail!icus!lenny  
UUCP     : ...{mtune, ihnp4, boulder, talcott, sbcs, bc-cis}!icus!lenny 



More information about the Unix-pc.sources mailing list