예제 #1
0
static bool test_swrap_socket(struct torture_context *tctx)
{
	backup_env();
	setenv("SOCKET_WRAPPER_DIR", "foo", 1);

	torture_assert_int_equal(tctx, swrap_socket(1337, 1337, 0), -1, "unknown address family fails");
	torture_assert_int_equal(tctx, errno, EAFNOSUPPORT, "correct errno set");
	torture_assert_int_equal(tctx, swrap_socket(AF_INET, 1337, 0), -1, "unknown type fails");
	torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set");
	torture_assert_int_equal(tctx, swrap_socket(AF_INET, SOCK_DGRAM, 10), -1, "unknown protocol fails");
	torture_assert_int_equal(tctx, errno, EPROTONOSUPPORT, "correct errno set");

	restore_env();

	return true;
}
예제 #2
0
static PyObject *py_socket_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{
	int family, sock_type, protocol;
	int *sock;
	PyObject *pysocket;

	if (!PyArg_ParseTuple(args, "iii:socket", &family, &sock_type, &protocol)) {
		return NULL;
	}

	sock = talloc_zero(NULL, int);
	if (sock == NULL) {
		return PyErr_NoMemory();
	}

	*sock = swrap_socket(family, sock_type, protocol);
	if (*sock < 0) {
		return PyErr_SetFromErrno(py_socket_error);
	}

	if ((pysocket = pytalloc_steal(type, sock)) == NULL) {
		return PyErr_NoMemory();
	}

	return pysocket;
}