Obtain the MAC address of the NIC by programming in SCO

Source: Internet
Author: User
Article title: obtain the MAC address of the NIC by programming under SCO. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
# Include
# Include
# Include
# Include
# Include
# Include
  
Int main (int argc, char * argv [])
{
Struct strioctl strioc;
U_char ether_addr [6];
Int s;
  
If (argc! = 2 ){
Fprintf (stderr, "usage: % s deviceFile \ n", argv [0]);
Exit (1 );
}
  
Bzero (ether_addr, sizeof (ether_addr ));
  
If (s = open (argv [1], 0) <0 ){
Perror (argv [1]);
Exit (1 );
}
Strioc. ic_cmd = MACIOC_GETADDR;
Strioc. ic_timout =-1;
Strioc. ic_len = sizeof (ether_addr );
Strioc. ic_dp = (caddr_t) ether_addr;
If (ioctl (s, I _STR, (char *) & strioc) <0 ){
Perror ("I _STR: MACIOC_GETADDR ");
Exit (1 );
}
  
Printf ("% s is using address % 02x: % 02x: % 02x: % 02x: % 02x: % 02x \ n ",
Argv [1],
Ether_addr [0], ether_addr [1], ether_addr [2],
Ether_addr [3], ether_addr [4], ether_addr [5]
);
  
Exit (0 );
}
  
/********************************** End **** *****************************/
  
Note:
The execution method is as follows (assume that the compiled execution file is getmac ):
./Getmac/dev/net0
  
MDI (MAC Driver Interface)
  
MACIOC_GETADDR
Send a request to the MDI driver to obtain the current MAC address of the network adapter );
  
MACIOC_GETRADDR
Send a request to the MDI driver to obtain the MAC address of the NIC vendor (the factory MAC address );
  
This program is applicable to SCO OpenServer and UnixWare and passed the test on OpenServer 5.06.
  
When I try to use MACIOC_GETRADDR, an invalid parameter is Prompted. I guess it may be related to the implementation not provided in the driver, because the copyright information I accidentally saw is
/*
* Copyright (C) The Santa Cruz Operation, 1993-1995.
* This Module contains Proprietary Information
* The Santa Cruz Operation and shoshould be treated
* As Confidential.
*/
In the AT-2500TX driver source code, the corresponding part only contains the MACIOC_GETADDR implementation, without MACIOC_GETRADDR.
Related Article

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.