From a3aa74b3b9c40569dc778857cf4d02628db22e70 Mon Sep 17 00:00:00 2001 From: tonton Th Date: Tue, 14 Apr 2020 11:08:52 +0200 Subject: [PATCH 1/3] converting to python3 --- tools/relay.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/relay.py b/tools/relay.py index 1d9c341..c745236 100755 --- a/tools/relay.py +++ b/tools/relay.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import socket, sys, getopt @@ -19,11 +19,11 @@ arguments = sys.argv[1:] opts, args = getopt.getopt(arguments, options) for o, a in opts: - print ' ', o, ' --> ', a + print (' ', o, ' --> ', a) if "-v" == o: verbose += 1 elif "-p" == o: rx_port = int(a) -print "listening port : ", rx_port +print ("listening port : ", rx_port) # --- @@ -34,7 +34,7 @@ for ligne in open("destinations.liste"): if p: cibles.append((a, int(p))) for cible in cibles: - print " -> ", cible + print (" -> ", cible) # point d'entree, d'ecoute @@ -49,7 +49,7 @@ sock_tx = socket.socket(socket.AF_INET, # Internet while True: data, addr = sock_rx.recvfrom(1024) # buffer size is 1024 bytes if verbose: - print "got:", addr, " ", len(data) + print ("got:", addr, " ", len(data)) for cible in cibles: # print cible sock_tx.sendto(data, cible) From 1b26e5b3280aa2f5d8b4ddb79a76d900eab5fe78 Mon Sep 17 00:00:00 2001 From: tonton Th Date: Tue, 14 Apr 2020 13:07:21 +0200 Subject: [PATCH 2/3] adding udp-dumper.c --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 69f2256..65085b8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ doc/*.ilg doc/*.ind functions/*.[oa] + +tools/udp-dumper + From 2ce7b5dd1409b0cb68420538c8d0c5d756d8b495 Mon Sep 17 00:00:00 2001 From: tonton Th Date: Tue, 14 Apr 2020 13:07:57 +0200 Subject: [PATCH 3/3] adding udp-dumper.c bis --- tools/Makefile | 8 +++ tools/README.md | 11 +++++ tools/udp-dumper.c | 121 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 tools/Makefile create mode 100644 tools/README.md create mode 100644 tools/udp-dumper.c diff --git a/tools/Makefile b/tools/Makefile new file mode 100644 index 0000000..8498370 --- /dev/null +++ b/tools/Makefile @@ -0,0 +1,8 @@ +# +# Various OSC tools +# + +# https://git.tetalab.org/tTh/gadgets-OSC + +udp-dumper: udp-dumper.c Makefile + gcc -Wall $< -o $@ diff --git a/tools/README.md b/tools/README.md new file mode 100644 index 0000000..3817bb3 --- /dev/null +++ b/tools/README.md @@ -0,0 +1,11 @@ +# Various OSC tools + + +## relay.py + +Quick hack build with a disgusting language. + +## udp-dumper + +This is not really an OSC dedicated tools, but a general purpose one. + diff --git a/tools/udp-dumper.c b/tools/udp-dumper.c new file mode 100644 index 0000000..3f41ec5 --- /dev/null +++ b/tools/udp-dumper.c @@ -0,0 +1,121 @@ +/* + * general purpose UDP dumper + * + * made by tTh, around 2019... + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PORT 5002 +#define BUFLEN 1024 + +int verbosity = 0; + +/* ----------------------------------------------------------------- */ +int dumpln(unsigned char *ptr) +{ +int foo; + +for (foo=0; foo<16; foo++) + printf("%02x ", ptr[foo]); + +printf("| "); +for (foo=0; foo<16; foo++) + if (isprint(ptr[foo])) putchar(ptr[foo]); + else putchar('.'); + +printf(" |\n"); +return 0; +} +/* ----------------------------------------------------------------- */ +void udp_dumper(uint16_t port) +{ +unsigned char buffer[BUFLEN]; +struct sockaddr_in si_me, si_other; +int sock, foo, bar, flag_exit; +unsigned int slen=sizeof(si_other); +long serial; +double starttime, curtime; +struct timeval tp; + +if (-1==(sock=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))) { + perror("socket fail "); + exit(1); + } + +#if DEBUG_LEVEL +fprintf(stderr, "port %d / sock -> %d\n", port, sock); +#endif + +memset((char *) &si_me, 0, sizeof(si_me)); +si_me.sin_family = AF_INET; +si_me.sin_port = htons(port); +si_me.sin_addr.s_addr = htonl(INADDR_ANY); +if (bind(sock, (struct sockaddr *)&si_me, sizeof(si_me))==-1) { + perror("'bind' failure "); + exit(1); + } + +flag_exit = 0; serial = 0L; + +gettimeofday(&tp, NULL); +starttime = tp.tv_sec + tp.tv_usec / 1e6; + +do { + memset(buffer, 0, BUFLEN); + slen = sizeof(si_other); + foo = recvfrom(sock, buffer, BUFLEN, 0, + (struct sockaddr *)&si_other, &slen); + + if (verbosity) { + gettimeofday(&tp, NULL); + curtime = tp.tv_sec + tp.tv_usec / 1e6; + printf("----+ %5d b ts: %.3f\n", foo, curtime - starttime); + } + + for (bar=0; bar<=foo; bar+=16) { + printf("%3ld | ", serial); + dumpln(buffer+bar); + } + serial++; + } while ( !flag_exit); +} +/* ----------------------------------------------------------------- */ +void help(int foo) +{ +puts("\t-h\tthis help text"); +puts("\t-p NNNN\treceiving port number"); +puts("\t-v\tincrease verbosity"); +exit(0); +return ; +} +/* ----------------------------------------------------------------- */ +int main(int argc, char *argv[]) +{ +int opt, port; + +port = PORT; +/* parsing command line options */ +while ((opt = getopt(argc, argv, "hp:v")) != -1) { + switch (opt) { + case 'h': help(0); break; + case 'p': port = atoi(optarg); break; + case 'v': verbosity++; break; + default: exit(1); + } + } + + +udp_dumper(port); + +return 0; +} +/* ----------------------------------------------------------------- */ +