[packages/python-ifconfig] Add package python-ifconfig
[openwrt/svn-archive/archive.git] / lang / python-ifconfig / patches / 001-errorcheck.patch
1 --- a/ifconfig.old 2010-12-10 11:18:19.890041196 +0100
2 +++ b/ifconfig.c 2010-12-10 11:59:58.170347114 +0100
3 @@ -43,6 +43,9 @@
4 char addr[20];
5 char brdaddr[20];
6 char netmask[20];
7 + short int flags = 0;
8 +
9 + hwaddr[0] = addr[0] = brdaddr[0] = netmask[0] = 0;
10
11 if (!PyArg_ParseTuple(args, "s", &itf))
12 return NULL;
13 @@ -51,29 +54,35 @@
14
15 strcpy(ifreq.ifr_name, itf);
16
17 - /* hardware address */
18 - ioctl(fd, SIOCGIFHWADDR, &ifreq);
19 - hw = ifreq.ifr_hwaddr.sa_data;
20 - sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
21 - *hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
22 -
23 - /* address */
24 - ioctl(fd, SIOCGIFADDR, &ifreq);
25 - sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
26 - sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
27 -
28 - /* broadcast */
29 - ioctl(fd, SIOCGIFBRDADDR, &ifreq);
30 - sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
31 - sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
32 -
33 - /* netmask */
34 - ioctl(fd, SIOCGIFNETMASK, &ifreq);
35 - sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
36 - sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
37 + /* flags */
38 + if (ioctl(fd, SIOCGIFFLAGS, &ifreq) == 0) {
39 + flags = ifreq.ifr_flags;
40 +
41 + /* hardware address */
42 + ioctl(fd, SIOCGIFHWADDR, &ifreq);
43 + hw = ifreq.ifr_hwaddr.sa_data;
44 + sprintf(hwaddr, "%02x:%02x:%02x:%02x:%02x:%02x",
45 + *hw, *(hw + 1), *(hw + 2), *(hw + 3), *(hw + 4), *(hw + 5));
46 +
47 + /* address */
48 + ioctl(fd, SIOCGIFADDR, &ifreq);
49 + sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
50 + sprintf(addr, "%s", inet_ntoa(sin->sin_addr));
51 +
52 + /* broadcast */
53 + ioctl(fd, SIOCGIFBRDADDR, &ifreq);
54 + sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
55 + sprintf(brdaddr, "%s", inet_ntoa(sin->sin_addr));
56 +
57 + /* netmask */
58 + ioctl(fd, SIOCGIFNETMASK, &ifreq);
59 + sin = (struct sockaddr_in *)&ifreq.ifr_broadaddr;
60 + sprintf(netmask, "%s", inet_ntoa(sin->sin_addr));
61 + }
62
63 close(fd);
64 - return Py_BuildValue("{s:s,s:s,s:s,s:s}",
65 + return Py_BuildValue("{s:i,s:s,s:s,s:s,s:s}",
66 + "flags", flags,
67 "hwaddr", hwaddr,
68 "addr", addr,
69 "brdaddr", brdaddr,