please input the mac :
00:1A:A9:AA:BB:CC
new mac for decrease is :00:1A:A9:AA:BB:CB
new mac for increase is :00:1A:A9:AA:BB:CD
#define BOOL int
#define FALSE 0
#define TRUE 1
#include <stdio.h>
#include <string.h>
BOOL macDecrease(char * mac) //DECREASE MAC BY ONE
{
int num=16;
while(num>=0)
{
if('A' == mac[num])
{
mac[num]='9';
break;
}
else if('0' == mac[num])
{
mac[num]='F';
num--;
}
else if(':' == mac[num])
{
num--;
}
else
{
mac[num]--;
break;
}
}
if(-1 == num)
return FALSE; //DECREASE FAIL
else
return TRUE;
}
BOOL macIncrease(char * mac) //INCREASE MAC BY ONE
{
int num=16;
while(num>=0)
{
if('9' == mac[num])
{
mac[num]='A';
break;
}
else if('F' == mac[num])
{
mac[num]='0';
num--;
}
else if(':' == mac[num])
{
num--;
}
else
{
mac[num]++;
break;
}
}
if(-1 == num)
return FALSE; //inclease FAIL
else
return TRUE;
}
void main(int argc, char* argv[])
{
char mac[18],macInc[18];
printf("please input the mac :\n");
scanf("%s",mac);
strcpy(macInc,mac);
if(TRUE == macDecrease(mac))
printf("new mac for decrease is :%s\n",mac);
else
printf("wrong in decrease\n");
if(TRUE == macIncrease(macInc))
printf("new mac for increase is :%s\n",macInc);
else
printf("wrong in increase\n");
}