Igor Kovalenko <Igor.Kovalenko@motorola.com> wrote:
: You’re saying you need to extract your own MAC address? I guess Sean can
: comment on that.
Sure:
Here are 2 methods, the first more BSD’ish, the second more NTO’ish:
-seanb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <ioctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <netinet/in.h>
int main (int argc, char **argv)
{
int s, i;
char buf[4096], *cplim;
struct ifconf ifc;
struct ifreq *ifr;
struct sockaddr_dl *sdl;
if(argc < 2)
{
fprintf (stderr, “Must specify interface.\n”);
exit (1);
}
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror (“socket”);
exit(1);
}
ifc.ifc_len = sizeof (buf);
ifc.ifc_buf = buf;
if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0)
{
perror (“SIOCGIFCONF”);
exit(1);
}
ifr = ifc.ifc_req;
cplim = (char *)ifr + ifc.ifc_len;
for(; (char )ifr <cplim; ifr= (struct ifreq)((char *)ifr + ifr->ifr_addr.sa_len + IFNAMSIZ))
{
if(strcmp(ifr->ifr_name, argv[1]) || ifr->ifr_addr.sa_family != AF_LINK)
continue;
sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
if(sdl->sdl_type != IFT_ETHER)
continue;
printf("%s: ", argv[1]);
for(i = 0; i < sdl->sdl_alen; i++)
printf("%#x ", (unsigned char)sdl->sdl_data[sdl->sdl_nlen + i]);
printf("\n");
exit(EXIT_SUCCESS);
}
fprintf (stderr, “%s: not found\n”, argv[1]);
exit(1);
}
#include <sys/dcmd_io-net.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
int
main(void)
{
int fd;
Nic_t nic;
if((fd = open("/dev/io-net/en0", O_RDONLY)) == -1)
{
perror(“open”);
return 1;
}
if(errno = devctl(fd, DCMD_IO_NET_NICINFO, &nic, sizeof( Nic_t ), NULL ))
{
perror(“devctl”);
return 1;
}
printf("%02X%02X%02X %02X%02X%02X\n",
nic.current_address[0], nic.current_address[1],
nic.current_address[2], nic.current_address[3],
nic.current_address[4], nic.current_address[5] );
}
: Larry Brigman wrote:
:>
:> Igor Kovalenko wrote:
:>
:> > “Larry Brigman” <lbrigman@fcpa.fujitsu.com> wrote in message
:> > news:3A5DD962.EC1ADFCA@fcpa.fujitsu.com…
:> > > Igor Kovalenko wrote:
:> > >
:> > > > How do you know dhcp.client does this? As far as I know, setting up
:> > > > broadcast address is not supported.
:> > >
:> > > Because I captured the dhcp packet request from my machine
:> > > with a network analyzer and it had the hardware (MAC) address
:> > > in the data section of the packet.
:> > >
:> >
:> > And that tells you what? Clients send their MAC address because server may
:> > use it to assign a certain IP address (which diskless client can’t store
:> > away).
:> >
:> > I’m not sure what you mean by ‘hardware address to use for broadcasting’.
:> > The only broadcast address I know which might be set by DHCP is IP broadcast
:> > address. According to docs NTO dhcp client does not support setting that.
:>
:> I guess broadcasting is the wrong term. I need the MAC address of the
:> card to include in the data section of a dhcp/bootp packet.
:>
:> In digging through the include files the ifru_hwaddr structure is not defined
:> in the files, which is where I would get this information.
:>
:> If this type of coding is different from other version of UNIX that support
:> the BSD api then I need to know how it is different to support my own
:> requirements.
:>
:> > > >
:> > > >
:> > > > Larry Brigman wrote:
:> > > > >
:> > > > > In the work of porting and modifing some code to retrive extended tags
:> > > > > on
:> > > > > a dhcp server; I have tried to compiled bootpc from the linux sources.
:> > > > > It looks (from the header files) that there is no way to get the
:> > > > > hardware
:> > > > > address to use for broadcasting.
:> > > > >
:> > > > > The structure that seems to be missing in inet/if.h is
:> > > > > ifr_hwaddr.
:> > > > >
:> > > > > Is there some other location for this information or was this not
:> > > > > included?
:> > > > > Also the ioctl define for SIOCGIFHWADDR is missing.
:> > > > >
:> > > > > I know that dhcp.client does do this but the includes that come with
:> > the
:> > > > >
:> > > > > CD don’t show that I can.
:> > >