Skip to content

Commit d8dfeb1

Browse files
committed
make ifconfig up parameters optional
1 parent ba836ee commit d8dfeb1

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

ifconfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,16 @@ function down(interface, callback) {
236236
* };
237237
*
238238
* ifconfig.up(options, function(err) {
239-
* // the interface is up
239+
* // the interface is up
240240
* });
241241
*
242+
* ipv4_address, ipv4_broadcast and ipv4_subnet_mask are optional
242243
*/
243244
function up(options, callback) {
244245
return this.exec('ifconfig ' + options.interface +
245-
' ' + options.ipv4_address +
246-
' netmask ' + options.ipv4_subnet_mask +
247-
' broadcast ' + options.ipv4_broadcast +
246+
' ' +
247+
(options.ipv4_address ? options.ipv4_address : '0.0.0.0') +
248+
(options.ipv4_subnet_mask ? ' netmask ' + options.ipv4_subnet_mask : '') +
249+
(options.ipv4_broadcast ? ' broadcast ' + options.ipv4_broadcast : '') +
248250
' up', callback);
249251
}

test/ifconfig.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,39 @@ describe('ifconfig', function() {
180180
});
181181
})
182182

183+
it('should bring up the interface without broadcast nor subnet', function(done) {
184+
ifconfig.exec = function(command, callback) {
185+
should(command).eql('ifconfig wlan0 192.168.10.1 up');
186+
callback(null, '', '');
187+
};
188+
189+
var options = {
190+
interface: 'wlan0',
191+
ipv4_address: '192.168.10.1',
192+
};
193+
194+
ifconfig.up(options, function(err) {
195+
should(err).not.be.ok;
196+
done();
197+
});
198+
})
199+
200+
it('should bring up the interface without ip/broadcast nor subnet', function(done) {
201+
ifconfig.exec = function(command, callback) {
202+
should(command).eql('ifconfig wlan0 0.0.0.0 up');
203+
callback(null, '', '');
204+
};
205+
206+
var options = {
207+
interface: 'wlan0'
208+
};
209+
210+
ifconfig.up(options, function(err) {
211+
should(err).not.be.ok;
212+
done();
213+
});
214+
})
215+
183216
it('should handle errors', function(done) {
184217
ifconfig.exec = function(command, callback) {
185218
callback('error');

0 commit comments

Comments
 (0)