From 6c2f84855fc7b93dea1582ef0c5128ac7179e3db Mon Sep 17 00:00:00 2001 From: sizhiying Date: Fri, 5 Aug 2011 13:34:40 +0800 Subject: [PATCH] repair ifaddr ifconfig ifdown command bug for loongson3a-780e.we can't set ip address more than once using ifaddr command,ifconfig command ping address failed in some situation,ifdown command will cause some bug using with ifup and ifaddr command.So we update the code. Signed-off-by: xiaqichao --- pmon/cmds/mycmd.c | 10 +++++----- pmon/netio/ifconfig.c | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pmon/cmds/mycmd.c b/pmon/cmds/mycmd.c index 97bbb878..11b2134a 100644 --- a/pmon/cmds/mycmd.c +++ b/pmon/cmds/mycmd.c @@ -1209,10 +1209,10 @@ int i; break; default: - while(ioctl(s, SIOCGIFADDR, ifra)==0) - { - (void) ioctl(s, SIOCDIFADDR, ifr); - } + //while(ioctl(s, SIOCGIFADDR, ifra)==0) + //{ + //(void) ioctl(s, SIOCDIFADDR, ifr); + //} setsin (SIN(ifra->ifra_addr), AF_INET, inet_addr(argv[2])); (void) ioctl(s, SIOCSIFADDR, ifra); if(argc>=4) @@ -1239,7 +1239,7 @@ bzero (&ifr, sizeof(ifr)); strcpy(ifr.ifr_name,argv[1]); (void) ioctl(s, SIOCGIFADDR, &ifr); printf("%s",inet_ntoa(satosin(&ifr.ifr_addr)->sin_addr)); -(void) ioctl(s, SIOCDIFADDR, &ifr); +//(void) ioctl(s, SIOCDIFADDR, &ifr); ifr.ifr_flags=0; (void) ioctl(s,SIOCSIFFLAGS,(void *)&ifr); close(s); diff --git a/pmon/netio/ifconfig.c b/pmon/netio/ifconfig.c index d7b15b5f..554b2890 100644 --- a/pmon/netio/ifconfig.c +++ b/pmon/netio/ifconfig.c @@ -183,6 +183,7 @@ ifconfig (ifname, ipaddr) local = *SAD(addreq.ifra_addr); /* now set our actual address */ + ioctl(s, SIOCSIFADDR, &addreq); if (ioctl(s, SIOCAIFADDR, &addreq) < 0) { /* Assume this means no network interface to attach to */ fprintf (stderr, "\nNOTICE: No network interface available\n"); @@ -205,7 +206,7 @@ ifconfig (ifname, ipaddr) perror("ioctl (SIOCAIFADDR) loopback"); close (s); return(0); - } + } /* * Now setup the routing tables, equivalent to: