Initial commit.
This commit is contained in:
198
client-socket.c
Normal file
198
client-socket.c
Normal file
@ -0,0 +1,198 @@
|
||||
/* a client in the unix domain */
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include "ipx.h"
|
||||
#include "ipxstack.h"
|
||||
|
||||
void *mmData = "AK> hello \0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxM";
|
||||
ipx_response_t *conn;
|
||||
|
||||
void error(const char *);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sockfd, servlen,n;
|
||||
int sockfd2, servlen2;
|
||||
int sockfd3, servlen3;
|
||||
struct sockaddr_un serv_addr;
|
||||
struct sockaddr_un serv_addr2;
|
||||
struct sockaddr_un serv_addr3;
|
||||
ipx_frame_t *ipx_packet;
|
||||
char buffer[1024];
|
||||
// uint32_t conn_pid;
|
||||
|
||||
ipx_request_t *init_connection;
|
||||
ipx_request_t *close_connection;
|
||||
|
||||
init_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!init_connection)
|
||||
error("Out of memory: init_connection");
|
||||
close_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!close_connection)
|
||||
error("Out of memory: close_connection");
|
||||
|
||||
// ethernet_frame_t *ethernet;
|
||||
ipx_frame_t *ipx;
|
||||
void *ipx_data;
|
||||
|
||||
size_t data_size = 512;
|
||||
size_t packet_size = sizeof(ipx_frame_t) + data_size;
|
||||
ipx_packet = malloc(packet_size);
|
||||
if(!ipx_packet) {
|
||||
error("Out of memory");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
ipx_packet->checksum = 0xffff;
|
||||
ipx_packet->length = htons(packet_size);
|
||||
ipx_packet->hops = 0;
|
||||
ipx_packet->type = 0x05;
|
||||
ipx_packet->dest_net = 0;
|
||||
ipx_packet->dest_node[0] = 0xffff;
|
||||
ipx_packet->dest_node[1] = 0xffff;
|
||||
ipx_packet->dest_node[2] = 0xffff;
|
||||
ipx_packet->dest_socket = htons(0x869b);
|
||||
ipx_packet->src_net = 0;
|
||||
ipx_packet->src_node[0] = htons(0x984b);
|
||||
ipx_packet->src_node[1] = htons(0xe108);
|
||||
ipx_packet->src_node[2] = htons(0x8847);
|
||||
ipx_packet->src_socket = htons(0x869b);
|
||||
memcpy(ipx_packet->data, mmData, data_size);
|
||||
|
||||
bzero((char *)&serv_addr,sizeof(serv_addr));
|
||||
serv_addr.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr.sun_path, argv[1]);
|
||||
servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
|
||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *) &serv_addr, servlen) < 0)
|
||||
error("Connecting");
|
||||
|
||||
// printf("Please enter your message: ");
|
||||
bzero(buffer,1002);
|
||||
init_connection->request_type = OPEN_SOCKET;
|
||||
init_connection->src_socket = 0x1234;
|
||||
init_connection->dest_net = 0x00000000;
|
||||
init_connection->dest_node[0] = 0xffff;
|
||||
init_connection->dest_node[1] = 0xffff;
|
||||
init_connection->dest_node[2] = 0xffff;
|
||||
init_connection->dest_socket = 0x869b;
|
||||
// init_connection->pid = 1234;
|
||||
// printf("Init connection: request_type=%i; src_socket=%0x; pid=%i\n", init_connection->request_type, init_connection->src_socket, init_connection->pid);
|
||||
memcpy(buffer, init_connection, sizeof(ipx_request_t));
|
||||
/* memcpy(buffer, frame, 1000);*/
|
||||
//fgets(buffer,80,stdin);
|
||||
/*
|
||||
ethernet = (ethernet_frame_t *) &buffer;
|
||||
ipx = (ipx_frame_t *) ðernet->ipxpacket;
|
||||
ipx_data = (void *)ipx->data;
|
||||
printf("data: %s", ipx_data);
|
||||
*/
|
||||
// write(sockfd,buffer,1000);
|
||||
printf("Setting up the Connection\n");
|
||||
write(sockfd, init_connection, sizeof(ipx_request_t));
|
||||
printf("Waiting for ansver\n");
|
||||
n=read(sockfd,buffer,280);
|
||||
printf("The return message was\n");
|
||||
|
||||
conn = (ipx_response_t *)buffer;
|
||||
if(conn->error != NO_ERROR) {
|
||||
printf("Error: socket is already opened\n");
|
||||
exit(2);
|
||||
}
|
||||
// printf("My connection: socket=%0x; socket name=%s; pid=%i\n", conn->src_socket, conn->socket_name, conn->pid);
|
||||
// conn_pid = conn->pid;
|
||||
write(1,buffer,n);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sleep(2);
|
||||
|
||||
char input_string[200];
|
||||
int loop = 1;
|
||||
|
||||
printf("Sending data on data sockeet\n");
|
||||
bzero(buffer, 1002);
|
||||
bzero((char *)&serv_addr3, sizeof(serv_addr3));
|
||||
serv_addr3.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr3.sun_path, "./socket.1234");
|
||||
servlen3 = strlen(serv_addr3.sun_path) + sizeof(serv_addr3.sun_family);
|
||||
if((sockfd3 = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
error("Creating data socket");
|
||||
|
||||
if(connect(sockfd3, (struct sockaddr *) &serv_addr3, servlen3) < 0)
|
||||
error("Connecting data socket");
|
||||
|
||||
while(loop) {
|
||||
bzero(buffer, 1002);
|
||||
gets(input_string);
|
||||
if(strncmp(input_string, "exit", 4) == 0)
|
||||
{
|
||||
loop = 0;
|
||||
}
|
||||
strncpy(buffer+6, input_string, sizeof(input_string));
|
||||
memcpy(ipx_packet->data, buffer, 512);
|
||||
write(sockfd3, ipx_packet, 1000);
|
||||
}
|
||||
close(sockfd3);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sleep(2);
|
||||
printf("Closing connection.\n");
|
||||
bzero(buffer, 1002);
|
||||
close_connection->request_type = CLOSE_SOCKET;
|
||||
close_connection->src_socket = 0x1234;
|
||||
// close_connection->pid = conn_pid;
|
||||
// printf("Closing connection: request_type=%i; src_socket=%0x; pid=%i\n", close_connection->request_type, close_connection->src_socket, close_connection->pid);
|
||||
|
||||
bzero((char *)&serv_addr2,sizeof(serv_addr2));
|
||||
serv_addr2.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr2.sun_path, argv[1]);
|
||||
servlen2 = strlen(serv_addr2.sun_path) + sizeof(serv_addr2.sun_family);
|
||||
if ((sockfd2 = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd2, (struct sockaddr *) &serv_addr2, servlen2) < 0)
|
||||
error("Connecting");
|
||||
|
||||
bzero(buffer,1002);
|
||||
memcpy(buffer, close_connection, sizeof(ipx_request_t));
|
||||
printf("Closing connection.....\n");
|
||||
|
||||
|
||||
write(sockfd2,buffer,1000);
|
||||
printf("Closing connection......\n");
|
||||
|
||||
// sleep(2);
|
||||
|
||||
close(sockfd2);
|
||||
free(init_connection);
|
||||
free(close_connection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void error(const char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
exit(0);
|
||||
}
|
||||
|
229
client-spx.c
Normal file
229
client-spx.c
Normal file
@ -0,0 +1,229 @@
|
||||
/* a client in the unix domain */
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "ipx.h"
|
||||
#include "ipxstack.h"
|
||||
|
||||
void *mmData = "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\
|
||||
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$";
|
||||
|
||||
ipx_response_t *conn;
|
||||
|
||||
void error(const char *);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sockfd, servlen,n;
|
||||
int sockfd2, servlen2;
|
||||
int sockfd3, servlen3;
|
||||
struct sockaddr_un serv_addr;
|
||||
struct sockaddr_un serv_addr2;
|
||||
struct sockaddr_un serv_addr3;
|
||||
spx_frame_t *ipx_packet;
|
||||
char buffer[2048];
|
||||
|
||||
// uint32_t conn_pid;
|
||||
|
||||
ipx_request_t *init_connection;
|
||||
ipx_request_t *close_connection;
|
||||
|
||||
init_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!init_connection)
|
||||
error("Out of memory: init_connection");
|
||||
close_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!close_connection)
|
||||
error("Out of memory: close_connection");
|
||||
|
||||
size_t data_size = 128;
|
||||
size_t packet_size = sizeof(spx_frame_t) + data_size;
|
||||
ipx_packet = malloc(packet_size);
|
||||
if(!ipx_packet) {
|
||||
|
||||
error("Out of memory");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
ipx_packet->checksum = 0xffff;
|
||||
ipx_packet->length = htons(packet_size);
|
||||
ipx_packet->hops = 0;
|
||||
ipx_packet->type = 0x05;
|
||||
ipx_packet->dest_net = 0;
|
||||
ipx_packet->dest_node[0] = htons(0x0800);
|
||||
ipx_packet->dest_node[1] = htons(0x2750);
|
||||
ipx_packet->dest_node[2] = htons(0xb177);
|
||||
ipx_packet->dest_socket = htons(0x869b);
|
||||
ipx_packet->src_net = 0;
|
||||
ipx_packet->src_node[0] = htons(0xb827);
|
||||
ipx_packet->src_node[1] = htons(0xeb02);
|
||||
ipx_packet->src_node[2] = htons(0xd221);
|
||||
ipx_packet->src_socket = htons(0x869b);
|
||||
|
||||
ipx_packet->conn_control = 0xc0;
|
||||
ipx_packet->datastream_type = 0;
|
||||
ipx_packet->src_conn_id = htons(0x1234);
|
||||
ipx_packet->dest_conn_id = htons(0xffff);
|
||||
ipx_packet->seq_no = 0;
|
||||
ipx_packet->ack_no = 0;
|
||||
ipx_packet->alloc_no = htons(3);
|
||||
|
||||
|
||||
|
||||
bzero((char *)&serv_addr,sizeof(serv_addr));
|
||||
serv_addr.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr.sun_path, argv[1]);
|
||||
servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
|
||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *) &serv_addr, servlen) < 0)
|
||||
error("Connecting");
|
||||
|
||||
// printf("Please enter your message: ");
|
||||
bzero(buffer,2048);
|
||||
init_connection->request_type = OPEN_SPX_SOCKET;
|
||||
init_connection->src_socket = 0x1234;
|
||||
init_connection->dest_net = 0x00000000;
|
||||
init_connection->dest_node[0] = htons(0x0800);
|
||||
init_connection->dest_node[1] = htons(0x2750);
|
||||
init_connection->dest_node[2] = htons(0xb177);
|
||||
init_connection->dest_socket = htons(0x7171);
|
||||
|
||||
// init_connection->pid = 1234;
|
||||
// printf("Init connection: request_type=%i; src_socket=%0x; pid=%i\n", init_connection->request_type, init_connection->src_socket, init_connection->pid);
|
||||
memcpy(buffer, init_connection, sizeof(ipx_request_t));
|
||||
/* memcpy(buffer, frame, 1000);*/
|
||||
//fgets(buffer,80,stdin);
|
||||
/*
|
||||
ethernet = (ethernet_frame_t *) &buffer;
|
||||
ipx = (ipx_frame_t *) ðernet->ipxpacket;
|
||||
ipx_data = (void *)ipx->data;
|
||||
printf("data: %s", ipx_data);
|
||||
*/
|
||||
// write(sockfd,buffer,1000);
|
||||
printf("Setting up the Connection\n");
|
||||
write(sockfd, init_connection, sizeof(ipx_request_t));
|
||||
printf("Waiting for ansver\n");
|
||||
n=read(sockfd,buffer,280);
|
||||
printf("The return message was\n");
|
||||
|
||||
conn = (ipx_response_t *)buffer;
|
||||
if(conn->error != NO_ERROR) {
|
||||
printf("Error: socket is already opened\n");
|
||||
exit(2);
|
||||
}
|
||||
// printf("My connection: socket=%0x; socket name=%s; pid=%i\n", conn->src_socket, conn->socket_name, conn->pid);
|
||||
// conn_pid = conn->pid;
|
||||
write(1,buffer,n);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sleep(1);
|
||||
|
||||
spx_frame_t *spx_packet;
|
||||
int loop = 1;
|
||||
|
||||
printf("Waiting for data\n");
|
||||
bzero(buffer, 2048);
|
||||
bzero((char *)&serv_addr3, sizeof(serv_addr3));
|
||||
serv_addr3.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr3.sun_path, "./socket.1234");
|
||||
servlen3 = strlen(serv_addr3.sun_path) + sizeof(serv_addr3.sun_family);
|
||||
if((sockfd3 = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
error("Creating data socket");
|
||||
|
||||
if(connect(sockfd3, (struct sockaddr *) &serv_addr3, servlen3) < 0)
|
||||
error("Connecting data socket");
|
||||
|
||||
int seq_no;
|
||||
|
||||
seq_no = 0;
|
||||
|
||||
while(loop) {
|
||||
printf("Read %i bytes.\n", read(sockfd3, buffer, 2048));
|
||||
spx_packet = (spx_frame_t *)&buffer;
|
||||
printf((const char *)&spx_packet->data);
|
||||
ipx_packet->checksum = 0xffff;
|
||||
ipx_packet->length = htons(packet_size);
|
||||
ipx_packet->hops = 0;
|
||||
ipx_packet->type = 5;
|
||||
ipx_packet->dest_net = spx_packet->src_net;
|
||||
ipx_packet->dest_node[0] = spx_packet->src_node[0];
|
||||
ipx_packet->dest_node[1] = spx_packet->src_node[1];
|
||||
ipx_packet->dest_node[2] = spx_packet->src_node[2];
|
||||
ipx_packet->src_net = spx_packet->dest_net;
|
||||
ipx_packet->src_node[0] = spx_packet->dest_node[0];
|
||||
ipx_packet->src_node[1] = spx_packet->dest_node[1];
|
||||
ipx_packet->src_node[2] = spx_packet->dest_node[2];
|
||||
ipx_packet->conn_control = 0b01010000;
|
||||
ipx_packet->datastream_type = 0;
|
||||
ipx_packet->src_conn_id = htons(conn->pid);
|
||||
ipx_packet->dest_conn_id = spx_packet->src_conn_id;
|
||||
ipx_packet->seq_no = htons(seq_no);
|
||||
ipx_packet->ack_no = htons(ntohs(spx_packet->seq_no) + 1);
|
||||
ipx_packet->alloc_no = htons(3);
|
||||
memcpy(ipx_packet->data, mmData, 128);
|
||||
bzero(buffer, 2048);
|
||||
memcpy(buffer, ipx_packet, packet_size);
|
||||
write(sockfd3, buffer, packet_size);
|
||||
printf("Packet size: %ib\n", packet_size);
|
||||
bzero(buffer, 2048);
|
||||
loop = 0;
|
||||
}
|
||||
sleep(5);
|
||||
close(sockfd3);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sleep(2);
|
||||
printf("Closing connection.\n");
|
||||
bzero(buffer, 1002);
|
||||
close_connection->request_type = CLOSE_SOCKET;
|
||||
close_connection->src_socket = 0x1234;
|
||||
// close_connection->pid = conn_pid;
|
||||
// printf("Closing connection: request_type=%i; src_socket=%0x; pid=%i\n", close_connection->request_type, close_connection->src_socket, close_connection->pid);
|
||||
|
||||
bzero((char *)&serv_addr2,sizeof(serv_addr2));
|
||||
serv_addr2.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr2.sun_path, argv[1]);
|
||||
servlen2 = strlen(serv_addr2.sun_path) + sizeof(serv_addr2.sun_family);
|
||||
if ((sockfd2 = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd2, (struct sockaddr *) &serv_addr2, servlen2) < 0)
|
||||
error("Connecting");
|
||||
|
||||
bzero(buffer,1002);
|
||||
memcpy(buffer, close_connection, sizeof(ipx_request_t));
|
||||
printf("Closing connection.....\n");
|
||||
|
||||
|
||||
write(sockfd2,buffer,1000);
|
||||
printf("Closing connection......\n");
|
||||
|
||||
// sleep(2);
|
||||
|
||||
close(sockfd2);
|
||||
free(init_connection);
|
||||
free(close_connection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void error(const char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
exit(0);
|
||||
}
|
||||
|
173
client-stream.c
Normal file
173
client-stream.c
Normal file
@ -0,0 +1,173 @@
|
||||
/* a client in the unix domain */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdio.h>
|
||||
#include "ipx.h"
|
||||
#include "ipxstack.h"
|
||||
|
||||
void *mmData = "AK> hello \0xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxM";
|
||||
ipx_response_t *conn;
|
||||
|
||||
void error(const char *);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sockfd, servlen,n;
|
||||
int sockfd2, servlen2;
|
||||
int sockfd3, servlen3;
|
||||
struct sockaddr_un serv_addr;
|
||||
struct sockaddr_un serv_addr2;
|
||||
struct sockaddr_un serv_addr3;
|
||||
char buffer[1024];
|
||||
// uint32_t conn_pid;
|
||||
|
||||
ipx_request_t *init_connection;
|
||||
ipx_request_t *close_connection;
|
||||
|
||||
init_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!init_connection)
|
||||
error("Out of memory: init_connection");
|
||||
close_connection = malloc(sizeof(ipx_request_t));
|
||||
if(!close_connection)
|
||||
error("Out of memory: close_connection");
|
||||
bzero((char *)&serv_addr,sizeof(serv_addr));
|
||||
serv_addr.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr.sun_path, argv[1]);
|
||||
servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family);
|
||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd, (struct sockaddr *) &serv_addr, servlen) < 0)
|
||||
error("Connecting");
|
||||
|
||||
// printf("Please enter your message: ");
|
||||
bzero(buffer,1002);
|
||||
init_connection->request_type = OPEN_STREAM;
|
||||
init_connection->src_socket = 0x1453;
|
||||
init_connection->dest_net = 0x00000000;
|
||||
init_connection->dest_node[0] = 0xffff;
|
||||
init_connection->dest_node[1] = 0xffff;
|
||||
init_connection->dest_node[2] = 0xffff;
|
||||
init_connection->dest_socket = 0x869b;
|
||||
// init_connection->pid = 1234;
|
||||
// printf("Init connection: request_type=%i; src_socket=%0x; pid=%i\n", init_connection->request_type, init_connection->src_socket, init_connection->pid);
|
||||
memcpy(buffer, init_connection, sizeof(ipx_request_t));
|
||||
/* memcpy(buffer, frame, 1000);*/
|
||||
//fgets(buffer,80,stdin);
|
||||
/*
|
||||
ethernet = (ethernet_frame_t *) &buffer;
|
||||
ipx = (ipx_frame_t *) ðernet->ipxpacket;
|
||||
ipx_data = (void *)ipx->data;
|
||||
printf("data: %s", ipx_data);
|
||||
*/
|
||||
// write(sockfd,buffer,1000);
|
||||
printf("Setting up the Connection\n");
|
||||
write(sockfd, init_connection, sizeof(ipx_request_t));
|
||||
printf("Waiting for ansver\n");
|
||||
n=read(sockfd,buffer,280);
|
||||
printf("The return message was\n");
|
||||
|
||||
conn = (ipx_response_t *)buffer;
|
||||
if(conn->error != NO_ERROR) {
|
||||
printf("Error: socket is already opened\n");
|
||||
exit(2);
|
||||
}
|
||||
// printf("My connection: socket=%0x; socket name=%s; pid=%i\n", conn->src_socket, conn->socket_name, conn->pid);
|
||||
// conn_pid = conn->pid;
|
||||
write(1,buffer,n);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sleep(2);
|
||||
|
||||
char input_string[200];
|
||||
int loop = 1;
|
||||
ipx_frame_t *ipx_packet;
|
||||
|
||||
printf("Sending data on data sockeet\n");
|
||||
bzero(buffer, 1002);
|
||||
bzero((char *)&serv_addr3, sizeof(serv_addr3));
|
||||
serv_addr3.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr3.sun_path, "./socket.1453");
|
||||
servlen3 = strlen(serv_addr3.sun_path) + sizeof(serv_addr3.sun_family);
|
||||
if((sockfd3 = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
error("Creating data socket");
|
||||
|
||||
if(connect(sockfd3, (struct sockaddr *) &serv_addr3, servlen3) < 0)
|
||||
error("Connecting data socket");
|
||||
|
||||
while(loop) {
|
||||
bzero(buffer, 1002);
|
||||
gets(input_string);
|
||||
if(strncmp(input_string, "exit", 4) == 0)
|
||||
{
|
||||
loop = 0;
|
||||
}
|
||||
strncpy(buffer+6, input_string, sizeof(input_string));
|
||||
write(sockfd3, buffer, 1000);
|
||||
/* bzero(buffer, 1002);
|
||||
read(sockfd3, buffer, 1000);
|
||||
ipx_packet = (ipx_frame_t *)buffer;
|
||||
printf((char *)ipx_packet->data + 6);*/
|
||||
}
|
||||
close(sockfd3);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sleep(2);
|
||||
printf("Closing connection.\n");
|
||||
bzero(buffer, 1002);
|
||||
close_connection->request_type = CLOSE_SOCKET;
|
||||
close_connection->src_socket = 0x1453;
|
||||
// close_connection->pid = conn_pid;
|
||||
// printf("Closing connection: request_type=%i; src_socket=%0x; pid=%i\n", close_connection->request_type, close_connection->src_socket, close_connection->pid);
|
||||
|
||||
bzero((char *)&serv_addr2,sizeof(serv_addr2));
|
||||
serv_addr2.sun_family = AF_UNIX;
|
||||
strcpy(serv_addr2.sun_path, argv[1]);
|
||||
servlen2 = strlen(serv_addr2.sun_path) + sizeof(serv_addr2.sun_family);
|
||||
if ((sockfd2 = socket(AF_UNIX, SOCK_STREAM,0)) < 0)
|
||||
error("Creating socket");
|
||||
|
||||
if (connect(sockfd2, (struct sockaddr *) &serv_addr2, servlen2) < 0)
|
||||
error("Connecting");
|
||||
|
||||
bzero(buffer,1002);
|
||||
memcpy(buffer, close_connection, sizeof(ipx_request_t));
|
||||
printf("Closing connection.....\n");
|
||||
|
||||
|
||||
write(sockfd2,buffer,1000);
|
||||
printf("Closing connection......\n");
|
||||
|
||||
// sleep(2);
|
||||
|
||||
close(sockfd2);
|
||||
free(init_connection);
|
||||
free(close_connection);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void error(const char *msg)
|
||||
{
|
||||
perror(msg);
|
||||
exit(0);
|
||||
}
|
||||
|
34
color.h
Normal file
34
color.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
//foreground
|
||||
#define FBLACK "\033[30;"
|
||||
#define FRED "\033[31;"
|
||||
#define FGREEN "\033[32;"
|
||||
#define FYELLOW "\033[33;"
|
||||
#define FBLUE "\033[34;"
|
||||
#define FPURPLE "\033[35;"
|
||||
#define D_FGREEN "\033[6;"
|
||||
#define FWHITE "\033[7;"
|
||||
#define FCYAN "\x1b[36m"
|
||||
|
||||
//background
|
||||
#define BBLACK "40m"
|
||||
#define BRED "41m"
|
||||
#define BGREEN "42m"
|
||||
#define BYELLOW "43m"
|
||||
#define BBLUE "44m"
|
||||
#define BPURPLE "45m"
|
||||
#define D_BGREEN "46m"
|
||||
#define BWHITE "47m"
|
||||
|
||||
//font control
|
||||
#define BOLD "\033[1m"
|
||||
#define BOLDOFF "\033[0m"
|
||||
#define BLINK "\033[5m"
|
||||
#define REVERSE "7;"
|
||||
|
||||
//end color
|
||||
#define NONE "\033[0m"
|
||||
|
||||
#endif /* COLOR_H */
|
105
ipx.h
Normal file
105
ipx.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef IPX_H
|
||||
#define IPX_H
|
||||
|
||||
typedef struct spx_frame spx_frame_t;
|
||||
struct spx_frame {
|
||||
uint16_t checksum;
|
||||
uint16_t length;
|
||||
uint8_t hops;
|
||||
uint8_t type;
|
||||
|
||||
uint32_t dest_net;
|
||||
uint16_t dest_node[3];
|
||||
uint16_t dest_socket;
|
||||
|
||||
uint32_t src_net;
|
||||
uint16_t src_node[3];
|
||||
uint16_t src_socket;
|
||||
|
||||
uint8_t conn_control;
|
||||
uint8_t datastream_type;
|
||||
uint16_t src_conn_id;
|
||||
uint16_t dest_conn_id;
|
||||
uint16_t seq_no;
|
||||
uint16_t ack_no;
|
||||
uint16_t alloc_no;
|
||||
|
||||
unsigned char data[0];
|
||||
}__attribute__((__packed__, aligned(1)));
|
||||
|
||||
typedef struct spx_header spx_header_t;
|
||||
struct spx_header {
|
||||
uint8_t conn_control;
|
||||
uint8_t datastream_type;
|
||||
uint16_t src_conn_id;
|
||||
uint16_t dest_conn_id;
|
||||
uint16_t seq_no;
|
||||
uint16_t ack_no;
|
||||
uint16_t alloc_no;
|
||||
}__attribute__((__packed__, aligned(1)));
|
||||
|
||||
typedef struct ipx_frame ipx_frame_t;
|
||||
struct ipx_frame {
|
||||
uint16_t checksum;
|
||||
uint16_t length;
|
||||
uint8_t hops;
|
||||
uint8_t type;
|
||||
|
||||
uint32_t dest_net;
|
||||
uint16_t dest_node[3];
|
||||
uint16_t dest_socket;
|
||||
|
||||
uint32_t src_net;
|
||||
uint16_t src_node[3];
|
||||
uint16_t src_socket;
|
||||
|
||||
unsigned char data[0];
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
typedef struct ethernet_frame ethernet_frame_t;
|
||||
struct ethernet_frame
|
||||
{
|
||||
uint16_t dest_mac[3];
|
||||
uint16_t src_mac[3];
|
||||
uint16_t ethertype;
|
||||
|
||||
ipx_frame_t ipxpacket;
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
typedef struct ethernet_spx_frame ethernet_spx_frame_t;
|
||||
struct ethernet_spx_frame
|
||||
{
|
||||
uint16_t dest_mac[3];
|
||||
uint16_t src_mac[3];
|
||||
uint16_t ethertype;
|
||||
|
||||
spx_frame_t spxpacket;
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
|
||||
typedef struct IEEE8023_frame IEEE8023_frame_t;
|
||||
struct IEEE8023_frame
|
||||
{
|
||||
uint16_t dest_mac[3];
|
||||
uint16_t src_mac[3];
|
||||
uint16_t length;
|
||||
uint8_t DSAP;
|
||||
uint8_t SSAP;
|
||||
uint8_t ctrl;
|
||||
|
||||
ipx_frame_t ipxpacket;
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
/* Packet types */
|
||||
|
||||
#define PACKET_UNKNOWN 0
|
||||
#define PACKET_RIP 1
|
||||
#define PACKET_ECHO 2
|
||||
#define PACKET_ERROR 3
|
||||
#define PACKET_IPX 4 // also SAP Packet
|
||||
#define PACKET_SPX 5
|
||||
#define PACKET_NCP 17
|
||||
#define PACKET_NETBIOS 20
|
||||
|
||||
#endif /* IPX_H */
|
||||
|
1031
ipxstack.c
Normal file
1031
ipxstack.c
Normal file
File diff suppressed because it is too large
Load Diff
37
ipxstack.h
Normal file
37
ipxstack.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef IPXSTACK_H
|
||||
#define IPXSTACK_H
|
||||
|
||||
#define OPEN_SOCKET 1
|
||||
#define OPEN_STREAM 2
|
||||
#define OPEN_SPX_SOCKET 3
|
||||
#define CLOSE_SOCKET 4
|
||||
|
||||
#define NO_ERROR 0
|
||||
#define ERROR_SOCKET_OPENED 1
|
||||
/*
|
||||
* Client sends struct to ipxstack on its socket. Ipxstack opens a new socket for
|
||||
* clients communication with network.
|
||||
*/
|
||||
typedef struct ipx_request ipx_request_t;
|
||||
struct ipx_request {
|
||||
uint16_t request_type;
|
||||
uint16_t src_socket;
|
||||
uint32_t dest_net;
|
||||
uint16_t dest_node[3];
|
||||
uint16_t dest_socket;
|
||||
uint32_t pid;
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
/*
|
||||
* Ipxstack responds to the clients's request to open new connection. It sends
|
||||
* struct containing info about connection socket.
|
||||
*/
|
||||
typedef struct ipx_response ipx_response_t;
|
||||
struct ipx_response {
|
||||
uint16_t src_socket;
|
||||
char socket_name[100];
|
||||
uint32_t pid;
|
||||
uint16_t error;
|
||||
} __attribute__((__packed__, aligned(1)));
|
||||
|
||||
#endif /* IPXSTACK_H */
|
17
ipxstack.ini
Normal file
17
ipxstack.ini
Normal file
@ -0,0 +1,17 @@
|
||||
#
|
||||
# Config file for IPXstack
|
||||
#
|
||||
|
||||
[PROGRAM]
|
||||
socket=socket
|
||||
use_pcap_filter=false
|
||||
pcap_read_timeout=500
|
||||
poll_timeout=100
|
||||
|
||||
[ADAPTER]
|
||||
# device=eth0
|
||||
device=bge0
|
||||
network=00000000
|
||||
# address=b827:eb02:d221
|
||||
address=984b:e108:8847
|
||||
# address=c4b3:018e:1d80
|
52
makefile
Normal file
52
makefile
Normal file
@ -0,0 +1,52 @@
|
||||
# Makefile
|
||||
#
|
||||
#
|
||||
CC = gcc
|
||||
DEPS = ipx.h ipxstack.h
|
||||
|
||||
# Flags for C compiler
|
||||
# -g adds debugging information to the executable file
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
CFLAGS = -ggdb -Wall
|
||||
LDFLAGS= -lxnet
|
||||
|
||||
all: ipxstack client-socket client-stream client-spx
|
||||
|
||||
ipxstack: ipxstack.o configini.o
|
||||
$(CC) ipxstack.o configini.o $(LDFLAGS) -o ipxstack -lpcap
|
||||
|
||||
configini.o: ../libconfigini/src/configini.c ../libconfigini/src/configini.h ../libconfigini/src/queue.h
|
||||
$(CC) -c ../libconfigini/src/configini.c $(LDFLAGS) -o configini.o
|
||||
|
||||
ipxstack.o: ipxstack.c $(DEPS)
|
||||
$(CC) -c ipxstack.c $(CFLAGS) -o ipxstack.o
|
||||
|
||||
client-spx: client-spx.o
|
||||
$(CC) client-spx.o $(LDFLAGS) -o client-spx
|
||||
|
||||
client-spx.o: client-spx.c
|
||||
$(CC) -c client-spx.c $(CFLAGS) -o client-spx.o
|
||||
|
||||
client-socket: client-socket.o
|
||||
$(CC) client-socket.o $(LDFLAGS) -o client-socket
|
||||
|
||||
client-stream: client-stream.o
|
||||
$(CC) client-stream.o $(LDFLAGS) -o client-stream
|
||||
|
||||
client-socket.o: client-socket.c $(DEPS)
|
||||
$(CC) -c client-socket.c $(CFLAGS) -o client-socket.o
|
||||
|
||||
client-stream.o: client-stream.c $(DEPS)
|
||||
$(CC) -c client-stream.c $(CFLAGS) -o client-stream.o
|
||||
|
||||
clean:
|
||||
$(RM) ipxstack
|
||||
$(RM) client-stream
|
||||
$(RM) client-socket
|
||||
$(RM) client-spx
|
||||
$(RM) *.o
|
||||
$(RM) socket*
|
||||
pkill ipxstack
|
||||
$(RM) core
|
||||
|
||||
|
Reference in New Issue
Block a user