summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoseph Henry <[email protected]>2018-07-19 17:19:06 -0700
committerJoseph Henry <[email protected]>2018-07-19 17:19:06 -0700
commit07be7a25a32b57093931d8e3186dc36656720a9c (patch)
treefc3c2d26cac3f45eb23601d0c078ed5eaef0ed4d /test
parent50396baaf19103a6375f49735e894f5dfa71e6f0 (diff)
Removed cruft from project
Diffstat (limited to 'test')
-rw-r--r--test/dummy.cpp15
-rw-r--r--test/layer2.cpp194
-rw-r--r--test/vera++/libzt85
3 files changed, 0 insertions, 294 deletions
diff --git a/test/dummy.cpp b/test/dummy.cpp
deleted file mode 100644
index 450da11..0000000
--- a/test/dummy.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <stdio.h>
-#include <unistd.h>
-
-#include "libzt.h"
-
-int main()
-{
- printf("Starting ZT service");
- zts_startjoin("my_config_path",0x0000000000000000);
-
- printf("Dummy. Going into infinite loop. Ping me or something\n");
- while(1) {
- sleep(1);
- }
-}
diff --git a/test/layer2.cpp b/test/layer2.cpp
deleted file mode 100644
index 50b82ce..0000000
--- a/test/layer2.cpp
+++ /dev/null
@@ -1,194 +0,0 @@
-// This file is built with libzt.a via `make tests`
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-
-#if defined(__APPLE__)
-#include <net/ethernet.h>
-#endif
-#if defined(__linux__)
-#include <netinet/ether.h>
-#include <sys/socket.h>
-#include <linux/if_packet.h>
-#include <net/ethernet.h>
-#endif
-
-#include "libzt.h"
-
-unsigned short csum(unsigned short *buf, int nwords)
-{
- unsigned long sum;
- for(sum=0; nwords>0; nwords--)
- sum += *buf++;
- sum = (sum >> 16) + (sum &0xffff);
- sum += (sum >> 16);
- return (unsigned short)(~sum);
-}
-
-int main(int argc , char *argv[])
-{
- if (argc < 3) {
- fprintf(stderr, "usage: layer2 <zt_home_dir> <nwid>\n");
- return 1;
- }
-
- // initialize library
- printf("Starting libzt...\n");
- zts_startjoin(argv[1], strtoull(argv[2], NULL, 16));
- uint64_t device_id = zts_get_node_id();
- fprintf(stderr, "Complete. I am %llx\n", device_id);
-
- // create socket
- int fd;
- if ((fd = zts_socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) < 0) {
- printf("There was a problem creating the raw socket\n");
- exit(-1);
- }
- fprintf(stderr, "Created raw socket (%d)\n", fd);
-
-#if defined(__APPLE__)
- fprintf(stderr, "SOCK_RAW not supported on mac builds yet. exiting");
- exit(0);
-#endif
-#if defined(__linux__) // The rest of this file isn't yet supported on non-linux platforms
- // get interface index to bind on
- struct ifreq if_idx;
- memset(&if_idx, 0, sizeof(struct ifreq));
- strncpy(if_idx.ifr_name, "libzt0", IFNAMSIZ-1);
- if (zts_ioctl(fd, SIOCGIFINDEX, &if_idx) < 0) {
- perror("SIOCGIFINDEX");
- exit(-1);
- }
- fprintf(stderr, "if_idx.ifr_ifindex=%d\n", if_idx.ifr_ifindex);
-
- // get MAC address of interface to send on
- struct ifreq if_mac;
- memset(&if_mac, 0, sizeof(struct ifreq));
- strncpy(if_mac.ifr_name, "libzt0", IFNAMSIZ-1);
- if (zts_ioctl(fd, SIOCGIFHWADDR, &if_mac) < 0) {
- perror("SIOCGIFHWADDR");
- exit(-1);
- }
- const unsigned char* mac=(unsigned char*)if_mac.ifr_hwaddr.sa_data;
- fprintf(stderr, "hwaddr=%02X:%02X:%02X:%02X:%02X:%02X\n", mac[0],mac[1],mac[2],mac[3],mac[4],mac[5]);
-
- // get IP address of interface to send on
- struct ifreq if_ip;
- memset(&if_ip, 0, sizeof(struct ifreq));
- strncpy(if_ip.ifr_name, "libzt0", IFNAMSIZ-1);
- if (zts_ioctl(fd, SIOCGIFADDR, &if_ip) < 0) {
- perror("SIOCGIFADDR");
- exit(-1);
- }
- char ipv4_str[INET_ADDRSTRLEN];
- struct sockaddr_in *in4 = (struct sockaddr_in *)&if_ip.ifr_addr;
- inet_ntop(AF_INET, (const void *)&in4->sin_addr.s_addr, ipv4_str, INET_ADDRSTRLEN);
- fprintf(stderr, "addr=%s", ipv4_str);
-
- // construct ethernet header
- int tx_len = 0;
- char sendbuf[1024];
- struct ether_header *eh = (struct ether_header *) sendbuf;
- memset(sendbuf, 0, 1024);
-
- // Ethernet header
- eh->ether_shost[0] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[0];
- eh->ether_shost[1] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[1];
- eh->ether_shost[2] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[2];
- eh->ether_shost[3] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[3];
- eh->ether_shost[4] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[4];
- eh->ether_shost[5] = ((uint8_t *)&if_mac.ifr_hwaddr.sa_data)[5];
-
- // set destination MAC
- int MY_DEST_MAC0 = 0x72;
- int MY_DEST_MAC1 = 0x92;
- int MY_DEST_MAC2 = 0xd4;
- int MY_DEST_MAC3 = 0xfd;
- int MY_DEST_MAC4 = 0x43;
- int MY_DEST_MAC5 = 0x45;
-
- eh->ether_dhost[0] = MY_DEST_MAC0;
- eh->ether_dhost[1] = MY_DEST_MAC1;
- eh->ether_dhost[2] = MY_DEST_MAC2;
- eh->ether_dhost[3] = MY_DEST_MAC3;
- eh->ether_dhost[4] = MY_DEST_MAC4;
- eh->ether_dhost[5] = MY_DEST_MAC5;
- eh->ether_type = htons(ETH_P_IP);
- tx_len += sizeof(struct ether_header);
-
-
- // Construct the IP header
- int ttl = 64;
- struct iphdr *iph = (struct iphdr *) (sendbuf + sizeof(struct ether_header));
- iph->ihl = 5;
- iph->version = 4;
- iph->tos = 16; // Low delay
- iph->id = htons(54321);
- iph->ttl = ttl; // hops
- iph->protocol = 17; // UDP
- // Source IP address, can be spoofed
- iph->saddr = inet_addr(inet_ntoa(((struct sockaddr_in *)&if_ip.ifr_addr)->sin_addr));
- // iph->saddr = inet_addr("192.168.0.112");
- // Destination IP address
- iph->daddr = inet_addr("10.7.7.1");
- tx_len += sizeof(struct iphdr);
-
- // Construct UDP header
- struct udphdr *udph = (struct udphdr *) (sendbuf + sizeof(struct iphdr) + sizeof(struct ether_header));
- udph->source = htons(3423);
- udph->dest = htons(5342);
- udph->check = 0; // skip
- tx_len += sizeof(struct udphdr);
-
- // Fill in UDP payload
- sendbuf[tx_len++] = 0xde;
- sendbuf[tx_len++] = 0xad;
- sendbuf[tx_len++] = 0xbe;
- sendbuf[tx_len++] = 0xef;
-
- // Fill in remaining header info
- // Length of UDP payload and header
- udph->len = htons(tx_len - sizeof(struct ether_header) - sizeof(struct iphdr));
- // Length of IP payload and header
- iph->tot_len = htons(tx_len - sizeof(struct ether_header));
- // Calculate IP checksum on completed header
- iph->check = csum((unsigned short *)(sendbuf+sizeof(struct ether_header)), sizeof(struct iphdr)/2);
-
- // Send packet
- // Destination address
- struct sockaddr_ll socket_address;
- // Index of the network device
- socket_address.sll_ifindex = if_idx.ifr_ifindex;
- // Address length
- socket_address.sll_halen = ETH_ALEN;
- // Destination MAC
- socket_address.sll_addr[0] = MY_DEST_MAC0;
- socket_address.sll_addr[1] = MY_DEST_MAC1;
- socket_address.sll_addr[2] = MY_DEST_MAC2;
- socket_address.sll_addr[3] = MY_DEST_MAC3;
- socket_address.sll_addr[4] = MY_DEST_MAC4;
- socket_address.sll_addr[5] = MY_DEST_MAC5;
-
- while(1)
- {
- usleep(10000);
- // Send packet
- if (zts_sendto(fd, sendbuf, tx_len, 0, (struct sockaddr*)&socket_address, sizeof(struct sockaddr_ll)) < 0)
- fprintf(stderr, "Send failed\n");
- }
-
- // dismantle all zt virtual taps
- zts_stop();
-#endif
- return 0;
-} \ No newline at end of file
diff --git a/test/vera++/libzt b/test/vera++/libzt
deleted file mode 100644
index dcd02fc..0000000
--- a/test/vera++/libzt
+++ /dev/null
@@ -1,85 +0,0 @@
-# Source files should not use the 'r' (CR) character
-rule=F001
-
-# File names should be well-formed
-rule=F002
-
-# No trailing whitespace
-rule=L001
-parameter=strict-trailing-space=0
-
-# Don't use tab characters
-# project deliberately uses TABS, so this rule should be left commented out
-# rule=L002
-
-# No leading and no trailing empty lines
-rule=L003
-
-# Line cannot be too long
-rule=L004
-parameter=max-line-length=120
-
-# There should not be too many consecutive empty lines
-rule=L005
-parameter=max-consecutive-empty-lines=5
-
-# Source file should not be too long
-# rule=L006
-# parameter=max-file-length=3000
-
-# One-line comments should not have forced continuation
-rule=T001
-
-# Reserved names should not be used for preprocessor macros
-rule=T002
-
-# Some keywords should be followed by a single space
-rule=T003
-
-# Some keywords should be immediately followed by a colon
-rule=T004
-
-# Keywords break and continue should be immediately followed by a semicolon
-rule=T005
-
-# Keywords return and throw should be immediately followed by a semicolon or a single space
-rule=T006
-
-# Semicolons should not be isolated by spaces or comments from
-rule=T007
-
-# Keywords catch, for, if, switch and while should be followed by a single space
-rule=T008
-
-# Comma should not be preceded by whitespace, but should be followed by one
-rule=T009
-
-# Identifiers should not be composed of 'l' and 'O' characters only
-rule=T010
-
-# Curly brackets from the same pair should be either in the same line or in the same column
-# rule=T011
-
-# Negation operator should not be used in its short form
-rule=T012
-
-# Source files should contain the copyright notice
-rule=T013
-
-#
-# rule=T014
-
-# HTML links in comments and string literals should be correct
-rule=T015
-
-# Calls to min/max should be protected against accidental macro
-rule=T016
-
-# Unnamed namespaces are not allowed in header files
-rule=T017
-
-# Using namespace is not allowed in header files
-rule=T018
-
-# Control structures should have complete curly-braced block of code
-rule=T019