diff --git a/ifconfig.js b/ifconfig.js index 08f9fa7..fa20efd 100644 --- a/ifconfig.js +++ b/ifconfig.js @@ -236,14 +236,16 @@ function down(interface, callback) { * }; * * ifconfig.up(options, function(err) { - * // the interface is up + * // the interface is up * }); * + * ipv4_address, ipv4_broadcast and ipv4_subnet_mask are optional */ function up(options, callback) { return this.exec('ifconfig ' + options.interface + - ' ' + options.ipv4_address + - ' netmask ' + options.ipv4_subnet_mask + - ' broadcast ' + options.ipv4_broadcast + + ' ' + + (options.ipv4_address ? options.ipv4_address : '0.0.0.0') + + (options.ipv4_subnet_mask ? ' netmask ' + options.ipv4_subnet_mask : '') + + (options.ipv4_broadcast ? ' broadcast ' + options.ipv4_broadcast : '') + ' up', callback); } diff --git a/test/ifconfig.js b/test/ifconfig.js index 4c61cc0..ef5528e 100644 --- a/test/ifconfig.js +++ b/test/ifconfig.js @@ -180,6 +180,39 @@ describe('ifconfig', function() { }); }) + it('should bring up the interface without broadcast nor subnet', function(done) { + ifconfig.exec = function(command, callback) { + should(command).eql('ifconfig wlan0 192.168.10.1 up'); + callback(null, '', ''); + }; + + var options = { + interface: 'wlan0', + ipv4_address: '192.168.10.1', + }; + + ifconfig.up(options, function(err) { + should(err).not.be.ok; + done(); + }); + }) + + it('should bring up the interface without ip/broadcast nor subnet', function(done) { + ifconfig.exec = function(command, callback) { + should(command).eql('ifconfig wlan0 0.0.0.0 up'); + callback(null, '', ''); + }; + + var options = { + interface: 'wlan0' + }; + + ifconfig.up(options, function(err) { + should(err).not.be.ok; + done(); + }); + }) + it('should handle errors', function(done) { ifconfig.exec = function(command, callback) { callback('error');