Conversion of MAC addresses between 18 bytes and 6 bytes

Source: Internet
Author: User


#include  <stdio.h> #include  <string.h> #define  unsigned int u32#define  MACSTR  "%02x:%02x:%02x:%02x:%02x:%02x" #define &NBSP;MACSTOL (a)    (a) [0],  (a) [1],  (a) [2],  (a) [3],  (a) [4],  (a) [5] #define &NBSP;MACLTOS (a)    (u32 *) & (a) [0],  ( u32 *) & (A) [1],  (u32 *) & (A) [2],  (u32 *) & (A) [3],  (u32 *) & (a) [ 4],  (u32 *) & (a) [5]int main (int argc,char argv[]) {    char  mac_add[18] =  "00:12:32:4a:56:7b";     char mac_add_tmp[6] =  {0};    char mac_add_test[18] = {0};         /* uses sscanf to convert 18 bytes to 6 bytes, and some compilers do not have to (u32 *) do a strong turn */    sscanf (mac_add,  Macstr, macltos (mac_add_tmp))     /*6 bytes to 18 bytes */    snprintf (mac_ Add_test, 18, macStr, macstol (Mac_add));         printf ("original : %s   new : %s\n ",  mac_add, mac_add_test);     return 0;}



Conversion of MAC addresses between 18 bytes and 6 bytes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.