* Linux AX.25 Socket programming
@ 2003-01-01 18:59 Jonathan Naylor
2003-01-01 22:48 ` Kelly Black
2003-01-02 4:37 ` Tomi Manninen
0 siblings, 2 replies; 14+ messages in thread
From: Jonathan Naylor @ 2003-01-01 18:59 UTC (permalink / raw)
To: linux-hams
I have seen some messages on Linux-Hams about AX.25 socket programming
that seem to miss the potential simplicity of it. By this I mean making
use of the existing infrastructure within the ax25-utils/ax25-lib.
AX.25 (and NET/ROM and ROSE) server development can by careful design of
the server be made extremely easy. The program ax25d is exactly
analogous to inetd, in that it can launch programs when an incoming
connection is received. This is controlled by the ax25d.conf file which
also allows for different servers to be started depending on the
incoming interface and/or incoming callsign. The started program only
has to read and write to stdin and stdout respectively, ax25d is also
capable of passing command line arguments to the started program based
on a set of substitution parameters and literal text given in its
configuration file.
This mode of server program assumes that one program will handle one
connection. This makes (usually) for much simpler programs that don't
have to internally multi-task, but then places more complexity into any
needed inter-process communication that may be needed between different
instances of the same server. An example I can think of is for a DX
Cluster implementation, whereby the IPC would be via a database accessed
from all of the instances. Each server could either be multi-threaded
with one thread to listen for incoming commands from the user and the
other thread sending incoming spot data to the user, or alternatively a
polling structure using select(2) with a timeout.
Servers that can be started by ax25d do not need to be in C or C++, but
can be in Perl, Java, Ruby, COBOL or anything else that can read and
write to stdin/stdout.
As a side note, a server designed to be used from ax25d, can just as
easily be started by inetd and therefore be made available to users of
an IP network also. The only caveat would be that the end of line
convention between AX.25 and the Internet are different, I am not sure
if the ax25-lib has support for this, but the alternative would be to
pass an indication of the required EOL character via the command line,
possibly as an incoming connection type e.g. ax25, netrom, rose, inet.
As I said at the beginning this only applies to server programming, for
a client you have to get your hands dirty, and indeed for any program
that needs to monitor traffic like listen.
Jonathan G4KLX
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-01 18:59 Linux AX.25 Socket programming Jonathan Naylor
@ 2003-01-01 22:48 ` Kelly Black
2003-01-01 23:00 ` Andrew Bates
2003-01-02 4:37 ` Tomi Manninen
1 sibling, 1 reply; 14+ messages in thread
From: Kelly Black @ 2003-01-01 22:48 UTC (permalink / raw)
To: Linux Hams mailing list
On Wed, 2003-01-01 at 12:59, Jonathan Naylor wrote:
> AX.25 (and NET/ROM and ROSE) server development can by careful design of
> the server be made extremely easy. The program ax25d is exactly
> analogous to inetd, in that it can launch programs when an incoming
> connection is received. This is controlled by the ax25d.conf file which
> also allows for different servers to be started depending on the
> incoming interface and/or incoming callsign. The started program only
> has to read and write to stdin and stdout respectively, ax25d is also
> capable of passing command line arguments to the started program based
> on a set of substitution parameters and literal text given in its
> configuration file.
Thanks G4KLX!
Excellent!!! Does anybody know where I can find an example of a script
that is doing just this read from stdin and write to stdout.
Sounds like a great way to prototype a server quickly. Neat way to
implement a quick service outside of the regular ones to get emergency
services via a simple scripted telnet client as well!
Kelly
KB0GBJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-01 22:48 ` Kelly Black
@ 2003-01-01 23:00 ` Andrew Bates
2003-01-02 2:12 ` Kelly Black
0 siblings, 1 reply; 14+ messages in thread
From: Andrew Bates @ 2003-01-01 23:00 UTC (permalink / raw)
To: Kelly Black; +Cc: Linux Hams mailing list
> Excellent!!! Does anybody know where I can find an example of a script
> that is doing just this read from stdin and write to stdout.
>
Here is a very simply perl script that reads and writes to the stdin/stdout:
#!/usr/bin/perl
# -- beginning of script
# display our message to the stdout
print "Testing ax25d\n";
print "Please enter your callsign: ";
# read input from the command line, until
# a carriage return is received
$call = (<>);
# remove the trailing carriage return
chomp $call;
# display callsign to the stdout
print "Hello ".$call."!\n";
exit;
# -- end of script
hope that helps, more information about perl can be found at www.perl.com...
other scripting languages (like korn shell) have howto's at the linux
documentation project (www.tldp.org). Any language that can communicate with
*nix's STDIN/STDOUT (C/C++, Java, ksh, sh, bash, perl, etc.) can be used for
AX25d processes.
Andrew
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-01 23:00 ` Andrew Bates
@ 2003-01-02 2:12 ` Kelly Black
2003-01-03 0:44 ` Curt Mills, WE7U
0 siblings, 1 reply; 14+ messages in thread
From: Kelly Black @ 2003-01-02 2:12 UTC (permalink / raw)
To: Linux Hams mailing list
On Wed, 2003-01-01 at 17:00, Andrew Bates wrote:
> > Excellent!!! Does anybody know where I can find an example of a script
> > that is doing just this read from stdin and write to stdout.
> >
>
> Here is a very simply perl script that reads and writes to the stdin/stdout:
>
SNIP---
O.K. Thanks for the tip. Can you get the callsign or other environment
info from the environment ( $ENV ?) as well like a CGI script does.
I will probably still write the program in C though as I was impressed
at how well I was able to view a curses based application via TCP/IP
over AX.25, and was floored by its responsiveness.
One of my reasons for re-writing the existing application is to make
user training simple by providing a simple interface option instead of
just the terse command line option that exists now.
Kelly
KB0GBJ
P.S. The application I am trying to re-create will be a sub-set of
ARES-DATA. I will tailor it for tracking runners in a marathon race.
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-01 18:59 Linux AX.25 Socket programming Jonathan Naylor
2003-01-01 22:48 ` Kelly Black
@ 2003-01-02 4:37 ` Tomi Manninen
2003-01-02 5:13 ` Kelly Black
2003-01-03 6:32 ` Wilbert Knol
1 sibling, 2 replies; 14+ messages in thread
From: Tomi Manninen @ 2003-01-02 4:37 UTC (permalink / raw)
To: linux-hams
On Wed, 1 Jan 2003, Jonathan Naylor wrote:
> Servers that can be started by ax25d do not need to be in C or C++, but
> can be in Perl, Java, Ruby, COBOL or anything else that can read and
> write to stdin/stdout.
One word of caution though: AX.25 connections are so called sequential
packet connections which means that packet boundaries have meaning in the
protocol. To make a long story short, this means that you are yourself
responsible for packetizing the data in correct size chunks.
When you read from stdin, you have to pass the read() system call a buffer
that is larger than any incoming packet might be. Otherwise data will be
lost. See for example axconv where read() is always called with a buffer
of 4096 bytes.
When you write to stdout, you need to make sure you don't write() a buffer
longer than the MTU (or PACLEN). Also, you probably want to avoid a
situation where you write() several short buffers in a row as they will be
sent separately. In axconv I have used the stdio functions for writing
(and buffering) and used setvbuf() to set the effective paclen.
The above holds for C, and I'm not completely sure how you can accomplish
the same in eg. Perl. There was a thread about Perl and ax25d recently on
this list but I have already forgotten what the correct procedure was...
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-02 4:37 ` Tomi Manninen
@ 2003-01-02 5:13 ` Kelly Black
2003-01-03 6:32 ` Wilbert Knol
1 sibling, 0 replies; 14+ messages in thread
From: Kelly Black @ 2003-01-02 5:13 UTC (permalink / raw)
To: Linux Hams mailing list
OK, just to be silly I set up a simple call to fortune in my ax25d.conf
to see what would happen, and had great fun watching the fortune flash
up on the screen and then have the call program exit. This is great
fun! (Although I should get on with writing the program now)...
73's,
Kelly
KB0GBJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-02 2:12 ` Kelly Black
@ 2003-01-03 0:44 ` Curt Mills, WE7U
0 siblings, 0 replies; 14+ messages in thread
From: Curt Mills, WE7U @ 2003-01-03 0:44 UTC (permalink / raw)
To: Kelly Black; +Cc: Linux Hams mailing list
On 1 Jan 2003, Kelly Black wrote:
> O.K. Thanks for the tip. Can you get the callsign or other environment
> info from the environment ( $ENV ?) as well like a CGI script does.
Yes. Very easily:
$display=$ENV{"DISPLAY"};
> I will probably still write the program in C though as I was impressed
> at how well I was able to view a curses based application via TCP/IP
> over AX.25, and was floored by its responsiveness.
Remember though that Perl is a compiled language as well. It just
happens to compile it each time you invoke it. It's very fast.
Perls strongpoint is in ripping apart text and reconstructing it in
various ways. It does most everything else as well.
> One of my reasons for re-writing the existing application is to make
> user training simple by providing a simple interface option instead of
> just the terse command line option that exists now.
There's also PerlTk. Not a bad way to get a program with a GUI up
and running in a hurry.
--
Curt Mills, WE7U hacker_NO_SPAM_@tc.fluke.com
Senior Methods Engineer/SysAdmin
"Lotto: A tax on people who are bad at math!"
"Windows: Microsoft's tax on computer illiterates!" -- WE7U
"The world DOES revolve around me: I picked the coordinate system!"
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-02 4:37 ` Tomi Manninen
2003-01-02 5:13 ` Kelly Black
@ 2003-01-03 6:32 ` Wilbert Knol
2003-01-03 17:17 ` Tomi Manninen OH2BNS
1 sibling, 1 reply; 14+ messages in thread
From: Wilbert Knol @ 2003-01-03 6:32 UTC (permalink / raw)
To: linux-hams
On Thu, 2 Jan 2003, Tomi Manninen wrote:
> the same in eg. Perl. There was a thread about Perl and ax25d recently on
> this list but I have already forgotten what the correct procedure was...
The trick was, to 'unbuffer' the Perl interpreter with:
$|=1;
# or any non-zero value
My Perl Bible says:
English name: $OUTPUT_AUTOFLUSH
If set to any non-zero value, forces a flush after every write or
print on the currently selected output device
I tried out the recently posted Perl script (having 'unbuffered it
first...)
It looks as though AX25 scrambles the '\n', because the script keeps
waiting for input (much
like a Windows shutdown :-)
When I set $/ to any character, the script then gets past the
$call=(<>);
statement once that character appears on stdin.
How does ax25d present end-of-line?
Wilbert, ZL2BSJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 6:32 ` Wilbert Knol
@ 2003-01-03 17:17 ` Tomi Manninen OH2BNS
2003-01-03 20:47 ` Wilbert Knol
0 siblings, 1 reply; 14+ messages in thread
From: Tomi Manninen OH2BNS @ 2003-01-03 17:17 UTC (permalink / raw)
To: Wilbert Knol; +Cc: linux-hams
On Fri, 3 Jan 2003, Wilbert Knol wrote:
> On Thu, 2 Jan 2003, Tomi Manninen wrote:
>
> > the same in eg. Perl. There was a thread about Perl and ax25d recently on
> > this list but I have already forgotten what the correct procedure was...
>
> The trick was, to 'unbuffer' the Perl interpreter with:
Ok, but how about input? Didn't it need something special too?
> How does ax25d present end-of-line?
The standard end-of-line in AX.25 related world is CR (yes, a really
bright idea indeed...). Ax25d doesn't touch that at all so any program
lauched from ax25s needs to do the conversions itself.
--
Tomi Manninen Internet: oh2bns@sral.fi
OH2BNS AX.25: oh2bns@oh2rbi.fin.eu
KP20ME04 Amprnet: oh2bns@oh2rbi.ampr.org
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 17:17 ` Tomi Manninen OH2BNS
@ 2003-01-03 20:47 ` Wilbert Knol
2003-01-03 20:58 ` Kelly Black
2003-01-03 21:02 ` M Taylor
0 siblings, 2 replies; 14+ messages in thread
From: Wilbert Knol @ 2003-01-03 20:47 UTC (permalink / raw)
To: Tomi Manninen OH2BNS; +Cc: linux-hams
> The standard end-of-line in AX.25 related world is CR
Thanks. In that case, in order to make it work with ax25d, Andrew
Bates's Perl script needs to start off like this:
#!/usr/bin/perl
# -- beginning of script
# Un-buffer STDIN:
$|=1;
# Use AX25 EOL:
# (Check the '$/' paragraph in 'man perlvar')
$/="\r";
I found that the AX25 socket gets closed as soon as the script runs
out. The remote end gets a UI disconnect, hot on the heels of the last
Info frame. The remote user never gets to see the result of the script.
A graceful closedown by the remote user would fix that:
print "Hit ENTER to quit:";
$call = (<>);
exit;
# end of script
So, it looks like it _really_ is as easy as advertised by G4KLX! I am
now scripting a search-my-log gizmo :-)
Wilbert, ZL2BSJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 20:47 ` Wilbert Knol
@ 2003-01-03 20:58 ` Kelly Black
2003-01-03 21:02 ` M Taylor
1 sibling, 0 replies; 14+ messages in thread
From: Kelly Black @ 2003-01-03 20:58 UTC (permalink / raw)
To: Wilbert Knol; +Cc: Linux Hams mailing list
On Fri, 2003-01-03 at 14:47, Wilbert Knol wrote:
snip----
> So, it looks like it _really_ is as easy as advertised by G4KLX! I am
> now scripting a search-my-log gizmo :-)
>
>
> Wilbert, ZL2BSJ
>
Thanks! Now I kno why the fortune program would not send more than one
fortune per connect and the call program exited after the first fortune
when I requested multiples.
This ax25d trick can be a great boon to the local AX25 users! I needed
something besides showing converse nodes to the local club at a future
meeting... I think it will spark interest in a few more people in the
club to do other projects as well!
Kelly
KB0GBJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 20:47 ` Wilbert Knol
2003-01-03 20:58 ` Kelly Black
@ 2003-01-03 21:02 ` M Taylor
2003-01-03 22:26 ` Wilbert Knol
1 sibling, 1 reply; 14+ messages in thread
From: M Taylor @ 2003-01-03 21:02 UTC (permalink / raw)
To: Wilbert Knol; +Cc: linux-hams
On Sat, Jan 04, 2003 at 09:47:05AM +1300, Wilbert Knol wrote:
>
>
> > The standard end-of-line in AX.25 related world is CR
>
> # Un-buffer STDIN:
> $|=1;
> # Use AX25 EOL:
> # (Check the '$/' paragraph in 'man perlvar')
> $/="\r";
For portable Perl,
$/ = \015; # CR
because \r and \n can vary across different Perl platforms (e.g. MacOS as
I recall).
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 21:02 ` M Taylor
@ 2003-01-03 22:26 ` Wilbert Knol
2003-01-06 9:28 ` Wilbert Knol
0 siblings, 1 reply; 14+ messages in thread
From: Wilbert Knol @ 2003-01-03 22:26 UTC (permalink / raw)
To: M Taylor; +Cc: linux-hams
On Fri, 3 Jan 2003, M Taylor wrote:
> For portable Perl,
> $/ = \015; # CR
Try:
$/ = "\015";
Perl wants a string. If you give it an integer number, it gets
interpreted as a buffer size....
Wilbert, ZL2BSJ
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: Linux AX.25 Socket programming
2003-01-03 22:26 ` Wilbert Knol
@ 2003-01-06 9:28 ` Wilbert Knol
0 siblings, 0 replies; 14+ messages in thread
From: Wilbert Knol @ 2003-01-06 9:28 UTC (permalink / raw)
To: linux-hams
On a similar note: I am now trying to get a Bash script, started by
the ax25d daemon, to accept input from a user.
The Bash command I am trying to press into service is the 'read'
built-in. The function keeps waiting for a line-feed that never comes.
I have tried things like:
read -d \x0d input_string
read -d \015 input_string
read -d \r input_string
etc etc, without any success.
How can I read user input with the Bash shell?
Wilbert, ZL2BSJ
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2003-01-06 9:28 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-01 18:59 Linux AX.25 Socket programming Jonathan Naylor
2003-01-01 22:48 ` Kelly Black
2003-01-01 23:00 ` Andrew Bates
2003-01-02 2:12 ` Kelly Black
2003-01-03 0:44 ` Curt Mills, WE7U
2003-01-02 4:37 ` Tomi Manninen
2003-01-02 5:13 ` Kelly Black
2003-01-03 6:32 ` Wilbert Knol
2003-01-03 17:17 ` Tomi Manninen OH2BNS
2003-01-03 20:47 ` Wilbert Knol
2003-01-03 20:58 ` Kelly Black
2003-01-03 21:02 ` M Taylor
2003-01-03 22:26 ` Wilbert Knol
2003-01-06 9:28 ` Wilbert Knol
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox