something to warry about...

Johannes Stezenbach js at sig21.net
Wed Jan 19 13:50:22 UTC 2011


(somehow mail delivery from the list to me seems to be delayed?)

On Wed, Jan 19, 2011 at 01:20:20PM +0100, Johannes Stezenbach wrote:
> On Wed, Jan 19, 2011 at 12:43:23PM +0100, Denys Vlasenko wrote:
> > On Tue, Jan 18, 2011 at 1:22 PM, Johannes Stezenbach <js at sig21.net> wrote:
> > > +union mii_ifreq {
> > > +       struct ifreq ifreq;
> > > +       struct mii_ioctl_data mii;
> > > +};

Another variation of the theme: C99 aliasing rules
also say that any pointer can alias with a char pointer.
Maybe you like this approach better.

(compiles, but otherwise untested)

diff --git a/networking/ifplugd.c b/networking/ifplugd.c
index 58f56db..4730e01 100644
--- a/networking/ifplugd.c
+++ b/networking/ifplugd.c
@@ -131,18 +131,19 @@ static int network_ioctl(int request, void* data, const char *errmsg)
 
 static smallint detect_link_mii(void)
 {
-	struct ifreq ifreq;
-	struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data;
+	char buf[sizeof(struct ifreq)];
+	struct ifreq *ifreq = (struct ifreq *)buf;
+	struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
 
-	set_ifreq_to_ifname(&ifreq);
+	set_ifreq_to_ifname(ifreq);
 
-	if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) {
+	if (network_ioctl(SIOCGMIIPHY, ifreq, "SIOCGMIIPHY") < 0) {
 		return IFSTATUS_ERR;
 	}
 
 	mii->reg_num = 1;
 
-	if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) {
+	if (network_ioctl(SIOCGMIIREG, ifreq, "SIOCGMIIREG") < 0) {
 		return IFSTATUS_ERR;
 	}
 
@@ -151,18 +152,19 @@ static smallint detect_link_mii(void)
 
 static smallint detect_link_priv(void)
 {
-	struct ifreq ifreq;
-	struct mii_ioctl_data *mii = (void *)&ifreq.ifr_data;
+	char buf[sizeof(struct ifreq)];
+	struct ifreq *ifreq = (struct ifreq *)buf;
+	struct mii_ioctl_data *mii = (void *)&ifreq->ifr_data;
 
-	set_ifreq_to_ifname(&ifreq);
+	set_ifreq_to_ifname(ifreq);
 
-	if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) {
+	if (network_ioctl(SIOCDEVPRIVATE, ifreq, "SIOCDEVPRIVATE") < 0) {
 		return IFSTATUS_ERR;
 	}
 
 	mii->reg_num = 1;
 
-	if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) {
+	if (network_ioctl(SIOCDEVPRIVATE+1, ifreq, "SIOCDEVPRIVATE+1") < 0) {
 		return IFSTATUS_ERR;
 	}
 

Johannes


More information about the busybox mailing list