Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: a40b63c513
...
compare: 49e06b9be0
  • 8 commits
  • 14 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 16, 2013
@matthiasl Perl: correct bug introduced by 67481b
The expect_xml function always checked for 'ok', no matter what
the argument was. But this was harmless since the argument always
was 'ok'.
6e69d8c
@matthiasl Perl: add -v switch to all commands for debugging 4f02caf
Commits on Dec 19, 2013
@matthiasl Perl: fix PCap file creation on Windows machines
Windows machines do LF -> CRLF conversion by default. Disable that,
otherwise we get corrupt PCap files.
375c352
Commits on Jan 23, 2014
@matthiasl Fix auto-detection of mingw cross compiler architecture
It was broken on 64 bit linux systems
ef9e90b
@matthiasl Eliminate warnings/update cross compiler code for GCC 4.6.4
The MingGW update to GCC 4.6.4 changes a few things in its
header files which caused warnings in our code; eliminate
those warnings.
65a326d
@matthiasl Fix %z format character so that it works for WIN32 targets 6686966
@matthiasl Teach 'make clean' to remove version.c
This cuts the number of ways you can accidentally release code
with false version strings in it.
06dd300
@matthiasl C: fix usage information for save_to_pcap when piping
Wireshark _can_ capture from stdin or a pipe, but only
if the incoming format is classic Pcap. Pcap-NG doesn't
work. It might work in a future version of Wireshark,
but it doesn't work now (Wireshark 1.10.5).

So: change the examples to nudge people in the right
direction.
49e06b9
View
6 c/Makefile
@@ -32,7 +32,7 @@ CC_WIN32_64bit=i686-w64-mingw32-gcc
# present on older debian systems
CC_WIN32_32bit=i586-mingw32msvc-gcc
-CC_WIN32:=$(shell if test -x $(CC_WIN32_64bit) ; then echo $(CC_WIN32_64bit); else echo $(CC_WIN32_32bit); fi)
+CC_WIN32:=$(shell if test -x `which $(CC_WIN32_64bit)` ; then echo $(CC_WIN32_64bit); else echo $(CC_WIN32_32bit); fi)
LIBS_WIN32=-lws2_32
CC=gcc
@@ -44,7 +44,7 @@ unix: $(target_basenames)
win32: $(win_targets)
clean:
- rm -f $(win_targets) $(target_basenames) *~ *.zip README.dos version.h
+ rm -f $(win_targets) $(target_basenames) *~ *.zip README.dos version.c
ship: version.c
make clean
@@ -53,7 +53,7 @@ ship: version.c
sed -e 's/$$/\r/g' < README.unix > README.txt
zip gth_c_examples *.c *.h NMakefile Makefile audio/* README.* *.exe
-version.c: $(headers)
+version.c:
@echo "#include \"gth_apilib.h\"" > $@
@echo "const char git_head[] = \""$(repo_head)"\";" >> $@
@echo "const char build_hostname[] = \""$(shell hostname)"\";" >> $@
View
6 c/gth_apilib.c
@@ -1583,9 +1583,9 @@ void win32_specific_startup() {
return;
}
-#ifndef _MSC_VER
-// Microsoft use a "more secure" variant of fopen(). So if we're not using
-// a Microsoft compiler, provide a workalike:
+#ifndef WIN32
+// Microsoft use a "more secure" variant of fopen(). So, if we're using
+// gcc for a non-windows target, provide a workalike:
int fopen_s(FILE **file, const char *filename, const char *mode)
{
*file = fopen(filename, mode);
View
19 c/gth_win32_compat.h
@@ -6,7 +6,7 @@
// Case 3. visual studio 2010 native compiling on win32
//
//
-// There are three sources of problems
+// Sources of problems
//
// A. GNU and Microsoft have fixed strcat/strcpy and friends in different
// ways with different names and different argument orders.
@@ -25,6 +25,9 @@
// pragma, but it's unclear whether they always will; GNU don't
// seem to think the #pragma approach is a good idea.
//
+// D. Linux (and other *nix, not sure) have a 'z' format modifier
+// for printing size_t. Windows doesn't.
+//
//
//----------------------------------------------------------------------
@@ -46,9 +49,6 @@
// Cases 1 & 2
#else
-// Workalike for Microsoft's variant of fopen()
-int fopen_s(FILE **file, const char *filename, const char *mode);
-
// GCC's pack pragma is a suffix, which is a bit messy.
#define PACK_SUFFIX __attribute__((__packed__))
@@ -57,11 +57,6 @@ int fopen_s(FILE **file, const char *filename, const char *mode);
//----------------------------------------------------------------------
// Case 2
#if ( !defined(_MSC_VER) && defined(WIN32))
-// Microsoft's sockets API has different names to the normal API, but
-// only if we're cross compiling. (why?)
-#define ENETUNREACH WSAENETUNREACH
-#define ENOTSOCK WSAENOTSOCK
-
#define HANDLE_OR_FILEPTR HANDLE
#endif
//----------------------------------------------------------------------
@@ -69,4 +64,10 @@ int fopen_s(FILE **file, const char *filename, const char *mode);
#ifndef WIN32
#define closesocket close
#define HANDLE_OR_FILEPTR FILE*
+// Workalike for Microsoft's variant of fopen()
+int fopen_s(FILE **file, const char *filename, const char *mode);
+#define SIZE_T_FORMAT "%zu"
+#else
+// Cases 2 and 3
+#define SIZE_T_FORMAT "%Iu"
#endif
View
6 c/save_to_pcap.c
@@ -190,9 +190,9 @@ usage() {
"./save_to_pcap 172.16.1.10 1A 2A 16 1B 5 6 7 8 capture.pcapng\n"
"./save_to_pcap -m 172.16.1.10 1A 2A 16 isup_capture.pcapng\n"
"./save_to_pcap -m -n 1000 172.16.1.10 1A 2A 16 isup_capture.pcapng\n"
- "./save_to_pcap 172.16.1.10 1A 2A 16 - | tshark -V -i - \n"
- "./save_to_pcap 172.16.1.10 1A 2A 16 - | wireshark -k -i - \n"
- "./save_to_pcap 172.16.1.10 1A 2A 16 \\\\.\\pipe\\isup_capture.1\n");
+ "./save_to_pcap -c 172.16.1.10 1A 2A 16 - | tshark -V -i - \n"
+ "./save_to_pcap -c 172.16.1.10 1A 2A 16 - | wireshark -k -i - \n"
+ "./save_to_pcap -c 172.16.1.10 1A 2A 16 \\\\.\\pipe\\isup_capture.1\n");
fprintf(stderr,
"\nExamples (on SDH/SONET hardware, usually optical):\n"
View
2  c/wide_recorder.c
@@ -135,7 +135,7 @@ static void wide_record_a_file(GTH_api *api,
}
if (packet_count++ % 100 == 0) {
- fprintf(stderr, "seq: %d packet_count: %zu seq_errors: %u\n",
+ fprintf(stderr, "seq: %d packet_count: " SIZE_T_FORMAT " seq_errors: %u\n",
seq, packet_count, n_seq_errors);
}
}
View
13 perl/enable.pl
@@ -12,12 +12,13 @@
sub usage() {
print("
-enable.pl <hostname> <resource> [<attribute> [<value>]]
+enable.pl [-v] <hostname> <resource> [<attribute> [<value>]]
<hostname>: the hostname or IP address of a GTH
- <resource>: an SDH/SONET or E1/T1 link on the GTH (hint: 'query inventory')
+ <resource>: an SDH/SONET or E1/T1 link on the GTH (hint: 'query inventory')
<attribute>: optional, the name of an attribute of the given resource
<value>: optional, sets the given attribute of the given resource
+ -v: verbose, for debugging
Multiple <attribute> <value> arguments can be given to set multiple attributes.
@@ -32,13 +33,19 @@ ()
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV >= 1) || usage() && die();
my $host = $ARGV[0];
shift @ARGV;
my $resource = $ARGV[0];
shift @ARGV;
-my $api = new gth_control($host);
+my $api = new gth_control($host, $verbose);
$api->enable($resource, @ARGV);
View
36 perl/gth_control/lib/gth_control.pm
@@ -8,9 +8,12 @@ use Data::Dumper;
use XML::Simple; # From CPAN. In Debian it's called libxml-simple-perl
sub new {
- my ($unused, $gth_ip_or_hostname) = @_;
+ my ($unused, $gth_ip_or_hostname, $verbose) = @_;
my $self = {};
+ $self->{VERBOSE} = $verbose;
+
+ debug($self, "connecting to $gth_ip_or_hostname...");
# Open a socket to the GTH command socket
my $sock = new IO::Socket::INET->new(PeerAddr => $gth_ip_or_hostname,
PeerPort => 2089,
@@ -22,6 +25,7 @@ sub new {
$self->{MY_IP} = inet_ntoa($ia);
bless($self);
+ $self->debug("...connected OK");
return $self;
}
@@ -35,6 +39,14 @@ sub bye {
expect_xml($parsed, "ok", "bye failed");
}
+sub debug {
+ my ($self, $info) = @_;
+
+ if ($self->{VERBOSE}) {
+ print STDERR $info, "\n";
+ }
+}
+
sub delete {
my ($self, $id) = @_;
@@ -79,7 +91,7 @@ sub new_mtp2_monitor {
"<pcm_source span='$span' timeslot='$timeslot'/>".
"</mtp2_monitor></new>");
- my $data_socket = $listen_socket->accept();
+ my $data_socket = $self->accept($listen_socket);
my $job_id = parse_job_id($self->next_non_event());
return ($job_id, $data_socket);
@@ -97,7 +109,7 @@ sub new_player {
"<pcm_sink span='$span' timeslot='$timeslot'/>".
"</player></new>");
- my $data_socket = $listen_socket->accept();
+ my $data_socket = $self->accept($listen_socket);
my $job_id = parse_job_id($self->next_non_event());
return ($job_id, $data_socket);
@@ -116,7 +128,7 @@ sub new_recorder {
"</recorder></new>");
- my $data_socket = $listen_socket->accept();
+ my $data_socket = $self->accept($listen_socket);
my $job_id = parse_job_id($self->next_non_event());
return ($job_id, $data_socket);
@@ -177,7 +189,7 @@ sub set {
my $parsed = $self->next_non_event();
- defined $parsed->{"ok"} || die("set failed");
+ expect_xml($parsed, "ok", "set failed");
}
sub unmap {
@@ -192,10 +204,20 @@ sub unmap {
#-- Internal functions.
+sub accept {
+ my ($self, $listen) = @_;
+
+ $self->debug("waiting for accept...");
+ my $s = $listen->accept();
+ $self->debug("...accepted");
+
+ return $s;
+}
+
sub expect_xml {
my ($parsed, $expected, $hint) = @_;
- if (defined $parsed->{"ok"}) {
+ if (defined $parsed->{$expected}) {
return;
}
printf(STDERR "$hint\n");
@@ -226,6 +248,7 @@ sub send {
if (! defined($type)) {
$type = "text/xml";
+ $self->debug("API command: $data");
}
$s->send("Content-type: $type\r\n");
@@ -245,6 +268,7 @@ sub receive_raw {
my $length = $1;
read($s, my $buffer, $length);
+ $self->debug("XML: $buffer");
length($buffer) == $length || die("definite_read got a short read");
View
8 perl/map.pl
@@ -27,11 +27,17 @@ ()
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV == 1) || usage() && die();
my ($host, $resource) = @ARGV;
-my $api = new gth_control($host);
+my $api = new gth_control($host, $verbose);
my $new_name = $api->map($resource);
print "$new_name\n";
View
15 perl/play.pl
@@ -12,12 +12,13 @@
sub usage() {
print("
-play <hostname> <span> <timeslot> <filename>
+play [-v] <hostname> <span> <timeslot> <filename>
<hostname>: the hostname or IP address of a GTH
<span>: the name of an E1/T1, e.g. 1A or 4D on a GTH 2.x
<timeslot>: 1--31 on an E1 or 1--24 on a T1
<filename>: which file to write the data to. - means stdin
+ -v: verbose, for debugging
Typical invocation: ./play 172.16.1.10 1A 16 signalling.raw
");
@@ -42,8 +43,8 @@ sub warn_if_l1_dead {
}
sub play {
- my ($host, $span, $timeslot, $file) = @_;
- my $api = new gth_control($host);
+ my ($host, $span, $timeslot, $file, $verbose) = @_;
+ my $api = new gth_control($host, $verbose);
warn_if_l1_dead($api, $span);
my ($player_id, $data) = $api->new_player($span, $timeslot);
@@ -73,6 +74,12 @@ sub play {
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV == 3) || usage() && die();
my $host = $ARGV[0];
@@ -85,5 +92,5 @@ sub play {
open($file, $ARGV[3]) || die("can't open $ARGV[3]");
}
-play($ARGV[0], $ARGV[1], $ARGV[2], $file);
+play($ARGV[0], $ARGV[1], $ARGV[2], $file, $verbose);
View
11 perl/query_set.pl
@@ -12,12 +12,13 @@
sub usage() {
print("
-query_set.pl <hostname> <resource> [<attribute> [<value>]]
+query_set.pl [-v] <hostname> <resource> [<attribute> [<value>]]
<hostname>: the hostname or IP address of a GTH
<resource>: the name of a resource on the GTH
<attribute>: optional, the name of an attribute of the given resource
<value>: optional, sets the given attribute of the given resource
+ -v: verbose; for debugging
If no <value> argument is given, just query the GTH.
If a <value> argument is given, set the <attribute> to the <value>
@@ -33,11 +34,17 @@ ()
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV >= 1) || usage() && die();
my $host = $ARGV[0];
my $resource = $ARGV[1];
-my $api = new gth_control($host);
+my $api = new gth_control($host, $verbose);
if ($#ARGV == 1) {
if ($resource eq "inventory") {
View
19 perl/record.pl
@@ -12,13 +12,14 @@
sub usage() {
print("
-record <hostname> <span> <timeslot> <octets> <filename>
+record [-v] <hostname> <span> <timeslot> <octets> <filename>
<hostname>: the hostname or IP address of a GTH
<span>: the name of an E1/T1, e.g. 1A or 4D on a GTH 2.x
<timeslot>: 1--31 on an E1 or 1--24 on a T1
<octets>: how many octets to record. There are 8000 per second
<filename>: which file to write the data to. - means stdout
+ -v: verbose; show debugging information
Typical invocation: ./record.pl 172.16.1.10 1A 16 16000 signalling.raw
");
@@ -45,8 +46,8 @@ sub warn_if_l1_dead {
}
sub record {
- my ($host, $span, $timeslot, $octets_wanted, $file) = @_;
- my $api = new gth_control($host);
+ my ($host, $span, $timeslot, $octets_wanted, $file, $verbose) = @_;
+ my $api = new gth_control($host, $verbose);
warn_if_l1_dead($api, $span);
my ($recorder_id, $data) = $api->new_recorder($span, $timeslot);
@@ -54,20 +55,28 @@ sub record {
my $buffer = "";
while ($octets_received < $octets_wanted) {
+ $api->debug("waiting for $octets_wanted bytes...");
read($data, $buffer, $octets_wanted) || die("socket read failed");
+ $api->debug("...got $octets_wanted bytes");
$octets_received += length($buffer);
print $file $buffer;
}
close($file);
close($data);
- print "recorder_id is $recorder_id\n";
+
$api->delete($recorder_id);
print STDERR "All done, saved $octets_received octets\n";
$api->bye();
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV == 4) || usage() && die();
my $host = $ARGV[0];
@@ -80,4 +89,4 @@ sub record {
open($file, ">", $ARGV[4]) || die("can't open $ARGV[4]");
}
-record($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $file);
+record($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $file, $verbose);
View
20 perl/save_to_pcap.pl
@@ -23,11 +23,13 @@
sub usage() {
print("
- save_to_pcap.pl <hostname> <span> <timeslot> <filename>
+ save_to_pcap.pl [-v] <hostname> <span> <timeslot> <filename>
+
<hostname>: the hostname or IP address of a GTH
<span>: the name of an E1/T1, e.g. 1A or 4D on a GTH 2.x
<timeslot>: 1--31 on an E1 or 1--24 on a T1
<filename>: a writeable file; - means standard output
+ -v: verbose; enables debugging output
Typical invocation #1: ./save_to_pcap.pl 172.16.1.10 1A 16 /tmp/captured.pcap
Typical invocation #2: ./save_to_pcap.pl 172.16.1.10 1A 16 - | tshark -i -
@@ -76,9 +78,9 @@ sub write_pcap_global_header {
}
sub monitor_mtp2 {
- my ($host, $span, $timeslot, $filename) = @_;
+ my ($host, $span, $timeslot, $filename, $verbose) = @_;
- my $api = gth_control->new($host);
+ my $api = gth_control->new($host, $verbose);
my $file;
warn_if_l1_dead($api, $span);
@@ -89,13 +91,16 @@ sub monitor_mtp2 {
} else {
open($file, ">", $filename) || die("can't open $filename");
}
+ binmode($file);
write_pcap_global_header($file);
my ($mtp2_id, $data) = $api->new_mtp2_monitor($span, $timeslot);
while (1) {
+ $api->debug("waiting for a packet...");
read($data, my $b, 2);
+ $api->debug("...got a header");
my $length = unpack("n", $b);
read($data, my $packet, $length);
@@ -116,6 +121,7 @@ sub monitor_mtp2 {
print $file $pcap_packet_header;
my $payload = substr($packet, 10); # strip the GTH header
print $file $payload;
+ $file->flush();
}
$api->delete($mtp2_id);
@@ -124,10 +130,16 @@ sub monitor_mtp2 {
$api->bye();
}
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
# Entry point
if ($#ARGV + 1 != 4) {
usage();
exit(-1);
}
-monitor_mtp2($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);
+monitor_mtp2($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $verbose);
View
18 perl/sniff_isup.pl
@@ -16,10 +16,11 @@
sub usage() {
print("
- sniff_isup.pl <hostname> <span> <timeslot>
+ sniff_isup.pl [-v] <hostname> <span> <timeslot>
<hostname>: the hostname or IP address of a GTH
<span>: the name of an E1/T1, e.g. 1A or 4D on a GTH 2.x
<timeslot>: 1--31 on an E1 or 1--24 on a T1
+ -v: verbose; print debug information
Typical invocation: ./sniff_isup.pl 172.16.1.10 1A 16
");
@@ -141,17 +142,18 @@ sub isup_ignore {
}
sub monitor_mtp2 {
- my ($host, $span, $timeslot) = @_;
+ my ($host, $span, $timeslot, $verbose) = @_;
- my $api = gth_control->new($host);
+ my $api = gth_control->new($host, $verbose);
warn_if_l1_dead($api, $span);
my ($mtp2_id, $data) = $api->new_mtp2_monitor($span, $timeslot);
-
while (1) {
+ $api->debug("waiting for a packet...");
read($data, my $b, 2);
+ $api->debug("...got a header");
my $length = unpack("n", $b);
read($data, my $packet, $length);
decode_mtp2($packet);
@@ -164,9 +166,15 @@ sub monitor_mtp2 {
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
if ($#ARGV + 1 != 3) {
usage();
die();
}
-monitor_mtp2($ARGV[0], $ARGV[1], $ARGV[2]);
+monitor_mtp2($ARGV[0], $ARGV[1], $ARGV[2], $verbose);
View
8 perl/unmap.pl
@@ -24,11 +24,17 @@ ()
}
# Entry point
+my $verbose = 0;
+if ($ARGV[0] eq "-v") {
+ $verbose = 1;
+ shift @ARGV;
+}
+
($#ARGV == 1) || usage() && die();
my ($host, $resource) = @ARGV;
-my $api = new gth_control($host);
+my $api = new gth_control($host, $verbose);
$api->unmap($resource);
$api->bye();

No commit comments for this range

Something went wrong with that request. Please try again.