SCO get MAC Address

Does anyone know how to get the mac address of a SCO box using c.

Does arp work in SCO?

What did you try for code, ioctl?

does this work?


#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>


int main( int argc, char *argv[] )
{
	int s;
		
	struct ifreq buffer;
	s = socket(PF_INET, SOCK_DGRAM, 0);
	memset(&buffer, 0x00, sizeof(buffer));
	strcpy(buffer.ifr_name, "eth0");
	ioctl(s, SIOCGIFHWADDR, &buffer);
	close(s);	
	for( s = 0; s < 6; s++ )
	{
		printf("%.2X ", (unsigned char)buffer.ifr_hwaddr.sa_data);
	}
	printf("\n");

	return 0;
}

I am a newbie, to doing this on the SCO. I got it to work with the AIX. From the documentation that I read arp is supposed to work. Acutally a coding sample or two with arp would really really be appreciated.

Thanks.

These are the errors I got:

"sco.c", line 16: error: undefined symbol: SIOCGIFHWADDR
"sco.c", line 20: error: undefined struct/union member: ifr_hwaddr
"sco.c", line 20: warning: left operand of "." must be struct/union object
"sco.c", line 20: error: cannot access member of non-struct/union object
"sco.c", line 25: warning: newline not last character in file

SIOCGIFFLAGS works in place of SIOCGIFHWADDR

#include <stdio.h>

int main()
{
   
   FILE *cmd=popen("arp kcsdev | awk '{print $4}'", "r");
   char tmp[80]={0x0};
   
   while(fgets( tmp, sizeof(tmp), cmd)!=NULL)
   {
         printf("%s\n", tmp);
    }
   pclose(cmd);
   return 0;
}

kcsdev = node this was tested on. Change it.

I know this may sound like I'm stupid, but what should kcsdev be changed to.

Whatever the hostname program returns - the name of the box you are running the query on

kcsdev:/home/jmcnama> hostname
kcsdev
kcsdev:/home/jmcnama>

The program just prints no.

What does

uname -a

show?
I don't know SCO, but I'm hoping they can spell POSIX - a set of UNIX standards

I'll post, thanks Jim for all of your help it is appreciated.

#include <stdio.h>

int main()
{

FILE *cmd=popen(" ndstat | grep net0 | awk '{print $3}'", "r");
char tmp[80]={0x0};

while(fgets( tmp, sizeof(tmp), cmd)!=NULL)
{
printf("%s\n", tmp);
}
pclose(cmd);
return 0;
}

I'm going to post a new thread about md5 hashing, in unix (SCO) environment. Hope to see you there