1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add ipv6 support to udp node

This commit is contained in:
dceejay 2015-03-05 13:07:38 +00:00
parent 10b092a9a7
commit 3cbc1bbb1b
2 changed files with 25 additions and 10 deletions

View File

@ -17,9 +17,8 @@
<!-- The Input Node --> <!-- The Input Node -->
<script type="text/x-red" data-template-name="udp in"> <script type="text/x-red" data-template-name="udp in">
<div class="form-row"> <div class="form-row">
<label for="node-input-port"><i class="fa fa-sign-in"></i> Listen</label> <label for="node-input-port"><i class="fa fa-sign-in"></i> Listen for</label>
on port <input type="text" id="node-input-port" placeholder="Port" style="width: 45px"> <select id="node-input-multicast" style='width:62%'>
for <select id="node-input-multicast" style='width:40%'>
<option value="false">udp messages</option> <option value="false">udp messages</option>
<option value="true">multicast messages</option> <option value="true">multicast messages</option>
</select> </select>
@ -32,6 +31,14 @@
<label for="node-input-iface"><i class="fa fa-random"></i> Interface</label> <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
<input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0"> <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
</div> </div>
<div class="form-row">
<label for="node-input-port"><i class="fa fa-sign-in"></i> on Port</label>
<input type="text" id="node-input-port" placeholder="Port" style="width: 80px">
&nbsp;&nbsp;using <select id="node-input-ipv" style="width:80px">
<option value="udp4">ipv4</option>
<option value="udp6">ipv6</option>
</select>
</div>
<div class="form-row"> <div class="form-row">
<label for="node-input-datatype"><i class="fa fa-sign-out"></i> Output</label> <label for="node-input-datatype"><i class="fa fa-sign-out"></i> Output</label>
<select id="node-input-datatype" style="width: 70%;"> <select id="node-input-datatype" style="width: 70%;">
@ -74,9 +81,10 @@
name: {value:""}, name: {value:""},
iface: {value:""}, iface: {value:""},
port: {value:"",required:true,validate:RED.validators.number()}, port: {value:"",required:true,validate:RED.validators.number()},
datatype: {value:"buffer",required:true}, ipv: {value:"udp4"},
multicast: {value:"false"}, multicast: {value:"false"},
group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} } group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} },
datatype: {value:"buffer",required:true}
}, },
inputs:0, inputs:0,
outputs:1, outputs:1,
@ -98,7 +106,7 @@
<script type="text/x-red" data-template-name="udp out"> <script type="text/x-red" data-template-name="udp out">
<div class="form-row"> <div class="form-row">
<label for="node-input-port"><i class="fa fa-envelope"></i> Send a</label> <label for="node-input-port"><i class="fa fa-envelope"></i> Send a</label>
<select id="node-input-multicast" style='width:40%'> <select id="node-input-multicast" style="width:40%">
<option value="false">udp message</option> <option value="false">udp message</option>
<option value="broad">broadcast message</option> <option value="broad">broadcast message</option>
<option value="multi">multicast message</option> <option value="multi">multicast message</option>
@ -107,7 +115,11 @@
</div> </div>
<div class="form-row node-input-addr"> <div class="form-row node-input-addr">
<label for="node-input-addr" id="node-input-addr-label"><i class="fa fa-list"></i> Address</label> <label for="node-input-addr" id="node-input-addr-label"><i class="fa fa-list"></i> Address</label>
<input type="text" id="node-input-addr" placeholder="destination ip" style="width: 70%;"> <input type="text" id="node-input-addr" placeholder="destination ip" style="width: 50%;">
<select id="node-input-ipv" style="width:70px">
<option value="udp4">ipv4</option>
<option value="udp6">ipv6</option>
</select>
</div> </div>
<div class="form-row node-input-iface"> <div class="form-row node-input-iface">
<label for="node-input-iface"><i class="fa fa-random"></i> Interface</label> <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
@ -167,6 +179,7 @@
addr: {value:""}, addr: {value:""},
iface: {value:""}, iface: {value:""},
port: {value:""}, port: {value:""},
ipv: {value:"udp4"},
outport: {value:""}, outport: {value:""},
base64: {value:false,required:true}, base64: {value:false,required:true},
multicast: {value:"false"} multicast: {value:"false"}

View File

@ -26,9 +26,10 @@ module.exports = function(RED) {
this.datatype = n.datatype; this.datatype = n.datatype;
this.iface = n.iface || null; this.iface = n.iface || null;
this.multicast = n.multicast; this.multicast = n.multicast;
this.ipv = n.ipv || "udp4";
var node = this; var node = this;
var server = dgram.createSocket('udp4'); var server = dgram.createSocket(node.ipv); // default to ipv4
server.on("error", function (err) { server.on("error", function (err) {
if ((err.code == "EACCES") && (node.port < 1024)) { if ((err.code == "EACCES") && (node.port < 1024)) {
@ -83,7 +84,7 @@ module.exports = function(RED) {
// Hack for when you have both in and out udp nodes sharing a port // Hack for when you have both in and out udp nodes sharing a port
// if udp in starts last it shares better - so give it a chance to be last // if udp in starts last it shares better - so give it a chance to be last
setTimeout( function() { server.bind(node.port,node.iface); }, 250);; setTimeout( function() { server.bind(node.port,node.iface); }, 250);
} }
RED.nodes.registerType("udp in",UDPin); RED.nodes.registerType("udp in",UDPin);
@ -98,9 +99,10 @@ module.exports = function(RED) {
this.addr = n.addr; this.addr = n.addr;
this.iface = n.iface || null; this.iface = n.iface || null;
this.multicast = n.multicast; this.multicast = n.multicast;
this.ipv = n.ipv || "udp4";
var node = this; var node = this;
var sock = dgram.createSocket('udp4'); // only use ipv4 for now var sock = dgram.createSocket(node.ipv); // default to ipv4
if (node.multicast != "false") { if (node.multicast != "false") {
if (node.outport == "") { node.outport = node.port; } if (node.outport == "") { node.outport = node.port; }