~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/runner/portmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2001-2004 Twisted Matrix Laboratories.
 
3
 * See LICENSE for details.
 
4
 
 
5
 * 
 
6
 */
 
7
 
 
8
/* portmap.c: A simple Python wrapper for pmap_set(3) and pmap_unset(3) */
 
9
 
 
10
#include <Python.h>
 
11
#include <rpc/rpc.h>
 
12
#include <rpc/pmap_clnt.h>
 
13
 
 
14
static PyObject * portmap_set(PyObject *self, PyObject *args)
 
15
{
 
16
        unsigned long program, version;
 
17
        int protocol;
 
18
        unsigned short port;
 
19
        
 
20
        if (!PyArg_ParseTuple(args, "llih:set", 
 
21
                              &program, &version, &protocol, &port))
 
22
                return NULL;
 
23
 
 
24
        pmap_unset(program, version);
 
25
        pmap_set(program, version, protocol, port);
 
26
        
 
27
        Py_INCREF(Py_None);
 
28
        return Py_None;
 
29
}
 
30
 
 
31
static PyObject * portmap_unset(PyObject *self, PyObject *args)
 
32
{
 
33
        unsigned long program, version;
 
34
        
 
35
        if (!PyArg_ParseTuple(args, "ll:unset",
 
36
                              &program, &version))
 
37
                return NULL;
 
38
 
 
39
        pmap_unset(program, version);
 
40
        
 
41
        Py_INCREF(Py_None);
 
42
        return Py_None;
 
43
}
 
44
 
 
45
static PyMethodDef PortmapMethods[] = {
 
46
        {"set", portmap_set, METH_VARARGS, 
 
47
         "Set an entry in the portmapper."},
 
48
        {"unset", portmap_unset, METH_VARARGS,
 
49
         "Unset an entry in the portmapper."},
 
50
        {NULL, NULL, 0, NULL}
 
51
};
 
52
 
 
53
void initportmap(void)
 
54
{
 
55
        (void) Py_InitModule("portmap", PortmapMethods);
 
56
}
 
57