diff --git a/README.md b/README.md index 2c26247..631c424 100644 --- a/README.md +++ b/README.md @@ -172,16 +172,17 @@ ifconfig.down('wlan0', function(err) { ``` ## ifconfig.up(options, callback) -The **ifconfig up** command is used to bring up an interface with the specified configuration. +The **ifconfig up** command is used to bring up an interface with an optional specified +configuration. ``` javascript var ifconfig = require('wireless-tools/ifconfig'); var options = { interface: 'wlan0', - ipv4_address: '192.168.10.1', - ipv4_broadcast: '192.168.10.255', - ipv4_subnet_mask: '255.255.255.0' + ipv4_address(optional): '192.168.10.1', + ipv4_broadcast(optional): '192.168.10.255', + ipv4_subnet_mask(optional): '255.255.255.0' }; ifconfig.up(options, function(err) { diff --git a/ifconfig.js b/ifconfig.js index 08f9fa7..70010fd 100644 --- a/ifconfig.js +++ b/ifconfig.js @@ -230,9 +230,9 @@ function down(interface, callback) { * * var options = { * interface: 'wlan0', - * ipv4_address: '192.168.10.1', - * ipv4_broadcast: '192.168.10.255', - * ipv4_subnet_mask: '255.255.255.0' + * ipv4_address(optional): '192.168.10.1', + * ipv4_broadcast(optional): '192.168.10.255', + * ipv4_subnet_mask(optional): '255.255.255.0' * }; * * ifconfig.up(options, function(err) { @@ -242,8 +242,8 @@ function down(interface, callback) { */ 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)) || '') + + ((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..5762637 100644 --- a/test/ifconfig.js +++ b/test/ifconfig.js @@ -160,6 +160,23 @@ describe('ifconfig', function() { describe('ifconfig.up(options, callback)', function() { it('should bring up the interface', function(done) { + ifconfig.exec = function(command, callback) { + should(command).eql('ifconfig wlan0 up'); + + callback(null, '', ''); + }; + + var minimal_options = { + interface: 'wlan0' + }; + + ifconfig.up(minimal_options, function(err) { + should(err).not.be.ok; + done(); + }); + }) + + it('should bring up and configure the ip settings for the interface', function(done) { ifconfig.exec = function(command, callback) { should(command).eql('ifconfig wlan0 192.168.10.1' + ' netmask 255.255.255.0 broadcast 192.168.10.255 up');