[asterisk-commits] [svn-commits] branch mogorman/asterisk-xmpp
r17822 - /team/mogorman/asterisk-xmpp/res/stun/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Apr 6 03:52:08 MST 2006
Author: mogorman
Date: Thu Apr 6 05:52:07 2006
New Revision: 17822
URL: http://svn.digium.com/view/asterisk?rev=17822&view=rev
Log:
all basic stun implemented...
Modified:
team/mogorman/asterisk-xmpp/res/stun/Makefile
team/mogorman/asterisk-xmpp/res/stun/client.cpp
team/mogorman/asterisk-xmpp/res/stun/main.c
team/mogorman/asterisk-xmpp/res/stun/stunwrapper.cpp
Modified: team/mogorman/asterisk-xmpp/res/stun/Makefile
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/stun/Makefile?rev=17822&r1=17821&r2=17822&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/stun/Makefile (original)
+++ team/mogorman/asterisk-xmpp/res/stun/Makefile Thu Apr 6 05:52:07 2006
@@ -15,7 +15,7 @@
#LDFLAGS+= -lnsl -lsocket
-all: client libstunwrapper test
+all: client libstunwrapper libstun.a test
clean:
- rm *.o client
@@ -33,8 +33,8 @@
test:
gcc main.c libstunwrapper.a -lstdc++
-libstunwrapper: stunwrapper.o
- ar crv libstunwrapper.a stunwrapper.o
+libstunwrapper: stunwrapper.o stun.o udp.o
+ ar crv libstunwrapper.a stunwrapper.o stun.o udp.o
%:RCS/%
co $@
Modified: team/mogorman/asterisk-xmpp/res/stun/client.cpp
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/stun/client.cpp?rev=17822&r1=17821&r2=17822&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/stun/client.cpp (original)
+++ team/mogorman/asterisk-xmpp/res/stun/client.cpp Thu Apr 6 05:52:07 2006
@@ -3,15 +3,11 @@
#include <iostream>
#include <cstdlib>
-#ifdef WIN32
-#include <time.h>
-#else
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <netinet/in.h>
#include <errno.h>
-#endif
#include "udp.h"
#include "stun.h"
@@ -257,13 +253,8 @@
stunServerAddr.addr,
stunServerAddr.port,verbose );
}
-#ifdef WIN32 // !cj! TODO - should fix this up in windows
- clock_t now = clock();
- assert( CLOCKS_PER_SEC == 1000 );
- while ( clock() <= now+10 ) { };
-#else
+
usleep(10*1000);
-#endif
}
}
else if (testNum==-2)
Modified: team/mogorman/asterisk-xmpp/res/stun/main.c
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/stun/main.c?rev=17822&r1=17821&r2=17822&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/stun/main.c (original)
+++ team/mogorman/asterisk-xmpp/res/stun/main.c Thu Apr 6 05:52:07 2006
@@ -2,7 +2,7 @@
int main() {
void *hott, *cold;
- hott=gethead();
+ hott=insertstun();
cold = insertstun();
printf("HELLO \n");
printf("HELLO %d\n",getSrcPort(hott));
Modified: team/mogorman/asterisk-xmpp/res/stun/stunwrapper.cpp
URL: http://svn.digium.com/view/asterisk/team/mogorman/asterisk-xmpp/res/stun/stunwrapper.cpp?rev=17822&r1=17821&r2=17822&view=diff
==============================================================================
--- team/mogorman/asterisk-xmpp/res/stun/stunwrapper.cpp (original)
+++ team/mogorman/asterisk-xmpp/res/stun/stunwrapper.cpp Thu Apr 6 05:52:07 2006
@@ -8,9 +8,15 @@
#include "udp.h"
#include "stun.h"
+#define MAX_NIC 3
+
struct Node {
StunAddress4 stunServerAddr;
+ StunAddress4 sAddr[MAX_NIC];
+ int retval[MAX_NIC];
int srcPort;
+ int numNic;
+ NatType type;
Node *next;
};
@@ -18,9 +24,7 @@
public:
stunwrapper(void)
{
- head = (struct Node *)malloc(sizeof(struct Node));
- memset(head, 0, sizeof(struct Node));
- head->srcPort = 0;
+ head = NULL;
};
int getSrcPort(Node *mynode)
@@ -36,12 +40,87 @@
void *gethead()
{
return head;
- }
+ };
+
+ void *setupstun(Node *mynode, char *server, char *nic, int port)
+ {
+ if (stunParseServerName(nic, mynode->sAddr[mynode->numNic++]))
+ return NULL;
+ if (stunParseServerName(server, mynode->stunServerAddr))
+ return NULL;
+ mynode->srcPort = port;
+ mynode->sAddr[mynode->numNic].port=port;
+ return mynode;
+ };
+
+ void *executestun(Node *mynode)
+ {
+ int i;
+ bool presPort;
+ bool hairpin;
+
+ for(i = 0; i < mynode->numNic; i++) {
+ presPort=false;
+ hairpin=false;
+ mynode->type = stunNatType( mynode->stunServerAddr, 0, &presPort, &hairpin, mynode->srcPort, &mynode->sAddr[i]);
+ switch(mynode->type) {
+ case StunTypeFailure:
+ mynode->retval[i] = -1;
+ return(NULL);
+ break;
+ case StunTypeUnknown:
+ mynode->retval[i] = 0xEE;
+ break;
+ case StunTypeOpen:
+ mynode->retval[i] = 0x00;
+ break;
+ case StunTypeIndependentFilter:
+ mynode->retval[i] = 0x02;
+ break;
+ case StunTypeDependentFilter:
+ mynode->retval[i] = 0x04;
+ break;
+ case StunTypePortDependedFilter:
+ mynode->retval[i] = 0x06;
+ break;
+ case StunTypeDependentMapping:
+ mynode->retval[i] = 0x08;
+ break;
+ case StunTypeFirewall:
+ mynode->retval[i] = 0x0A;
+ break;
+ case StunTypeBlocked:
+ mynode->retval[i] = 0x0C;
+ break;
+ default:
+ mynode->retval[i] = 0x0E; // Unknown NAT type
+ break;
+ }
+
+ if (!hairpin) {
+ mynode->retval[i] |= 0x10;
+ }
+
+ if (presPort) {
+ mynode->retval[i] |= 0x01;
+ }
+ }
+ };
+
void *addpointer()
{
+ int i;
Node *newnode;
newnode = (struct Node *)malloc(sizeof(struct Node));
memset(newnode, 0, sizeof(struct Node));
+ newnode->srcPort = 0;
+ newnode->numNic = 0;
+ newnode->stunServerAddr.addr=0;
+ for(i = 0; i < MAX_NIC; i++) {
+ newnode->sAddr[i].addr=0;
+ newnode->sAddr[i].port=0;
+ newnode->retval[i]=0;
+ }
newnode->next = head;
head = newnode;
return head;
@@ -71,6 +150,18 @@
wrapper.setSrcPort(mynode, i);
}
+ void *setupstun(void *pointer, char *server, char *nic, int port)
+ {
+ Node *mynode = (struct Node *)pointer;
+ return wrapper.setupstun(mynode, server, nic, port);
+ }
+
+ void *executestun(void *pointer)
+ {
+ Node *mynode = (struct Node *)pointer;
+ return executestun(mynode);
+ }
+
void *gethead()
{
return wrapper.gethead();
_______________________________________________
--Bandwidth and Colocation provided by Easynews.com --
svn-commits mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/svn-commits
More information about the asterisk-commits
mailing list