본문 바로가기

IT Tech/Programming

[C언어] parse Mac Address

반응형





int parse_mac_address(char  *strNum,  uchar_t rslt_hex[])
{
    int     enteredNum = 0;
    int     orgIndex = 0;
    int     oprIndex = 0;
    char    numChar[100];


    while(orgIndex <= strlen(strNum))
    {
        if (strNum[orgIndex] == ':' || strNum[orgIndex] == '\0')
        {
            numChar[oprIndex] = '\0';
			if (strlen(numChar) > 2 )
				return -1;
			
            rslt_hex[enteredNum++] = strtoul(numChar, NULL, 16);
            oprIndex = 0;
        }
        else
        {
            if(strNum[orgIndex] >'F' || strNum[orgIndex] < '0')
                return(-1);

            numChar[oprIndex++] = strNum[orgIndex];
        }
        orgIndex++;
    }

    return (enteredNum);
}



입력 포맷 : AA:BB:CC:11:22:33
저장 포맷 : unsigned char rslt_hex[6]





반응형