Permalink
Browse files

increment, address and port fixes

  • Loading branch information...
1 parent f31f91c commit e068493ded373ce1e944a819010886de364b25f7 @isfos isfos committed Apr 8, 2011
Showing with 19 additions and 13 deletions.
  1. +10 −0 SRC/basic_reciever_no_asio.c
  2. +2 −0 SRC/basic_sender_no_asio.c
  3. +3 −12 SRC/classdefs.h
  4. +4 −1 SRC/functiondefs.h
@@ -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{
@@ -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,
@@ -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,
View
@@ -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);
@@ -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;
View
@@ -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);
@@ -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";

0 comments on commit e068493

Please sign in to comment.