Mac Address 를 String 으로 변환하는 간편한 방법

by digipine posted Nov 02, 2017
?

Shortcut

PrevPrev Article

NextNext Article

ESCClose

Larger Font Smaller Font Up Down Go comment Print

Mac Address를 출력해야될 필요가 있을때 String(문자열) 값으로 변환하려면 귀찮을 경우가 있다면

아래와 같은 정의문을 만들에서 Global 헤더에 포함시키면 편리합니다.

 

#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"


 

사용방법은 다음과 같습니다.

    

#include <stdio.h>

#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"

 

int main(void) {
  int mac_val[6] = {0x0a, 0x0b, 0x0c, 0x01, 0x02, 0x03};
  char str_mac[18] = {0};
  sprintf(str_mac, MACSTR, MAC2STR(mac_val));
  printf("mac address : %s\n", str_mac);
  return 0;
}

 
TAG •

Articles

1 2 3 4 5 6