File: error.c

package info (click to toggle)
python-libpcap 0.6.4-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 340 kB
  • ctags: 592
  • sloc: ansic: 4,129; python: 522; makefile: 2
file content (46 lines) | stat: -rw-r--r-- 1,169 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

/*
Python libpcap
Copyright (C) 2001, David Margrave
Copyright (C) 2004, William Lewis
Based PY-libpcap (C) 1998, Aaron L. Rhodes

This program is free software; you can redistribute it and/or
modify it under the terms of the BSD Licence. See the file COPYING
for details.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
*/

#include <pcap.h>
#include <Python.h>

/* static */ PyObject *pcapError;
static PyObject *error_object;

void init_errors(PyObject *m)
{
  const char *modname;
  char *namebuf;
  PyObject *d;

  d = PyModule_GetDict(m);
  modname = PyModule_GetName(m);
  namebuf = malloc(strlen(modname) + 11  /* ".EXCEPTION" + NUL */ );

  /* the base class */
  sprintf(namebuf, "%s.error", modname);
  pcapError = PyErr_NewException(namebuf, NULL, NULL);
  PyDict_SetItemString(d, "error", pcapError);

  sprintf(namebuf, "%s.EXCEPTION", modname);
  error_object = PyErr_NewException(namebuf,pcapError,NULL);
  PyDict_SetItemString(d, "EXCEPTION", error_object);
  Py_DECREF(error_object);

  free(namebuf);
  return;
}