forked from delian/node-sflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sflow.js
36 lines (28 loc) · 855 Bytes
/
sflow.js
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
/**
* Created by delian
*/
var debug = require('debug')('sflow');
var dgram = require('dgram');
var Packet = require('./lib/packet');
function sflow(cb) {
if (!(this instanceof sflow)) return new sflow(cb);
var me = this;
this.templates = {};
this.server = dgram.createSocket('udp4');
this.server.on('message', function (msg, rinfo) {
debug('got a packet');
var packet = new Packet(msg);
if (cb) {
packet.on('flow', function (flow) {
debug('gow a flow %d from packet with sequence %d', flow.seqNum, packet.header.sequence);
cb({header:packet.header, rinfo:rinfo, flow:flow});
});
}
});
this.listen = function(port) {
setTimeout(function() {
me.server.bind(port);
},50);
}
}
module.exports = sflow;