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

Allow ifconfig up to be performed without options #56

Open
wants to merge 2 commits 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions ifconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
17 changes: 17 additions & 0 deletions test/ifconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down