/*
Functionality:Get HWaddr in AIX
Prototype:
Parameters:
Return-Value:
Author:
Date:
*/
#include
#include
#include
#define MAXLINE 100
typedef unsigned char u_int8_t;
int main(int argc,char** argv)
{
char line[MAXLINE];
char cmd[MAXLINE];
char* p;
FILE *res;
unsigned int hwaddr[6];
if (argc !=2)
{
fprintf(stderr,"usage: gethwaddr_aix \n");
return -1;
}
sprintf(cmd,"%s%s%s","/usr/bin/entstat -d ",argv[1]," | grep 'Hardware Address' | sed -e 's/Hardware Address: //'");
if((res=popen(cmd,"r")) == NULL)
{
fprintf(stderr,"popen error\n");
return -1;
}
while (fgets(line,MAXLINE,res) != NULL)
{
sscanf(line,"%x:%x:%x:%x:%x:%x",&hwaddr[0],&hwaddr[1],&hwaddr[2],&hwaddr[3],&hwaddr[4],&hwaddr[5]);
printf("%02x:%02x:%02x:%02x:%02x:%02x\n",hwaddr[0],hwaddr[1],hwaddr[2],hwaddr[3],hwaddr[4],hwaddr[5]);
}
if (pclose(res) == -1)
{
fprintf(stderr,"pclose error\n");
return -1;
}
return 0;
}
阅读(1071) | 评论(0) | 转发(0) |