Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make ifconfig parameters optional #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
10 changes: 6 additions & 4 deletions ifconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
33 changes: 33 additions & 0 deletions test/ifconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may this address be used from ENV var?

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');
Expand Down