File: exception.c

package info (click to toggle)
python-libpcap 0.6.1%2Bcvs.2007.07.28-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 128 kB
  • ctags: 116
  • sloc: ansic: 616; python: 375; makefile: 34
file content (43 lines) | stat: -rw-r--r-- 1,027 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

/*
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 <stdlib.h>
#include <pcap.h>
#include <Python.h>
#include "pypcap.h"

void throw_exception(int err, char *ebuf)
{
  if (err == -1) {
    PyErr_SetString(PyExc_Exception, ebuf);
  } else {
    PyErr_Format(PyExc_Exception, "[Error %d] %s", err, ebuf);
  }
}

void throw_pcap_exception(pcap_t *pcap, char *fname)
{
  PyObject *errorArgs;
  
  if (fname == NULL)
    errorArgs = Py_BuildValue("(s)", pcap_geterr(pcap));
  else
    errorArgs = Py_BuildValue("(ss)", pcap_geterr(pcap), fname);
  PyErr_SetObject(pcapError, errorArgs);
  Py_DECREF(errorArgs);
}