Il giorno lun, 04/06/2007 alle 13.32 -0700, Fabrizio Gattuso ha scritto:
> On 4 Giu, 22:10, "Andrea Ferraresi" <[EMAIL PROTECTED]>
> wrote:
> > scusate il repost ma ho mandato la mail a fabrizio in privato
> >
> > ---------- Forwarded message ----------
> > From: Andrea Ferraresi <[EMAIL PROTECTED]>
> > Date: 4-giu-2007 22.06
> > Subject: Re: Mac Address in C
> > To: Fabrizio Gattuso <[EMAIL PROTECTED]>
> >
> > tutte le informazioni della scheda vengono date dal comando ifconfig
> > quindi basta dare il seguente comando
> >
> > ifconfig | grep HW
> >
> > ciao.
> 
> intendevo in C  :)  non da shell!

struct  ifreq ifr;
char mac[20];     

int s = socket (AF_INET,SOCK_DGRAM,0);
strcpy(ifr.ifr_name, "eth1");
/* get mac address of the interface */
if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) {
            cerr << "ioctl SIOCGIFHWADDR non riuscita" << endl;
}
else
{
            unsigned char *pmac = (u_char
*)&ifr.ifr_ifru.ifru_hwaddr.sa_data[0];
            sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x",
                    *pmac, *(pmac + 1), *(pmac + 2), *(pmac + 3),
                    *(pmac + 4), *(pmac + 5) );
}

Ciao
sc

-- 
Stefano Canepa aka sc: [EMAIL PROTECTED]  http://www.stefanocanepa.it
Three great virtues of a programmer: laziness, impatience and hubris.
Le tre grandi virtù di un programmatore: pigrizia, impazienza e
arroganza. (Larry Wall)

Attachment: signature.asc
Description: Questa è una parte del messaggio firmata digitalmente

Rispondere a