forked from OpenResearchInstitute/ka9q-radio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadump.c
75 lines (63 loc) · 1.63 KB
/
metadump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// $Id: metadump.c,v 1.2 2018/12/12 08:38:42 karn Exp karn $
// Utility to trace multicast SDR metadata
// Copyright 2018 Phil Karn, KA9Q
#define _GNU_SOURCE 1
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include <pthread.h>
#include <string.h>
#if defined(linux)
#include <bsd/string.h>
#endif
#include <math.h>
#include <complex.h>
#undef I
#include <sys/time.h>
#include <ncurses.h>
#include <ctype.h>
#include <sys/socket.h>
#include <netdb.h>
#include <locale.h>
#include "misc.h"
#include "multicast.h"
#include "status.h"
int Status_sock;
int Verbose,Dump;
char Locale[256] = "en_US.UTF-8";
int main(int argc,char *argv[]){
int c;
while((c = getopt(argc,argv,"vd")) != EOF){
switch(c){
case 'v':
Verbose++;
break;
}
}
{
char const * const cp = getenv("LANG");
if(cp != NULL){
strlcpy(Locale,cp,sizeof(Locale));
}
}
setlocale(LC_ALL,Locale); // Set either the hardwired default or the value of $LANG if it exists
fprintf(stderr,"Listening to %s\n",argv[optind]);
Status_sock = setup_mcast(argv[optind],NULL,0,0,2);
struct sockcache sc;
for(;;){
unsigned char buffer[8192];
memset(buffer,0,sizeof(buffer));
struct sockaddr_storage source;
socklen_t len = sizeof(source);
int length = recvfrom(Status_sock,buffer,sizeof(buffer),0,(struct sockaddr *)&source,&len);
if(length <= 0){
sleep(1);
continue;
}
update_sockcache(&sc,(struct sockaddr *)&source);
int cr = buffer[0]; // Command/response byte
printf("%s:%s: %s",sc.host,sc.port,cr ? "CMD " : "STAT");
dump_metadata(buffer+1,length-1);
}
}