mirror of https://github.com/sipwise/rtpengine.git
parent
033b7d1f55
commit
8c06d3254a
@ -0,0 +1,24 @@
|
||||
#include "stun.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
struct stun {
|
||||
u_int16_t msg_type;
|
||||
u_int16_t msg_len;
|
||||
u_int32_t cookie;
|
||||
unsigned char transaction[12];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
int stun(const char *buf, int len) {
|
||||
const struct stun *s = (const void *) buf;
|
||||
int msglen, method, class;
|
||||
|
||||
msglen = ntohs(s->msg_len);
|
||||
class = method = ntohl(s->msg_type);
|
||||
class = ((class & 0x10) >> 4) | ((class & 0x100) >> 7);
|
||||
method = (method & 0xf) | ((method & 0xe0) >> 1) | ((method & 0x3e00) >> 2);
|
||||
if (method != 0x1) /* binding */
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#ifndef _STUN_H_
|
||||
#define _STUN_H_
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
static inline int is_stun(const char *bx, int len) {
|
||||
const unsigned char *b = (const void *) bx;
|
||||
const u_int32_t *u;
|
||||
|
||||
if (len < 20)
|
||||
return 0;
|
||||
if ((b[0] & 0xb0) != 0x00)
|
||||
return 0;
|
||||
if ((b[3] & 0x3) != 0x0)
|
||||
return 0;
|
||||
u = (const void *) &b[4];
|
||||
if (*u != htonl(0x2112A442))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int stun(const char *buf, int len);
|
||||
|
||||
|
||||
#endif
|
Loading…
Reference in new issue