Skip to content

Commit

Permalink
snmp big endian fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@silente committed Apr 30, 2010
1 parent b9cc3b6 commit 99d305c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions snmp.c
Expand Up @@ -271,7 +271,7 @@ static uint8_t snmp_int_to_snmp(uint64_t snmp_val, uint8_t oid_type, uint8_t * b

uint8_t tlen;
int i, j;
uint8_t *ptr = (uint8_t *) & snmp_val;
uint8_t *ptr = (uint8_t *) &snmp_val;


// check for counter, counter64 or gauge
Expand Down Expand Up @@ -339,7 +339,7 @@ PyObject *py_snmp_counter32(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;

if (!PyArg_ParseTuple(args, "bi:snmp_set_counter32", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bI:snmp_set_counter32", &oid_num, &oid_val)) {
return NULL;
}

Expand All @@ -363,7 +363,7 @@ PyObject *py_snmp_counter64(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint64_t oid_val = 0;

if (!PyArg_ParseTuple(args, "bl:snmp_set_counter64", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bK:snmp_set_counter64", &oid_num, &oid_val)) {
return NULL;
}

Expand All @@ -387,7 +387,7 @@ PyObject *py_snmp_gauge(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;

if (!PyArg_ParseTuple(args, "bi:snmp_set_gauge", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bI:snmp_set_gauge", &oid_num, &oid_val)) {
return NULL;
}

Expand Down
18 changes: 18 additions & 0 deletions utils.c
Expand Up @@ -7,6 +7,24 @@ extern struct uwsgi_server uwsgi;
uint16_t uwsgi_swap16(uint16_t x) {
return (uint16_t) ((x & 0xff) << 8 | (x & 0xff00) >> 8);
}

uint32_t uwsgi_swap32(uint32_t x) {
x = ( (x<<8) & 0xFF00FF00 ) | ( (x>>8) & 0x00FF00FF );
return (x>>16) | (x<<16);
}

// thanks to ffmpeg project for this idea :P
uint64_t uwsgi_swap64(uint64_t x) {
union {
uint64_t ll;
uint32_t l[2];
} w, r;
w.ll = x;
r.l[0] = uwsgi_swap32(w.l[1]);
r.l[1] = uwsgi_swap32(w.l[0]);
return r.ll;
}

#endif

void set_harakiri(int sec) {
Expand Down
2 changes: 2 additions & 0 deletions uwsgi.h
Expand Up @@ -667,6 +667,8 @@ void set_harakiri(int);

#ifdef __BIG_ENDIAN__
uint16_t uwsgi_swap16(uint16_t);
uint32_t uwsgi_swap32(uint32_t);
uint64_t uwsgi_swap64(uint64_t);
#endif

int init_uwsgi_app(PyObject *, PyObject *);
Expand Down

0 comments on commit 99d305c

Please sign in to comment.