Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
increment, address and port fixes
  • Loading branch information
isfos committed Apr 8, 2011
1 parent f31f91c commit e068493
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
10 changes: 10 additions & 0 deletions SRC/basic_reciever_no_asio.c
Expand Up @@ -67,6 +67,16 @@ int main(int argc, char* argv[]){

//get the next address from the table
address next = table.getToAddress(p.dest);

//make the packet
packet p = packet( //construct packet
ACK,
p.dest,
p.source,
p.size,
p.data,
0);

//send an ACK
sendPacket(port, &p, &remote_address, next);
}else{
Expand Down
2 changes: 2 additions & 0 deletions SRC/basic_sender_no_asio.c
Expand Up @@ -62,6 +62,7 @@ int main(int argc, char* argv[]){
//make the packet
packet p = packet( //construct packet
DAT,
local_raddress,
dest_raddress,
strlen(buffer),
buffer,
Expand Down Expand Up @@ -128,6 +129,7 @@ int main(int argc, char* argv[]){
//make the packet
packet p = packet( //construct packet
DAT,
local_raddress,
dest_raddress,
request_length,
buffer,
Expand Down
15 changes: 3 additions & 12 deletions SRC/classdefs.h
Expand Up @@ -126,14 +126,16 @@ typedef enum {ACK, DAT} packettype;
class packet {
public:
packettype type;
address source;
address dest;
int size;
char data[256];
int current_num_ints;

packet(){dest = address();};
packet(packettype pt, address d, int s, char indat[256], int n){
packet(packettype pt, address src, address d, int s, char indat[256], int n){
type = pt;
source = src;
dest = d;
size = s;
strncpy(data, indat, 256);
Expand Down Expand Up @@ -171,14 +173,3 @@ class packet {
}

};

typedef struct{
packettype type; //type of packet ACK or DATA
char dest[16]; //destination
int size; //size of data field
char data[256]; //maximum size of data payload
int current_num_ints; //number of intermediate nodes
//traversed by packet
char intermediate_nodes[8][16]; //array to hold ip
// addresses of intermediate nodes
} PACKET;
5 changes: 4 additions & 1 deletion SRC/functiondefs.h
Expand Up @@ -56,6 +56,10 @@ void forwardTo(RouteTable t,packet p, int port){
//int n = sendto(sout,(void*)&p,sizeof(packet),0,
// (struct sockaddr *)&remote_address, sizeof(struct sockaddr_in));
cout << "packet:"<<p.data <<", "<<p.dest.addr<<"\n";

//IMPORTANT: increment hop count before forwarding
p.current_num_ints++;

packet *j = &p;
int n = sendto(sout,(void*)j,sizeof(packet),0,
(struct sockaddr *)&remote_address, remote_length);
Expand Down Expand Up @@ -124,7 +128,6 @@ int sendPacket(int port, packet* p, sockaddr_in* dest_sockaddress, address next)
dest_sockaddress->sin_family = AF_INET;
dest_sockaddress->sin_port = htons(port);
//remote_address.sin_addr.s_addr = inet_addr(string_route_destination);
cout << next.addr << "\n";
inet_aton(next.addr, &((*dest_sockaddress).sin_addr));

cout << "packet:"<< p->data << ", " << p->dest.addr << "\n";
Expand Down

0 comments on commit e068493

Please sign in to comment.