aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/ip/snoopy/rtp.c
blob: 1aef15fa50b0b2ba00632bf94e588de64d6cf365 (plain)
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
#include <u.h>
#include <libc.h>
#include <ip.h>
#include "dat.h"
#include "protos.h"

typedef struct Hdr Hdr;
struct Hdr {
	uchar	hdr;		/* RTP header */
	uchar	marker;	/* Payload and marker */
	uchar	seq[2];	/* Sequence number */
	uchar	ts[4];		/* Time stamp */
	uchar	ssrc[4];	/* Synchronization source identifier */
};

enum{
	RTPLEN = 12,		/* Minimum size of an RTP header */
};

static int
p_seprint(Msg *m)
{
	Hdr*h;
	ushort seq;
	ulong ssrc, ts;
	int cc, i;

	if(m->pe - m->ps < RTPLEN)
		return -1;

	h = (Hdr*)m->ps;
	cc = h->hdr & 0xf;
	if(m->pe - m->ps < RTPLEN + cc * 4)
		return -1;

	m->ps += RTPLEN;

	seq = NetS(h->seq);
	ts = NetL(h->ts);
	ssrc = NetL(h->ssrc);

	m->p = seprint(m->p, m->e, "version=%d x=%d cc=%d seq=%d ts=%ld ssrc=%ulx",
				(h->hdr >> 6) & 3, (h->hdr >> 4) & 1, cc, seq, ts, ssrc);
	for(i = 0; i < cc; i++){
		m->p = seprint(m->p, m->e, " csrc[%d]=%d",
				i, NetL(m->ps));
		m->ps += 4;
	}
	m->pr = nil;
	return 0;
}

Proto rtp = {
	"rtp",
	nil,
	nil,
	p_seprint,
	nil,
	nil,
	nil,
	defaultframer
};