summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorArend van Spriel <aspriel@gmail.com>2015-05-10 10:22:17 (GMT)
committerThomas Haller <thaller@redhat.com>2015-05-12 11:26:15 (GMT)
commit36f4adfa8130b3a3d922121e1210428e4a70c897 (patch)
treee79680058101d03663670de27eeea4ffb5876b1d /python
parentff6467135e39f9a50bfff787098ff3f51e1d1662 (diff)
downloadlibnl-36f4adfa8130b3a3d922121e1210428e4a70c897.zip
libnl-36f4adfa8130b3a3d922121e1210428e4a70c897.tar.gz
libnl-36f4adfa8130b3a3d922121e1210428e4a70c897.tar.bz2
python: capi: add nla_put() function to python capi
Adding nla_put() to the capi using a typemap on the input parameter which needs to be either a str or bytearray. Otherwise a SWIG exception with be thrown. Signed-off-by: Arend van Spriel <aspriel@gmail.com>
Diffstat (limited to 'python')
-rw-r--r--python/netlink/capi.i14
1 files changed, 14 insertions, 0 deletions
diff --git a/python/netlink/capi.i b/python/netlink/capi.i
index f59effa..98f4e33 100644
--- a/python/netlink/capi.i
+++ b/python/netlink/capi.i
@@ -17,6 +17,7 @@
%include <stdint.i>
%include <cstring.i>
%include <cpointer.i>
+%include <exception.i>
%inline %{
struct nl_dump_params *alloc_dump_params(void)
@@ -812,6 +813,19 @@ extern void *nla_data(struct nlattr *);
%typemap(out) void *;
extern int nla_type(const struct nlattr *);
+%typemap(in) (int, const void *) {
+ $1 = Py_SIZE($input);
+ if (PyByteArray_Check($input)) {
+ $2 = ($2_ltype)PyByteArray_AsString($input);
+ } else if (PyString_Check($input)) {
+ $2 = ($2_ltype)PyString_AsString($input);
+ } else
+ SWIG_exception(SWIG_TypeError,
+ "pointer must be bytearray or string.");
+}
+extern int nla_put(struct nl_msg *, int, int, const void *);
+%typemap(in) const void *;
+
/* Integer attribute */
extern uint8_t nla_get_u8(struct nlattr *);
extern int nla_put_u8(struct nl_msg *, int, uint8_t);