diff options
author | David Cantrell <dcantrell@redhat.com> | 2006-10-02 19:29:21 +0000 |
---|---|---|
committer | David Cantrell <dcantrell@redhat.com> | 2006-10-02 19:29:21 +0000 |
commit | c605886cce2f117cd3b74bbd32746737962b06e1 (patch) | |
tree | d3816e82f3378ad55b1b434c6eed031d6b0df593 /isys | |
parent | 287138b5f91b3061df3f4bb629e264eab0553799 (diff) | |
download | anaconda-c605886cce2f117cd3b74bbd32746737962b06e1.tar.gz anaconda-c605886cce2f117cd3b74bbd32746737962b06e1.tar.xz anaconda-c605886cce2f117cd3b74bbd32746737962b06e1.zip |
* isys/isys.py (inet_doConvertPrefixToNetmask): Removed since it does
not work right. Added prefix2netmask() passthrough to _isys.
* isys/isys.c (doConvertPrefixToNetmask): When Python fails, use C.
Added isys.prefix2netmask() for use in Python code to convert a CIDR
prefix to a dotted-quad format netmask (#207845).
* iw/network_gui.py (NetworkWindow): Use isys.prefix2netmask()
* textw/network_text.py (NetworkDeviceWindow): Use isys.prefix2netmask()
Diffstat (limited to 'isys')
-rw-r--r-- | isys/isys.c | 15 | ||||
-rw-r--r-- | isys/isys.py | 10 |
2 files changed, 18 insertions, 7 deletions
diff --git a/isys/isys.c b/isys/isys.c index 23cb85342..378316fdf 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -120,6 +120,7 @@ static PyObject * doProbeBiosDisks(PyObject * s, PyObject * args); static PyObject * doGetBiosDisk(PyObject * s, PyObject * args); static PyObject * doSegvHandler(PyObject *s, PyObject *args); static PyObject * doAuditDaemon(PyObject *s); +static PyObject * doConvertPrefixToNetmask(PyObject *s, PyObject *args); static PyMethodDef isysModuleMethods[] = { { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL }, @@ -175,6 +176,7 @@ static PyMethodDef isysModuleMethods[] = { { "getbiosdisk",(PyCFunction) doGetBiosDisk, METH_VARARGS,NULL}, { "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL }, { "auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL }, + { "prefix2netmask", (PyCFunction) doConvertPrefixToNetmask, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } } ; @@ -651,6 +653,19 @@ static PyObject * doDhcpNetDevice(PyObject * s, PyObject * args) { return rc; } +static PyObject * doConvertPrefixToNetmask (PyObject * s, PyObject * args) { + char *prefix = NULL; + int mask = 0; + char dst[INET_ADDRSTRLEN]; + + if (!PyArg_ParseTuple(args, "s", &prefix)) return NULL; + + mask = htonl(~((1 << (32 - atoi(prefix))) - 1)); + inet_ntop(AF_INET, (struct in_addr *) &mask, dst, INET_ADDRSTRLEN); + + return Py_BuildValue("s", dst); +} + #include <linux/fb.h> static PyObject * doFbconProbe (PyObject * s, PyObject * args) { diff --git a/isys/isys.py b/isys/isys.py index e62713ad0..f62148e85 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -449,13 +449,6 @@ def inet_convertNetmaskToPrefix (netmask): return prefix -# Converts IPv4 CIDR prefix to a dotted-quad netmask -def inet_convertPrefixToNetmask (prefix): - (m,) = struct.unpack('I',socket.inet_pton(socket.AF_INET,'255.255.255.255')) - tmp = m >> (32 - int(prefix)) - ret = socket.inet_ntop(socket.AF_INET, struct.pack('i', tmp)) - return ret - def getopt(*args): warnings.warn("isys.getopt is deprecated. Use optparse instead.", DeprecationWarning, stacklevel=2) @@ -886,6 +879,9 @@ def getIPAddress(dev): def resetFileContext(fn, instroot = '/'): return _isys.resetFileContext(fn, instroot) +def prefix2netmask(prefix): + return _isys.prefix2netmask(prefix) + auditDaemon = _isys.auditdaemon handleSegv = _isys.handleSegv |