Skip to content
This repository was archived by the owner on Mar 8, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ on each `get`, `getAll`, etc.
between each). A backoff can be implemented by timeouts along the lines of
`[ 1000, 2000, 4000, 8000 ]`. Retransmissions can be disabled by using only
a single timeout value: `[ 5000 ]`.
- `sourceAddress`: The IP address to bind the socket to, and where requests
are coming from. Must be an IP address on the node, if specified.
Default is to bind to all interfaces.
- `sourcePort`: The UDP port number to bind the socket to, and where requests
are coming from. Default: `0` (random).

### VarBind objects

Expand Down
13 changes: 11 additions & 2 deletions lib/snmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,19 @@ function Session(options) {
// If exclusive is false (default), then cluster workers will use the same underlying handle,
// allowing connection handling duties to be shared.
// When exclusive is true, the handle is not shared, and attempted port sharing results in an error.
self.socket.bind({
var bindOptions = {
port: 0, //get a random port automatically
exclusive: true // you should not share the same port, otherwise yours packages will be screwed up between workers
});
};
if (self.options.sourceAddress) {
// Support binding to specific source address (wanted on multi-homed nodes)
bindOptions.address = self.options.sourceAddress;
}
if (self.options.sourcePort) {
// Support binding to specific source port
bindOptions.port = self.options.sourcePort;
}
self.socket.bind(bindOptions);
}

// We inherit from EventEmitter so that we can emit error events
Expand Down