-
Notifications
You must be signed in to change notification settings - Fork 1
/
exception.c
43 lines (34 loc) · 1 KB
/
exception.c
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
/*
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);
}