A PHP Error was encountered

Severity: Warning

Message: fopen(/var/cpanel/php/sessions/ea-php56/PHPSESSIDb3thci1gr3rclp4ibpl8ieue1c7s3tld): failed to open stream: No space left on device

Filename: drivers/Session_files_driver.php

Line Number: 174

C++ program to set MAC address in Linux Devices
Q:

C++ program to set MAC address in Linux Devices

0

C++ program to set MAC address in Linux Devices

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Consider the program:

#include <iostream>
using namespace std;

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void  setMac(char * mac)
{
	char cmd[64];
	//network interface
	char nwkInf[5]="eth0";

	memset(cmd,0X00,64);
	
	//command to link down network
	sprintf((char *)cmd,(const char *)"ip link set %s down",nwkInf);
	system((const char *)cmd); 
	usleep(500);
	
	memset(cmd,0X00,64);
	//command to set MAC address
	sprintf((char *)cmd,(const char *)"ifconfig %s hw ether %s",nwkInf,mac);
	system((const char *)cmd);
	usleep(500);

	memset(cmd,0X00,64);
	//command to link up network
	sprintf((char *)cmd,(const char *)"ip link set %s up",nwkInf);
	system((const char *)cmd);
	usleep(500);

}

int main()
{
    //funcion call to set MAC address
	setMac("67:45:C4:AC:2F:CA");
	return 0;
}

Here, "67:45:C4:AC:2F:CA" is MAC address to be assigned.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Most popular and Searched C++ solved programs with Explanation and Output

Similar questions


need a help?


find thousands of online teachers now
C++ program to pad octets of IP Address with Zeros... >>
<< C++ program to get MAC address of Linux based netw...

A PHP Error was encountered

Severity: Warning

Message: Unknown: Failed to write session data (user). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56)

Filename: Unknown

Line Number: 0