git » pytipc » commit 15cae24

Add support for ADDR_MCAST and ADDR_ID.

author Alberto Bertogli
2007-12-17 14:17:17 UTC
committer Alberto Bertogli
2007-12-17 18:31:13 UTC
parent 2e442dae81992116a38342a067c6542e8ed6bf6a

Add support for ADDR_MCAST and ADDR_ID.

Signed-off-by: Alberto Bertogli <albertito@gmail.com>

examples/rdm.py +2 -2
tipc.py +24 -7
tipc_ll.c +35 -14

diff --git a/examples/rdm.py b/examples/rdm.py
index 435bff2..4e84eb6 100755
--- a/examples/rdm.py
+++ b/examples/rdm.py
@@ -6,8 +6,8 @@ import tipc
 import cs
 
 #srvaddr = (tipc.TIPC_ADDR_NAMESEQ, 2000, 10, 100, tipc.TIPC_NODE_SCOPE)
-#srvaddr = (tipc.TIPC_ADDR_NAMESEQ, 2000, 10, 100)
-srvaddr = (tipc.TIPC_ADDR_NAME, 2000, 10, 0)
+srvaddr = (tipc.TIPC_ADDR_NAMESEQ, 2000, 10, 100)
+#srvaddr = (tipc.TIPC_ADDR_NAME, 2000, 10, 0)
 #srvaddr = (tipc.TIPC_ADDR_NAME, 2000, 10)  # broken
 
 def srv():
diff --git a/tipc.py b/tipc.py
index c3595a3..f942e3c 100644
--- a/tipc.py
+++ b/tipc.py
@@ -4,12 +4,29 @@ TIPC python wrapper
 Alberto Bertogli (albertito@gmail.com)
 
 
-Addresses are expressed as (addr_type, srv_type, lower, upper [, scope]);
-where addr_type can be either TIPC_ADDR_NAME or TIPC_ADDR_NAMESEQ and scope
-can be one of TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE.
-
-If addr_type is TIPC_ADDR_NAME, then the "upper" parameter is not used (but
-should be set to an int anyway).
+Addresses are expressed as (addr_type, v1, v2, v3 [, scope]);
+where addr_type can be one of:
+	TIPC_ADDR_NAMESEQ, TIPC_ADDR_MCAST, TIPC_ADDR_NAME, and TIPC_ADDR_ID;
+and scope can be one of:
+	TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, and TIPC_NODE_SCOPE.
+
+
+The meaning of v1, v2 and v3 depend on the value of addr_type:
+
+	if addr_type is TIPC_ADDR_NAME:
+		v1 is the server type
+		v2 is the port identifier
+		v3 is ignored
+	if addr_type is TIPC_ADDR_NAMESEQ or TIPC_ADDR_MCAST:
+		v1 is the server type
+		v2 is the lower port number
+		v3 is the upper port number
+	if addr_type is TIPC_ADDR_ID:
+		v1 is the node
+		v2 is the ref
+		v3 is ignored
+
+Even when ignored, v3 must be present and be an integer.
 """
 
 import os
@@ -18,7 +35,7 @@ import tipc_ll
 
 # Exported constants
 from tipc_ll import AF_TIPC, SOL_TIPC, \
-	TIPC_ADDR_NAME, TIPC_ADDR_NAMESEQ, \
+	TIPC_ADDR_NAMESEQ, TIPC_ADDR_MCAST, TIPC_ADDR_NAME, TIPC_ADDR_ID, \
 	TIPC_ZONE_SCOPE, TIPC_CLUSTER_SCOPE, TIPC_NODE_SCOPE, \
 	TIPC_IMPORTANCE, \
 	TIPC_SRC_DROPPABLE, TIPC_DEST_DROPPABLE, \
diff --git a/tipc_ll.c b/tipc_ll.c
index 29a3b19..3793bc0 100644
--- a/tipc_ll.c
+++ b/tipc_ll.c
@@ -25,47 +25,66 @@
 
 static int fill_sockaddr(struct sockaddr_tipc *sa, PyObject *addr)
 {
-	unsigned int atype, stype, lower, upper;
+	unsigned int atype, v1, v2, v3;
 	unsigned int scope = TIPC_CLUSTER_SCOPE;
 
 	if (!PyArg_ParseTuple(addr, "IIII|I;Invalid TIPC address format",
-				&atype, &stype, &lower, &upper, &scope))
+				&atype, &v1, &v2, &v3, &scope))
 		return 0;
 
 	memset(sa, 0, sizeof(struct sockaddr_tipc));
 
 	sa->family = AF_TIPC;
 	sa->scope = scope;
-
-	if (atype == TIPC_ADDR_NAME) {
-		sa->addrtype = TIPC_ADDR_NAME;
-		sa->addr.name.name.type = stype;
-		sa->addr.name.name.instance = lower;
+	sa->addrtype = atype;
+
+	if (atype == TIPC_ADDR_NAMESEQ || atype == TIPC_ADDR_MCAST) {
+		sa->addr.nameseq.type = v1;
+		sa->addr.nameseq.lower = v2;
+		sa->addr.nameseq.upper = v3;
+	} else if (atype == TIPC_ADDR_NAME) {
+		sa->addr.name.name.type = v1;
+		sa->addr.name.name.instance = v2;
+	} else if (atype == TIPC_ADDR_ID) {
+		sa->addr.id.node = v1;
+		sa->addr.id.ref = v2;
 	} else {
-		sa->addrtype = TIPC_ADDR_NAMESEQ;
-		sa->addr.nameseq.type = stype;
-		sa->addr.nameseq.lower = lower;
-		sa->addr.nameseq.upper = upper;
+		/* Shouldn't happen */
+		PyErr_SetString(PyExc_TypeError, "Invalid address type");
+		return 0;
 	}
+
 	return 1;
 }
 
 static PyObject *sa_to_tuple(const struct sockaddr_tipc *sa)
 {
-	if (sa->addrtype == TIPC_ADDR_NAMESEQ) {
+	if (sa->addrtype == TIPC_ADDR_NAMESEQ ||
+			sa->addrtype == TIPC_ADDR_MCAST) {
 		return Py_BuildValue("IIIII",
 				sa->addrtype,
 				sa->addr.nameseq.type,
 				sa->addr.nameseq.lower,
 				sa->addr.nameseq.upper,
 				sa->scope);
-	} else {
+	} else if (sa->addrtype == TIPC_ADDR_NAME) {
 		return Py_BuildValue("IIIII",
 				sa->addrtype,
 				sa->addr.name.name.type,
 				sa->addr.name.name.instance,
 				sa->addr.name.name.instance,
 				sa->scope);
+	} else if (sa->addrtype == TIPC_ADDR_ID) {
+		return Py_BuildValue("IIIII",
+				sa->addrtype,
+				sa->addr.id.node,
+				sa->addr.id.ref,
+				0,
+				sa->scope);
+	} else {
+		/* Shouldn't happen */
+		PyErr_SetString(PyExc_TypeError, "Invalid address type");
+		return NULL;
 	}
 }
 
@@ -286,8 +305,10 @@ PyMODINIT_FUNC inittipc_ll(void)
 	PyModule_AddIntConstant(m, "AF_TIPC", AF_TIPC);
 
 	/* for addresses */
-	PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME);
 	PyModule_AddIntConstant(m, "TIPC_ADDR_NAMESEQ", TIPC_ADDR_NAMESEQ);
+	PyModule_AddIntConstant(m, "TIPC_ADDR_MCAST", TIPC_ADDR_MCAST);
+	PyModule_AddIntConstant(m, "TIPC_ADDR_NAME", TIPC_ADDR_NAME);
+	PyModule_AddIntConstant(m, "TIPC_ADDR_ID", TIPC_ADDR_ID);
 
 	PyModule_AddIntConstant(m, "TIPC_ZONE_SCOPE", TIPC_ZONE_SCOPE);
 	PyModule_AddIntConstant(m, "TIPC_CLUSTER_SCOPE", TIPC_CLUSTER_SCOPE);