Merge branch 'master' of ssh://tetalab.org:2213/tTh/gadgets-OSC

expect garbage !
This commit is contained in:
tth 2020-10-09 02:38:37 +02:00
commit 7d961bc79f
5 changed files with 148 additions and 5 deletions

3
.gitignore vendored
View File

@ -15,3 +15,6 @@ doc/*.ilg
doc/*.ind
functions/*.[oa]
tools/udp-dumper

8
tools/Makefile Normal file
View File

@ -0,0 +1,8 @@
#
# Various OSC tools
#
# https://git.tetalab.org/tTh/gadgets-OSC
udp-dumper: udp-dumper.c Makefile
gcc -Wall $< -o $@

11
tools/README.md Normal file
View File

@ -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.

View File

@ -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)

121
tools/udp-dumper.c Normal file
View File

@ -0,0 +1,121 @@
/*
* general purpose UDP dumper
*
* made by tTh, around 2019...
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#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;
}
/* ----------------------------------------------------------------- */