summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/great.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/bin/great.c b/src/bin/great.c
new file mode 100644
index 0000000..11976b8
--- /dev/null
+++ b/src/bin/great.c
@@ -0,0 +1,76 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <net/if_gre.h>
+
+#define PORT 1013
+
+/*great = gre auto tunnel*/
+
+void dump(unsigned char *b,unsigned int t) {
+ for(;t;b++,t--) printf("%02x ",*b);
+}
+
+/* TODO:
+ args.
+ password?
+ clean out the extra shit.
+ clean it up even more.
+
+ arguments:
+ interface
+ listen-port
+ listen-addr
+ password?
+*/
+int main(int argc,char *argv[]) {
+ struct sockaddr_in sa;
+ struct sockaddr_in from;
+ char buf[512];
+ socklen_t sl=sizeof(struct sockaddr_in);
+ int so_link=socket(AF_LINK,SOCK_DGRAM,0);
+ int so_unspec=socket(AF_UNSPEC,SOCK_DGRAM,0);
+ int so_inet=socket(AF_INET,SOCK_DGRAM,0);
+ int so=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
+ memset(&sa,0,(size_t)sizeof(struct sockaddr_in));
+ memset(&from,0,(size_t)sizeof(struct sockaddr_in));
+ sa.sin_addr.s_addr=inet_addr("192.168.0.2");
+ sa.sin_port=htons(PORT);
+ sa.sin_family=PF_INET;
+ bind(so,(struct sockaddr *)&sa,sizeof(sa));
+ recvfrom(so,buf,sizeof(buf),0,(struct sockaddr *)&from,&sl);
+ connect(so,(struct sockaddr *)&from,sl);
+ struct in_addr addr = {from.sin_addr.s_addr};
+ printf("%s\n",inet_ntoa(addr));
+
+ struct ifreq *asdf;
+ asdf=malloc(sizeof(struct ifreq));
+
+ memset(asdf,0,sizeof(struct ifreq));
+ strcpy(asdf->ifr_name,"gre10");
+ printf("destroy: %d\n",ioctl(so_link,SIOCIFDESTROY,asdf));//destroy
+
+ memset(asdf,0,sizeof(struct ifreq));
+ strcpy(asdf->ifr_name,"gre10");
+ printf("create: %d\n",ioctl(so_link,SIOCIFCREATE,asdf));//create
+
+ memset(asdf,0,sizeof(struct ifreq));
+ strcpy(asdf->ifr_name,"gre10");
+ asdf->ifr_flags=IPPROTO_UDP;
+ printf("proto: %d\n",ioctl(so_link,GRESPROTO,asdf));//link0 link2
+
+ memset(asdf,0,sizeof(struct ifreq));
+ strcpy(asdf->ifr_name,"gre10");
+ asdf->ifr_value=so;
+ printf("gressock: %d\n",ioctl(so_inet,GRESSOCK,asdf));//set socket
+
+ sleep(1);
+ system("ifconfig gre10");//just so you can see what it looks like.
+ return 0;
+}