From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 9 05:42:52 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7117C106566C for ; Wed, 9 Nov 2011 05:42:52 +0000 (UTC) (envelope-from sife.mailling@yahoo.com) Received: from nm19-vm0.bullet.mail.sp2.yahoo.com (nm19-vm0.bullet.mail.sp2.yahoo.com [98.139.91.216]) by mx1.freebsd.org (Postfix) with SMTP id 477F88FC0A for ; Wed, 9 Nov 2011 05:42:52 +0000 (UTC) Received: from [98.139.91.69] by nm19.bullet.mail.sp2.yahoo.com with NNFMP; 09 Nov 2011 05:30:11 -0000 Received: from [98.139.91.22] by tm9.bullet.mail.sp2.yahoo.com with NNFMP; 09 Nov 2011 05:30:10 -0000 Received: from [127.0.0.1] by omp1022.mail.sp2.yahoo.com with NNFMP; 09 Nov 2011 05:30:10 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 930263.16347.bm@omp1022.mail.sp2.yahoo.com Received: (qmail 13690 invoked by uid 60001); 9 Nov 2011 05:30:10 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1320816610; bh=u1F+m/FgzymposjoSFLfzltyNY4LLuSl6qMJ0wRfLH0=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=F6OCGW9K/1H/JxVf15y2ccY0CU4129I9hF26wygP1lQwU911WG1jPJR+h3FNPWI9KgE4zj6xAJJgcJSgEzYWNt8YXSAmMjfQlO1cA1uTikTydh46XZjkkT3K7IQbY3uYrh0cwBzZPbces/Cro21m/1WdI25lFNgqAfZMcEO4y8k= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=1yhxoDoD6jTRgBxsZY4jji4MwwRBkNeW/Iu2WPmDFns8BP9xjAggYWMrNLxZxT9bLqNqEmrGrMVn9pzh+d1D+jYf4pE0HM1BALeJcQWLB5poNsTezF/Y+GEyOg7LhJctL+3ix+9tTyrvBpEAtlMyQiB5hw81MY3gWjH4I0y1GT0=; X-YMail-OSG: 8iIlBaUVM1lkHVJfOMyWUvg1aBxvcPskkvhmsYf6jJpj_hF 67J7ND2jUY4UxlrRDm0e9.T6CxfuOcp0bORIRSe.gSBoi34GbbpXB4NWS_vm NHXjs6h0sM7jdlIfiC9Mq7ihqy83AtUQJF6UYSvtpKf00xwvbJOKxg6Tfmap bnts07VElAK14aW29UlXlweLWLQVDU5LxV.DVez4G7JKjvDWwljZ0FPaemFy GeeIzg03RTklxRkZA8.Gqa6am8O5Wl.VTTtVvZeHuvZTZFfGFqudMjxyT6ri NX3hg_rQt1_jHBj_j5.270sD85vXysJl6182IRTAG5PWrNExoV9jVGZokMPJ f.55LAJYQjQwfY8WLquww6NXCB6kFVNxH5YcoZkEiENViDLIOxlNUorX6U0t psg1mD1Wqdy0iaWDU57eErrJsUDjwec_wSK2NkgDLdH.nM8Oq.0Dj.50ukv9 uC6VO3vlM7.0cFbxzmWTPTtgp6YtkzuoLnCv8MYG_hjDwhjiMYoXiImBuzou g_NruQLqd334HJW.oFzKuAPC2SDg- Received: from [41.100.65.10] by web113116.mail.gq1.yahoo.com via HTTP; Tue, 08 Nov 2011 21:30:10 PST X-Mailer: YahooMailWebService/0.8.115.325013 Message-ID: <1320816610.4259.YahooMailNeo@web113116.mail.gq1.yahoo.com> Date: Tue, 8 Nov 2011 21:30:10 -0800 (PST) From: Sife Mailling To: "freebsd-hackers@freebsd.org" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Set mac address via ioctl X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Sife Mailling List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2011 05:42:52 -0000 After reading ifconfig source code for hours, I end with this, witch was suppose to change mac address via a command line: #include #include #include #include #include #include #include /* IP */ #include #include #include #include #include #include #include #include #include #include #include #include struct afswtch { const char *af_name; /* as given on cmd line, e.g. "inet" */ short af_af; /* AF_* */ /* * Status is handled one of two ways; if there is an * address associated with the interface then the * associated address family af_status method is invoked * with the appropriate addressin info. Otherwise, if * all possible info is to be displayed and af_other_status * is defined then it is invoked after all address status * is presented. */ void (*af_status)(int, const struct ifaddrs *); void (*af_other_status)(int); /* parse address method */ void (*af_getaddr)(const char *, int); /* parse prefix method (IPv6) */ void (*af_getprefix)(const char *, int); void (*af_postproc)(int s, const struct afswtch *); u_long af_difaddr; /* set dst if address ioctl */ u_long af_aifaddr; /* set if address ioctl */ void *af_ridreq; /* */ void *af_addreq; /* */ struct afswtch *af_next; /* XXX doesn't fit model */ void (*af_status_tunnel)(int); void (*af_settunnel)(int s, struct addrinfo *srcres, struct addrinfo *dstres); }; int main(int argc, char **argv) { int s, error; struct ifreq ifr; //char name[IFNAMSIZ]; mac_t label; if (mac_from_text(&label, argv[1]) == -1) { perror(argv[1]); return; } ifr.ifr_addr.sa_family = AF_INET; if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0) err(1, "socket(family %u,SOCK_DGRAM", ifr.ifr_addr.sa_family); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, argv[2], sizeof(ifr.ifr_name)); ifr.ifr_ifru.ifru_data = (void *)label; error = ioctl(s, SIOCSIFMAC, &ifr); mac_free(label); if (error == -1) perror("setifmac"); return 0; } Now, if I try to change mac address of my card, I get this message: ./mactool dc0 00:10:22:33:44:77 mactool: socket(family 18,SOCK_DGRAM: Protocol not supported