summaryrefslogtreecommitdiff
path: root/attic
diff options
context:
space:
mode:
authorJoseph Henry <[email protected]>2017-06-05 17:10:24 -0700
committerJoseph Henry <[email protected]>2017-06-05 17:10:24 -0700
commita94979ecd0f6b8afc1781622d630d4859dc5267e (patch)
treeea25731b87e40514a8cad2e3416e2a99ae1c7af7 /attic
parent19839eeac904b2e668d392594111fcef401bcde2 (diff)
moved old tests to attic, updated selftest and host config files
Diffstat (limited to 'attic')
-rw-r--r--attic/old_tests/tcpclient4.cpp63
-rw-r--r--attic/old_tests/tcpclient6.cpp72
-rw-r--r--attic/old_tests/tcpserver4.cpp63
-rw-r--r--attic/old_tests/tcpserver6.cpp83
-rwxr-xr-xattic/old_tests/udpclient4.cpp88
-rwxr-xr-xattic/old_tests/udpclient6.cpp43
-rwxr-xr-xattic/old_tests/udpserver4.cpp86
-rwxr-xr-xattic/old_tests/udpserver6.cpp44
8 files changed, 542 insertions, 0 deletions
diff --git a/attic/old_tests/tcpclient4.cpp b/attic/old_tests/tcpclient4.cpp
new file mode 100644
index 0000000..0d2e731
--- /dev/null
+++ b/attic/old_tests/tcpclient4.cpp
@@ -0,0 +1,63 @@
+// TCP Client test program
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int atoi(const char *str);
+int close(int filedes);
+
+#define MSG_SZ 128
+
+int main(int argc , char *argv[])
+{
+ if(argc < 3) {
+ printf("usage: client <addr> <port> <single|multiple> <n?>\n");
+ return 1;
+ }
+
+ int sock, port = atoi(argv[2]);
+ struct sockaddr_in server;
+ char message[MSG_SZ] , server_reply[MSG_SZ];
+
+ sock = socket(AF_INET , SOCK_STREAM , 0);
+ if (sock == -1) {
+ printf("could not create socket");
+ }
+ server.sin_addr.s_addr = inet_addr(argv[1]);
+ server.sin_family = AF_INET;
+ server.sin_port = htons( port );
+
+ printf("connecting...\n");
+ if (connect(sock , (struct sockaddr *)&server , sizeof(server)) < 0) {
+ perror("connect failed. Error");
+ return 1;
+ }
+ printf("connected\n");
+
+ char *msg = (char*)"welcome to the machine!";
+
+ while(1)
+ {
+ // TX
+ if(send(sock, msg, strlen(msg), 0) < 0) {
+ printf("send failed");
+ return 1;
+ }
+ else {
+ printf("TX: %s\n", msg);
+ printf("len = %ld\n", strlen(msg));
+
+ int bytes_read = read(sock, server_reply, MSG_SZ);
+ if(bytes_read < 0)
+ printf("\tRX: Nothing\n");
+ else
+ printf("\tRX = (%d bytes): %s\n", bytes_read, server_reply);
+ }
+ }
+ close(sock);
+ return 0;
+}
diff --git a/attic/old_tests/tcpclient6.cpp b/attic/old_tests/tcpclient6.cpp
new file mode 100644
index 0000000..00d2324
--- /dev/null
+++ b/attic/old_tests/tcpclient6.cpp
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+void error(char *msg) {
+ perror(msg);
+ exit(0);
+}
+
+int main(int argc, char *argv[]) {
+ int sockfd, portno, n;
+ struct sockaddr_in6 serv_addr;
+ struct hostent *server;
+ char buffer[256] = "This is a string from client!";
+
+ if (argc < 3) {
+ printf("Usage: %s \n", argv[0]);
+ exit(0);
+ }
+ portno = atoi(argv[2]);
+
+ printf("\nIPv6 TCP Client Started...\n");
+
+ //Sockets Layer Call: socket()
+ sockfd = socket(AF_INET6, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ printf("ERROR opening socket");
+
+ //Sockets Layer Call: gethostbyname2()
+ server = gethostbyname2(argv[1],AF_INET6);
+ if (server == NULL) {
+ printf("ERROR, no such host\n");
+ exit(0);
+ }
+
+ memset((char *) &serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin6_flowinfo = 0;
+ serv_addr.sin6_family = AF_INET6;
+ memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
+ serv_addr.sin6_port = htons(portno);
+
+ //Sockets Layer Call: connect()
+ if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
+ printf("ERROR connecting");
+
+
+ //Sockets Layer Call: send()
+ n = send(sockfd,buffer, strlen(buffer)+1, 0);
+ if (n < 0)
+ printf("ERROR writing to socket");
+
+ printf("sent %d bytes\n", n);
+ memset(buffer, 0, 256);
+
+ //Sockets Layer Call: recv()
+ printf("reading...\n");
+ n = recv(sockfd, buffer, 255, 0);
+ if (n < 0)
+ printf("ERROR reading from socket");
+ printf("Message from server: %s\n", buffer);
+
+ //Sockets Layer Call: close()
+ close(sockfd);
+
+ return 0;
+} \ No newline at end of file
diff --git a/attic/old_tests/tcpserver4.cpp b/attic/old_tests/tcpserver4.cpp
new file mode 100644
index 0000000..b3d929a
--- /dev/null
+++ b/attic/old_tests/tcpserver4.cpp
@@ -0,0 +1,63 @@
+#include <stdio.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int atoi(const char *str);
+
+int main(int argc , char *argv[])
+{
+ if(argc < 2) {
+ printf("usage: tcp_server <port>\n");
+ return 0;
+ }
+
+ int comm_fd, sock, client_sock, c, read_size, port = atoi(argv[1]);
+ char client_message[2000];
+
+ struct sockaddr_in servaddr;
+ struct sockaddr_in client;
+
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ bzero( &servaddr, sizeof(servaddr));
+
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_addr.s_addr = htons(INADDR_ANY);
+ servaddr.sin_port = htons(port);
+ bind(sock, (struct sockaddr *) &servaddr, sizeof(servaddr));
+
+ printf("listening\n");
+ listen(sock , 3);
+ printf("waiting to accept\n");
+ c = sizeof(struct sockaddr_in);
+
+ client_sock = accept(sock, (struct sockaddr *)&client, (socklen_t*)&c);
+ if (client_sock < 0) {
+ perror("accept failed");
+ return 0;
+ }
+ printf("connection accepted\n reading...\n");
+
+ // RX
+
+ int msglen = 1024;
+ unsigned long count = 0;
+ while(1)
+ {
+ count++;
+ int bytes_read = read(client_sock, client_message, msglen);
+ printf("[%lu] RX = (%d): %s\n", count, bytes_read, client_message);
+
+ /*
+ for(int i=0; i<bytes_read; i++) {
+ printf("%c", client_message[i]);
+ }
+ */
+ // TX
+ //int bytes_written = write(client_sock, "Server here!", 12);
+ //printf("\t\nTX = %d\n", bytes_written);
+ }
+ return 0;
+}
diff --git a/attic/old_tests/tcpserver6.cpp b/attic/old_tests/tcpserver6.cpp
new file mode 100644
index 0000000..5eea293
--- /dev/null
+++ b/attic/old_tests/tcpserver6.cpp
@@ -0,0 +1,83 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include <arpa/inet.h>
+
+void error(char *msg) {
+ perror(msg);
+ exit(1);
+}
+
+int main(int argc, char *argv[]) {
+ int sockfd, newsockfd, portno;
+ socklen_t clilen;
+ char buffer[256];
+ struct sockaddr_in6 serv_addr, cli_addr;
+ int n;
+ char client_addr_ipv6[100];
+
+ if (argc < 2) {
+ printf("Usage: %s \n", argv[0]);
+ exit(0);
+ }
+
+ printf("\nIPv6 TCP Server Started...\n");
+
+ //Sockets Layer Call: socket()
+ sockfd = socket(AF_INET6, SOCK_STREAM, 0);
+ if (sockfd < 0)
+ printf("ERROR opening socket");
+
+ bzero((char *) &serv_addr, sizeof(serv_addr));
+ portno = atoi(argv[1]);
+ serv_addr.sin6_flowinfo = 0;
+ serv_addr.sin6_family = AF_INET6;
+ serv_addr.sin6_addr = in6addr_any;
+ serv_addr.sin6_port = htons(portno);
+
+
+ //Sockets Layer Call: bind()
+ if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
+ printf("ERROR on binding");
+
+ //Sockets Layer Call: listen()
+ listen(sockfd, 5);
+ clilen = sizeof(cli_addr);
+
+ //Sockets Layer Call: accept()
+ newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
+ if (newsockfd < 0)
+ printf("ERROR on accept");
+
+ //Sockets Layer Call: inet_ntop()
+ inet_ntop(AF_INET6, &(cli_addr.sin6_addr),client_addr_ipv6, 100);
+ printf("Incoming connection from client having IPv6 address: %s\n",client_addr_ipv6);
+
+ memset(buffer,0, 256);
+
+ //Sockets Layer Call: recv()
+ n = recv(newsockfd, buffer, 255, 0);
+ if (n < 0)
+ printf("ERROR reading from socket");
+
+ printf("Message from client: %s\n", buffer);
+
+ //Sockets Layer Call: send()
+ printf("sending...\n");
+ n = send(newsockfd, "Server got your message", 23+1, 0);
+ if (n < 0)
+ printf("ERROR writing to socket");
+
+ //Sockets Layer Call: close()
+ close(sockfd);
+ close(newsockfd);
+
+ return 0;
+}
diff --git a/attic/old_tests/udpclient4.cpp b/attic/old_tests/udpclient4.cpp
new file mode 100755
index 0000000..8200fdf
--- /dev/null
+++ b/attic/old_tests/udpclient4.cpp
@@ -0,0 +1,88 @@
+/*
+ * udpclient.c - A simple UDP client
+ * usage: udpclient <host> <port>
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <fcntl.h>
+
+#define BUFSIZE 1024
+
+/*
+ * error - wrapper for perror
+ */
+void error(char *msg) {
+ perror(msg);
+ exit(0);
+}
+
+int main(int argc, char **argv) {
+ int sock, portno, n;
+ int serverlen;
+ struct sockaddr_in serveraddr;
+ struct hostent *server;
+ char *hostname;
+ char buf[BUFSIZE];
+
+ /* check command line arguments */
+ if (argc != 3) {
+ fprintf(stderr,"usage: %s <hostname> <port>\n", argv[0]);
+ exit(0);
+ }
+ hostname = argv[1];
+ portno = atoi(argv[2]);
+
+ /* socket: create the socket */
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0)
+ printf("ERROR opening socket");
+
+ /* gethostbyname: get the server's DNS entry */
+ server = gethostbyname(hostname);
+ if (server == NULL) {
+ printf("ERROR, no such host as %s\n", hostname);
+ exit(0);
+ }
+
+ /* build the server's Internet address */
+ bzero((char *) &serveraddr, sizeof(serveraddr));
+ serveraddr.sin_family = AF_INET;
+ bcopy((char *)server->h_addr,
+ (char *)&serveraddr.sin_addr.s_addr, server->h_length);
+ serveraddr.sin_port = htons(portno);
+
+ /* get a message from the user */
+ char *msg = (char*)"A message to the server!";
+ fcntl(sock, F_SETFL, O_NONBLOCK);
+ long count = 0;
+ while(1)
+ {
+ count++;
+ printf("\n\n\nTX(%lu)...\n", count);
+ sleep(1);
+ //usleep(10000);
+ //bzero(buf, BUFSIZE);
+ //printf("\nPlease enter msg: ");
+ //fgets(buf, BUFSIZE, stdin);
+
+ /* send the message to the server */
+ serverlen = sizeof(serveraddr);
+ n = sendto(sock, msg, strlen(msg), 0, (struct sockaddr *)&serveraddr, serverlen);
+ //if (n < 0)
+ // error("ERROR in sendto");
+
+ /* print the server's reply */
+ memset(buf, 0, sizeof(buf));
+ n = recvfrom(sock, buf, BUFSIZE, 0, (struct sockaddr *)&serveraddr, (socklen_t *)&serverlen);
+ //if (n < 0)
+ // printf("ERROR in recvfrom: %d", n);
+ printf("Echo from server: %s", buf);
+ }
+ return 0;
+}
diff --git a/attic/old_tests/udpclient6.cpp b/attic/old_tests/udpclient6.cpp
new file mode 100755
index 0000000..36607fa
--- /dev/null
+++ b/attic/old_tests/udpclient6.cpp
@@ -0,0 +1,43 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include <string.h>
+
+#define MAXBUF 65536
+
+int main(int argc, char* argv[])
+{
+ int status;
+ struct addrinfo sainfo, *psinfo;
+ struct hostent *server;
+ char buffer[MAXBUF];
+
+ int sock, portno, n;
+ struct sockaddr_in6 serv_addr;
+
+ if(argc < 2)
+ printf("Specify a port number\n"), exit(1);
+
+ sock = socket(PF_INET6, SOCK_DGRAM,0);
+
+ portno = atoi(argv[2]);
+ server = gethostbyname2(argv[1],AF_INET6);
+ memset((char *) &serv_addr, 0, sizeof(serv_addr));
+ serv_addr.sin6_flowinfo = 0;
+ serv_addr.sin6_family = AF_INET6;
+ memmove((char *) &serv_addr.sin6_addr.s6_addr, (char *) server->h_addr, server->h_length);
+ serv_addr.sin6_port = htons(portno);
+
+ sprintf(buffer,"Ciao");
+
+ status = sendto(sock, buffer, strlen(buffer), 0, (const struct sockaddr *)&serv_addr, sizeof(serv_addr));
+ printf("buffer : %s \t%d\n", buffer, status);
+
+ close(sock);
+ return 0;
+} \ No newline at end of file
diff --git a/attic/old_tests/udpserver4.cpp b/attic/old_tests/udpserver4.cpp
new file mode 100755
index 0000000..2280435
--- /dev/null
+++ b/attic/old_tests/udpserver4.cpp
@@ -0,0 +1,86 @@
+// UDP Server test program
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+#define MAXBUF 1024*1024
+
+void echo(int sock) {
+ char bufin[MAXBUF];
+ struct sockaddr_in remote;
+ int n;
+ socklen_t len = sizeof(remote);
+ long count = 0;
+
+ while (1) {
+ sleep(1);
+ //usleep(50);
+ count++;
+ // read a datagram from the socket (put result in bufin)
+ n=recvfrom(sock,bufin,MAXBUF,0,(struct sockaddr *)&remote,&len);
+ // print out the address of the sender
+ printf("DGRAM from %s:%d\n", inet_ntoa(remote.sin_addr), ntohs(remote.sin_port));
+
+ if (n<0) {
+ perror("Error receiving data");
+ } else {
+ printf("GOT %d BYTES (count = %ld)\n", n, count);
+ // Got something, just send it back
+ // sendto(sock,bufin,n,0,(struct sockaddr *)&remote,len);
+ printf("RX = %s\n", bufin);
+ }
+ }
+}
+
+int main(int argc, char *argv[]) {
+
+ if(argc < 2) {
+ printf("usage: udp_server <port>\n");
+ return 0;
+ }
+ int sock, port = atoi(argv[1]);
+ socklen_t len;
+ struct sockaddr_in skaddr;
+ struct sockaddr_in skaddr2;
+
+ // Create socket
+ if ((sock = socket( PF_INET, SOCK_DGRAM, 0)) < 0) {
+ printf("error creating socket\n");
+ return 0;
+ }
+ // Create address
+ skaddr.sin_family = AF_INET;
+ skaddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ skaddr.sin_port = htons(port);
+ // Bind to address
+ if (bind(sock, (struct sockaddr *) &skaddr, sizeof(skaddr))<0) {
+ printf("error binding\n");
+ return 0;
+ }
+ // find out what port we were assigned
+ len = sizeof( skaddr2 );
+ //if (getsockname(sock, (struct sockaddr *) &skaddr2, &len)<0) {
+ // printf("error getsockname\n");
+ // return 0;
+ //}
+ // Display address:port to verify it was sent over RPC correctly
+ /*
+ port = ntohs(skaddr2.sin_port);
+ int ip = skaddr2.sin_addr.s_addr;
+ unsigned char d[4];
+ d[0] = ip & 0xFF;
+ d[1] = (ip >> 8) & 0xFF;
+ d[2] = (ip >> 16) & 0xFF;
+ d[3] = (ip >> 24) & 0xFF;
+ printf("bound to address: %d.%d.%d.%d : %d\n", d[0],d[1],d[2],d[3], port);
+ */
+ // RX
+ echo(sock);
+ return(0);
+}
diff --git a/attic/old_tests/udpserver6.cpp b/attic/old_tests/udpserver6.cpp
new file mode 100755
index 0000000..4ed977b
--- /dev/null
+++ b/attic/old_tests/udpserver6.cpp
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAXBUF 65536
+
+int main(int argc, char *argv[])
+{
+ int sock;
+ int n;
+ struct sockaddr_in6 sin6;
+ socklen_t sin6len;
+ char buffer[MAXBUF];
+
+ sock = socket(PF_INET6, SOCK_DGRAM,0);
+ sin6len = sizeof(struct sockaddr_in6);
+ memset(&sin6, 0, sin6len);
+
+ sin6.sin6_port = htons(atoi(argv[1]));
+ sin6.sin6_family = AF_INET6;
+ sin6.sin6_addr = in6addr_any;
+
+ n = bind(sock, (struct sockaddr *)&sin6, sin6len);
+ if(-1 == n)
+ perror("bind"), exit(1);
+
+ //n = getsockname(sock, (struct sockaddr *)&sin6, &sin6len);
+ //printf("%d\n", ntohs(sin6.sin6_port));
+
+ while (1) {
+ sleep(1);
+ n = recvfrom(sock, buffer, MAXBUF, 0, (struct sockaddr *)&sin6, &sin6len);
+ printf("n = %d, buffer : %s\n", n, buffer);
+ }
+
+ shutdown(sock, 2);
+ close(sock);
+ return 0;
+} \ No newline at end of file