//------------------------------------------------------------------- // joinvlan.cpp // // This program allows a user to modify the VLAN identification // number being used by our 'nic2.c' device-driver, assuming it // has already been compiled and installed in the Linux kernel. // // compile using: $ g++ joinvlan.cpp -o joinvlan // execute using: $ ./joinvlan // // programmer: ALLAN CRUSE // written on: 20 MAR 2008 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for ioctl() char devname[] = "/dev/nic"; char mac[6]; short vlan_id; int main( int argc, char **argv ) { // open the device-file int fd = open( devname, O_RDWR ); if ( fd < 0 ) { perror( devname ); exit(1); } // get the current value of the driver's VLAN identification if ( ioctl( fd, 3, &vlan_id ) ) { perror( "ioctl 3" ); exit(1); } printf( "\nCurrent VLAN identification: 0x%04X \n", vlan_id ); // prompt the user to enter a new VLAN identification value printf( "\nRevised VLAN identification: 0x" ); fflush( stdout ); // convert the user's hexadecimal input-string into a number char inbuf[ 8 ] = {0}; fgets( inbuf, 7, stdin ); vlan_id = (short)strtoul( inbuf, NULL, 16 ); // set the revised value of the driver's VLAN identification if ( ioctl( fd, 2, &vlan_id ) ) { perror( "ioctl 2" ); exit(1); } // get the revised value and display it for confirmation if ( ioctl( fd, 3, &vlan_id ) ) { perror( "ioctl 3" ); exit(1); } printf( "\nCurrent VLAN identification: 0x%04X \n", vlan_id ); printf( "\n" ); }