Index: kiss/kissattach.8
===================================================================
RCS file: /home/ax25-cvs/ax25-tools/kiss/kissattach.8,v
retrieving revision 1.3
diff -u -r1.3 kissattach.8
--- kiss/kissattach.8	26 Sep 2008 16:48:11 -0000	1.3
+++ kiss/kissattach.8	11 Sep 2009 08:46:42 -0000
@@ -1,63 +1,93 @@
-.TH KISSATTACH 8 "4 July 1999" Linux "Linux System Managers Manual"
+.TH KISSATTACH 8 "11 Sep 2009" Linux "Linux System Managers Manual"
 .SH NAME
 kissattach, spattach \- Attach a KISS or 6PACK interface
 .SH SYNOPSIS
-.B kissattach [-b] [-6] [-l] [-m mtu] [-v] tty port [inetaddr]
-.sp
-.B spattach [-b] [-l] [-m mtu] [-v] tty port [inetaddr]
+.IP \fBkissattach\fR 12em
+.RB [ \-6 ]
+.RB [ \-l ]
+.RB [ \-b ]
+.RB [ "\-m \fImtu\fR" ]
+.RB [ \-v ]
+.RI { tty | \- }
+.RI { axport | callsign }
+.RI [ inetaddr ]
+.LP
+.IP \fBspattach\fR 10em
+.RB [ "\-i \fIinetaddr\fR" ]
+.RB [ \-l ]
+.RB [ "\-m \fImtu\fR" ]
+.RB [ \-b ]
+.RB [ \-v ]
+.RI { tty | \- }
+.RI { axport | callsign }
+.LP
 .SH DESCRIPTION
 .LP
 Attach a KISS or a 6PACK interface to what is normally a tty line connected
 to a TNC in KISS or 6PACK mode. This program will turn itself into a
 background process. To down an interface send its attach process a SIGTERM.
 .LP
-.B Kissattach
-takes many of the parameters for the port from the axports(5) file. If the
-speed parameter in the file is not equal to zero then it is used for the
-serial port speed, a zero value means that no speed is set. The paclen
-parameter is used for the device mtu unless overridden by a value on the
-command line.
-.LP
-The tty argument will typically be that of a serial port with a KISS or 6PACK
-TNC attached, although it could be a pseudo tty or a KISS port emulator such as
-an SCC card. Kissattach supports BSD-style pseudo-terminals as well as
-the Unix98 pty's. If the tty argument is "/dev/ptmx", then Unix98 behaviour
-will automaticaly take effekt. With Unix98 pty's, the slave tty name
-could not be forseen. That's why kissattach will print the corresponding slave
-pty name as a separate line on stdout.
-.LP
-The port argument is the name of a port as given in the
-axports(5) file.
-.LP
-The optional inetaddr argument is the IP address of the new interface. Some
-time it was mandatory argument (although due to historical reasons this
-restriction is lifted if the old -i option is used). But there's really not
-a need for the interface to have an IP address assigned to.
+The
+.B kissattach
+takes many of the parameters for the port from the
+.BR axports (5)
+file.
+If the
+.I speed
+parameter in the file is not equal to zero then it is used for
+the serial port speed, a zero value means that no speed is set.
+The
+.I paclen
+parameter is used for the device mtu unless overridden by a value
+on the command line.
+.LP
+The
+.I tty
+argument will typically be that of a serial port with a KISS or 6PACK
+TNC attached, although it could be a pseudo tty or a KISS port emulator
+such as an SCC card.
+Alternative to tty is "\-", which is special designator for "use stdin for IO",
+and used by
+.BR mkiss (8).
+.LP
+The
+.I axport
+arguments is the name of a port as given in the
+.BR axports (5)
+file, or alternatively the
+.I callsign
+parameter in the same file.
+(Port names and callsigns are both unique, and have 1-on-1 matching.)
+.LP
+The optional
+.I inetaddr
+argument is the IP address of the new interface, and unless you really
+want to have an IP address on an AX.25 interface, you should not set any!
 .SH OPTIONS
 .TP 16
 .BI "\-6"
 Use the 6PACK line discipline instead of KISS. This is the default if
 the program is called as spattach.
 .TP 16
-.BI "\-i inetaddr"
+.BI "\-b"
+Allow broadcasts on the interface (default no - because several IP softwares
+are doing their own broadcasts on all IP capable interfaces.)
+.TP 16
+.BI "\-i " inetaddr
 Set the internet address of the interface. This address may either be a
 dotted decimal address or a host name. This option is now depreciated and
 the program will complain about it, though still work.
 .TP 16
-.BI \-l
+.BI "\-l"
 Log messages to the system log, the default is not to.
 .TP 16
-.BI \-b
-Allow broadcasts on the interface (default no - because for e.g. samba
-broadcasts are a pain..)
-.TP 16
-.BI "\-m mtu"
+.BI "\-m " mtu
 Sets the mtu of the interface. If this value is not given then the value is
 taken from the paclen parameter in axports.
 .TP 16
-.BI \-v
+.BI "\-v"
 Display the version.
-.SH "SEE ALSO"
+.SH SEE ALSO
 .BR kill (1),
 .BR stty (1),
 .BR ax25 (4),
@@ -66,7 +96,14 @@
 .BR ifconfig (8).
 .SH AUTHOR
 .nf
-Alan Cox GW4PTS <alan@cymru.net>
+Alan Cox GW4PTS, 1990es
+.br
+Jonathan Naylor G4KLX, 1990es
+.br
+Matti Aarnio OH2MQK, 2009
+.br
+Ralf Baechle DL5RB, 2009
+.br
+Thomas Osterried DL9SAU, 2009
 .br
-Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>
 .fi
Index: kiss/kissattach.c
===================================================================
RCS file: /home/ax25-cvs/ax25-tools/kiss/kissattach.c,v
retrieving revision 1.9
diff -u -r1.9 kissattach.c
--- kiss/kissattach.c	21 Jun 2009 18:01:55 -0000	1.9
+++ kiss/kissattach.c	11 Sep 2009 08:46:42 -0000
@@ -1,3 +1,19 @@
+/*
+ *  kissattach/spattach
+ *
+ *  Associate a  serial-port  with kernel AX.25 KISS line discipline.
+ *  Said port can be: real physical serial port, or pty emulation, or
+ *  perhaps even a SCC driver.
+ *
+ *  Written by 
+ *    Alan Cox GW4PTS <alan@cymru.net>
+ *    Jonathan Naylor G4KLX <g4klx@g4klx.demon.co.uk>
+ *  some time in early 1990es
+ *
+ * And hacked upon by a horde of dozens ever since..
+ *
+ */
+
 #include <stdio.h>
 #define __USE_XOPEN
 #include <stdlib.h>
@@ -33,15 +49,16 @@
 #endif
 
 static char *callsign;
-static int  speed	= 0;
-static int  mtu		= 0;
-static int  logging	= FALSE;
-static char *progname	= NULL;
-static char *kttyname	= NULL;
-static char *portname	= NULL;
-static char *inetaddr	= NULL;
-static int allow_broadcast = 0;
-static int i_am_unix98_pty_master = 0; /* unix98 ptmx support */
+static int  speed;
+static int  mtu;
+static int  logging;
+static char *progname;
+static char *kttyname;
+static char *portname;
+static char *inetaddr;
+static int allow_broadcast;
+static int i_am_unix98_pty_master; /* unix98 ptmx support */
+static int use_stdin;
 
 static char *kiss_basename(char *s)
 {
@@ -75,6 +92,7 @@
 	}
 
 	while (fgets(buffer, 90, fp) != NULL) {
+		int found = 0;
 		n++;
 	
 		if ((s = strchr(buffer, '\n')) != NULL)
@@ -85,21 +103,28 @@
 
 		if ((s = strtok(buffer, " \t\r\n")) == NULL) {
 			fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n);
+			fclose(fp);
 			return FALSE;
 		}
 		
-		if (strcmp(s, port) != 0)
-			continue;
-			
+		found = (strcmp(s, port) == 0);
+
 		if ((s = strtok(NULL, " \t\r\n")) == NULL) {
 			fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n);
+			fclose(fp);
 			return FALSE;
 		}
 
 		callsign = strdup(s);
 
+		if (!found && (strcmp(callsign, port) != 0)) {
+			/* Neither PORT name nor CALLSIGN matched on  axports  file.  */
+			continue;
+		}
+
 		if ((s = strtok(NULL, " \t\r\n")) == NULL) {
 			fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n);
+			fclose(fp);
 			return FALSE;
 		}
 
@@ -107,12 +132,14 @@
 
 		if ((s = strtok(NULL, " \t\r\n")) == NULL) {
 			fprintf(stderr, "%s: unable to parse line %d of the axports file\n", progname, n);
+			fclose(fp);
 			return FALSE;
 		}
 
 		if (mtu == 0) {
 			if ((mtu = atoi(s)) <= 0) {
 				fprintf(stderr, "%s: invalid paclen setting\n", progname);
+				fclose(fp);
 				return FALSE;
 			}
 		}
@@ -214,7 +241,7 @@
 
 static void usage(void)
 {
-        fprintf(stderr, "usage: %s [-b] [-l] [-m mtu] [-v] tty port [inetaddr]\n", progname);
+        fprintf(stderr, "usage: %s [-b] [-l] [-m mtu] [-v] {ttyinterface|-} {axport|callsign} [inetaddr]\n", progname);
 }
 
 int main(int argc, char *argv[])
@@ -256,8 +283,7 @@
 			case 'v':
 				printf("%s: %s\n", progname, VERSION);
 				return 0;
-			case ':':
-			case '?':
+			default:
 				usage();
 				return 1;
 		}
@@ -275,28 +301,35 @@
 	kttyname = argv[optind++];
 	portname = argv[optind++];
 
+	if (!readconfig(portname)) {
+		fprintf(stderr, "%s: device/callsign %s is not known\n", progname, portname);
+		return 1;
+	}
+
+	use_stdin = (strcmp(kttyname,"-") == 0);
+
+
 	if (argc-1 >= optind && !inetaddr)
 		inetaddr = argv[optind];
 
 	if (!strcmp("/dev/ptmx", kttyname))
 		i_am_unix98_pty_master = 1;
 
-	if (!i_am_unix98_pty_master) {
+	if (!i_am_unix98_pty_master && !use_stdin) {
 		if (tty_is_locked(kttyname)) {
 			fprintf(stderr, "%s: device %s already in use\n", progname, kttyname);
 			return 1;
 		}
 	}
 
-	if (!readconfig(portname))
-		return 1;
-
         if (inetaddr && (hp = gethostbyname(inetaddr)) == NULL) {
 		fprintf(stderr, "%s: invalid internet name/address - %s\n", progname, inetaddr);
 		return 1;
 	}
 
-	if ((fd = open(kttyname, O_RDONLY | O_NONBLOCK)) == -1) {
+	if (use_stdin) {
+		fd = 0;
+	} else if ((fd = open(kttyname, O_RDONLY | O_NONBLOCK)) < 0) {
 		if (errno == ENOENT) {
 			fprintf(stderr, "%s: Cannot find serial device %s, no such file or directory.\n", progname, kttyname);
 		} else {
@@ -372,16 +405,16 @@
 		fprintf(stderr, "%s: cannot become a daemon\n", progname);
 		return 1;
 	}
-	if (!i_am_unix98_pty_master) {
+	if (!i_am_unix98_pty_master && !use_stdin) {
 		if (!tty_lock(kttyname))
 			return 1;
 	}
 
 	fflush(stdout);
 	fflush(stderr);
-	close(0);
-	close(1);
-	close(2);
+	if (fd != 0) close(0);
+	if (fd != 1) close(1);
+	if (fd != 2) close(2);
 
 	while (1)
 		sleep(10000);
