Commit 945c0520 authored by ikumar's avatar ikumar

Kristine's algorithm with a little modification: doesnt work!!

parent 4e3e74bc
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: cli.c,v 1.4 2001-06-18 01:41:19 ikumar Exp $ * $Id: cli.c,v 1.5 2001-07-19 19:55:57 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -104,6 +104,7 @@ make_inquiry(topd_inqid_t *tip, u_int16_t ttl, u_int16_t factor) ...@@ -104,6 +104,7 @@ make_inquiry(topd_inqid_t *tip, u_int16_t ttl, u_int16_t factor)
/* ...and now our nodeID */ /* ...and now our nodeID */
nid = find_nodeID(); nid = find_nodeID();
memcpy((void *)tip->tdi_nodeID, nid, ETHADDRSIZ); memcpy((void *)tip->tdi_nodeID, nid, ETHADDRSIZ);
bzero(tip->tdi_p_nodeIF,ETHADDRSIZ);
} }
void void
...@@ -120,6 +121,7 @@ cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen, ...@@ -120,6 +121,7 @@ cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen,
sendto(sockfd, &ti, TOPD_INQ_SIZ, 0, pservaddr, servlen); sendto(sockfd, &ti, TOPD_INQ_SIZ, 0, pservaddr, servlen);
//print_tdinq((char *)&ti); //print_tdinq((char *)&ti);
n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL); n = recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
fflush(stdin);
//printf("Receiving in client:==>\n"); //printf("Receiving in client:==>\n");
//print_tdreply(recvline, n); //print_tdreply(recvline, n);
} }
......
/*$Id: discvr.h,v 1.5 2001-06-18 01:41:19 ikumar Exp $*/ /*$Id: discvr.h,v 1.6 2001-07-19 19:55:57 ikumar Exp $*/
#ifndef _TOPD_DISCVR_H_ #ifndef _TOPD_DISCVR_H_
#define _TOPD_DISCVR_H_ #define _TOPD_DISCVR_H_
...@@ -99,5 +99,8 @@ get_ifi_struct(int sock, struct ifi_info * ifihead); ...@@ -99,5 +99,8 @@ get_ifi_struct(int sock, struct ifi_info * ifihead);
void void
addMyID(char* mesg, int size); addMyID(char* mesg, int size);
void
get_recvIFADDR(char *name,struct ifi_info * ifihead);
#endif /* _TOPD_DISCVR_H_ */ #endif /* _TOPD_DISCVR_H_ */
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: forw_requests.c,v 1.7 2001-06-18 01:41:19 ikumar Exp $ * $Id: forw_requests.c,v 1.8 2001-07-19 19:55:57 ikumar Exp $
*/ */
#include <math.h> #include <math.h>
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
*/ */
char recvbuf[BUFSIZ]; char recvbuf[BUFSIZ];
extern u_char myNodeID[ETHADDRSIZ]; extern u_char myNodeID[ETHADDRSIZ];
extern u_char parent_nodeIF[ETHADDRSIZ];
static double start = 0.0; static double start = 0.0;
double double
...@@ -59,6 +61,7 @@ get_ifi_struct(int sock, struct ifi_info * ifihead) ...@@ -59,6 +61,7 @@ get_ifi_struct(int sock, struct ifi_info * ifihead)
return NULL; return NULL;
} }
/*
void void
addMyID(char* mesg, int size) addMyID(char* mesg, int size)
{ {
...@@ -67,7 +70,7 @@ addMyID(char* mesg, int size) ...@@ -67,7 +70,7 @@ addMyID(char* mesg, int size)
memcpy(p->tdnbor_dnode,myNodeID,ETHADDRSIZ); memcpy(p->tdnbor_dnode,myNodeID,ETHADDRSIZ);
} }
*/
struct ifi_info * struct ifi_info *
...@@ -77,7 +80,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -77,7 +80,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
int s, n; int s, n;
int more_time = 1; int more_time = 1;
fd_set rset,temp_rset; fd_set rset,temp_rset;
const int on = 1; const int on = 1;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct topd_inqid *tdi; struct topd_inqid *tdi;
struct topd_nborlist *save; struct topd_nborlist *save;
...@@ -86,7 +89,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -86,7 +89,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
struct timeval tv; struct timeval tv;
int selectReturn; int selectReturn;
struct sockaddr name; struct sockaddr name;
int namelen=sizeof(name); int namelen=sizeof(name);
int *sock_list=NULL, *temp_sock_list=NULL; int *sock_list=NULL, *temp_sock_list=NULL;
int sock_num = 0,i=0; int sock_num = 0,i=0;
struct topd_inqid *temp_mesg; struct topd_inqid *temp_mesg;
...@@ -134,12 +137,15 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -134,12 +137,15 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// Adding check for control net... -ik // Adding check for control net... -ik
if(strcmp(ifi->ifi_name,"fxp4")==0) continue; if(strcmp(ifi->ifi_name,"fxp4")==0) continue;
//memcpy(&(temp_mesg->tdi_p_nodeIF),&(ifi->ifi_haddr),IFHADDRSIZ);
memcpy(&(temp_mesg->tdi_p_nodeIF),&myNodeID,IFHADDRSIZ);
printf("Forwarding the query to interface: \"%s\"\n",ifi->ifi_name); printf("Forwarding the query to interface: \"%s\"\n",ifi->ifi_name);
temp_sock_list = sock_list; temp_sock_list = sock_list;
sock_list = (int *)malloc(sizeof(int)*(sock_num+1)); sock_list = (int *)malloc(sizeof(int)*(sock_num+1));
for(i=0;i<sock_num;i++) for(i=0;i<sock_num;i++)
{ {
printf("copying: %d\n",temp_sock_list[i]); //printf("copying: %d\n",temp_sock_list[i]);
sock_list[i] = temp_sock_list[i]; sock_list[i] = temp_sock_list[i];
} }
free(temp_sock_list); free(temp_sock_list);
...@@ -191,16 +197,17 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -191,16 +197,17 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
print_tdinq(mesg); print_tdinq(mesg);
n = sendto(s, mesg, mesglen, 0, n = sendto(s, mesg, mesglen, 0,
(struct sockaddr *)&sin, sizeof(struct sockaddr_in)); (struct sockaddr *)&sin, sizeof(struct sockaddr_in));
printf("$$$after forwarding the enquiry: "); //printf("$$$after forwarding the enquiry: ");
print_tdinq(mesg); //print_tdinq(mesg);
/*
if(getsockname(s, (struct sockaddr *)&name, &namelen)<0) if(getsockname(s, (struct sockaddr *)&name, &namelen)<0)
{ {
perror("getsockname\n"); perror("getsockname\n");
} }
*/
printf("The address from where i am sending: %s\n",sock_ntop(&name,name.sa_len)); //printf("The address from where i am sending: %s\n",sock_ntop(&name,name.sa_len));
if (n != mesglen) { if (n != mesglen) {
perror("Didn't send all of packet"); perror("Didn't send all of packet");
exit(1); exit(1);
...@@ -220,7 +227,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -220,7 +227,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
*/ */
n = 0; n = 0;
start = tod(); start = tod();
//while ( more_time ) { //while ( more_time ) {
while (1) { while (1) {
double begin, end, elapsed; double begin, end, elapsed;
...@@ -235,9 +242,9 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -235,9 +242,9 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
*/ */
begin = tod(); begin = tod();
temp_rset = rset; temp_rset = rset;
printf("entering select **** sec:%d and usec:%d\n",tv.tv_sec,tv.tv_usec); //printf("entering select **** sec:%d and usec:%d\n",tv.tv_sec,tv.tv_usec);
selectReturn = select(FD_SETSIZE, &temp_rset, NULL, NULL, &tv); selectReturn = select(FD_SETSIZE, &temp_rset, NULL, NULL, &tv);
printf("select return: %d\n",selectReturn); //printf("select return: %d\n",selectReturn);
if( selectReturn < 0 ) { if( selectReturn < 0 ) {
printf("Error in Select call\n"); printf("Error in Select call\n");
perror("select"); perror("select");
...@@ -260,7 +267,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -260,7 +267,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
deadline -= elapsed; deadline -= elapsed;
tv.tv_sec = floor(deadline); tv.tv_sec = floor(deadline);
tv.tv_usec = (deadline - tv.tv_sec) * 1e+6; tv.tv_usec = (deadline - tv.tv_sec) * 1e+6;
printf("sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec); //printf("sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec);
...@@ -276,7 +283,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -276,7 +283,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// receive one of my neighbors' list of neighbors through // receive one of my neighbors' list of neighbors through
// "ifi" interface to which I just forwarded the request -ik // "ifi" interface to which I just forwarded the request -ik
printf("Checking socket: %d\n",sock_list[i]); //printf("Checking socket: %d\n",sock_list[i]);
if (!FD_ISSET(sock_list[i], &temp_rset)) continue; if (!FD_ISSET(sock_list[i], &temp_rset)) continue;
...@@ -293,15 +300,14 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -293,15 +300,14 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
if((ifi=get_ifi_struct(sock_list[i],ifihead)) == NULL) if((ifi=get_ifi_struct(sock_list[i],ifihead)) == NULL)
{ {
printf("Socket \"%d\" is not in any ifi struct\n",sock_list[i]); fprintf(stderr,"Socket \"%d\" is not in any ifi struct\n",sock_list[i]);
} }
printf("The interface on which i received is \"%s\"",ifi->ifi_name); //printf("The interface on which i received is \"%s\"\n",ifi->ifi_name);
// save the existing list of neighbors which I just received through // save the existing list of neighbors which I just received through
// the "ifi" interface... -ik // the "ifi" interface... -ik
save = ifi->ifi_nbors; save = ifi->ifi_nbors;
printf("The value of save: \"%d\"\n",save);
// create a new node for the neighbor link list pointed by "ifi_nbors" // create a new node for the neighbor link list pointed by "ifi_nbors"
// -ik // -ik
...@@ -311,7 +317,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -311,7 +317,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
exit(1); exit(1);
} }
/* skip inquiry ID */ /* skip inquiry ID */
ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n); ifi->ifi_nbors->tdnbl_nbors = (u_char *)malloc(n-sizeof(topd_inqid_t));
if ( ifi->ifi_nbors->tdnbl_nbors == NULL ) { if ( ifi->ifi_nbors->tdnbl_nbors == NULL ) {
perror("Not enough memory for neighbor list."); perror("Not enough memory for neighbor list.");
exit(1); exit(1);
...@@ -322,11 +328,12 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -322,11 +328,12 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
// to every message there is a "inquiry ID" attached in the beginning... // to every message there is a "inquiry ID" attached in the beginning...
// -ik // -ik
//print_tdpairs(recvbuf + sizeof(topd_inqid_t),n-sizeof(topd_inqid_t)); //print_tdpairs(recvbuf + sizeof(topd_inqid_t),n-sizeof(topd_inqid_t));
memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf + sizeof(topd_inqid_t), n); memcpy((void *)ifi->ifi_nbors->tdnbl_nbors, recvbuf +
sizeof(topd_inqid_t), (n-sizeof(topd_inqid_t)));
// The "tdnbl_n" contains the number of neighbors that the node, along this // The "tdnbl_n" contains the number of neighbors that the node, along this
// interface, has ... -ik // interface, has ... -ik
ifi->ifi_nbors->tdnbl_n = n / sizeof(struct topd_nbor); ifi->ifi_nbors->tdnbl_n = (n-sizeof(topd_inqid_t)) / sizeof(struct topd_nbor);
ifi->ifi_nbors->tdnbl_next = save; ifi->ifi_nbors->tdnbl_next = save;
//print_tdpairs(ifi->ifi_nbors->tdnbl_nbors,n-sizeof(topd_inqid_t)); //print_tdpairs(ifi->ifi_nbors->tdnbl_nbors,n-sizeof(topd_inqid_t));
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: packet.h,v 1.3 2000-07-18 19:19:28 kwright Exp $ * $Id: packet.h,v 1.6 2001-08-02 21:21:05 ikumar Exp $
*/ */
#ifndef _TOPD_PACKET_H_ #ifndef _TOPD_PACKET_H_
...@@ -42,10 +42,11 @@ ...@@ -42,10 +42,11 @@
* are struct timevals returned by gettimeofday(). * are struct timevals returned by gettimeofday().
*/ */
typedef struct topd_inqid { typedef struct topd_inqid {
struct timeval tdi_tv; struct timeval tdi_tv;
u_int16_t tdi_ttl; u_int16_t tdi_ttl;
u_int16_t tdi_factor; u_int16_t tdi_factor;
u_char tdi_nodeID[ETHADDRSIZ]; u_char tdi_nodeID[ETHADDRSIZ];
u_char tdi_p_nodeIF[ETHADDRSIZ];
} topd_inqid_t; } topd_inqid_t;
#define TOPD_INQ_SIZ ALIGN(sizeof(struct topd_inqid)) #define TOPD_INQ_SIZ ALIGN(sizeof(struct topd_inqid))
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: reply.c,v 1.6 2001-06-14 23:19:23 ikumar Exp $ * $Id: reply.c,v 1.7 2001-07-19 19:55:57 ikumar Exp $
*/ */
...@@ -27,8 +27,9 @@ ...@@ -27,8 +27,9 @@
#include "util.h" #include "util.h"
extern u_char myNodeID[ETHADDRSIZ]; extern u_char myNodeID[ETHADDRSIZ];
extern u_char parent_nodeIF[ETHADDRSIZ];
extern topd_inqid_t inqid_current; extern topd_inqid_t inqid_current;
extern u_char receivingIF[ETHADDRSIZ];
/* /*
* Concatenate all the individual interfaces' messages into * Concatenate all the individual interfaces' messages into
* one long neighbor list. * one long neighbor list.
...@@ -68,11 +69,16 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors ...@@ -68,11 +69,16 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors
fprintf(stderr, "ran out of room and you didn't do anything reasonable.\n"); fprintf(stderr, "ran out of room and you didn't do anything reasonable.\n");
return 0; return 0;
} }
//printf("My parent's address is:");
//print_nodeID(parent_nodeIF);
memcpy(nid, myNodeID, ETHADDRSIZ); memcpy(nid, myNodeID, ETHADDRSIZ);
nid += ETHADDRSIZ; nid += ETHADDRSIZ;
memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ); memcpy(nid, ifi->ifi_haddr, ETHADDRSIZ);
nid += ETHADDRSIZ; nid += ETHADDRSIZ;
bzero(nid, ETHADDRSIZ << 1); memcpy(nid,parent_nodeIF,ETHADDRSIZ);
nid += ETHADDRSIZ;
memcpy(nid,receivingIF,ETHADDRSIZ);
//bzero(nid, ETHADDRSIZ);
if ( sendnbors != 0 ) { if ( sendnbors != 0 ) {
while ( nborl != NULL ) { while ( nborl != NULL ) {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: serv.c,v 1.3 2001-06-14 23:19:23 ikumar Exp $ * $Id: serv.c,v 1.7 2001-08-04 22:58:30 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -46,12 +46,14 @@ main(int argc, char **argv) ...@@ -46,12 +46,14 @@ main(int argc, char **argv)
{ {
perror("bind"); perror("bind");
} }
printf("The address I am listening on is: %s\n",inet_ntoa(servaddr.sin_addr)); //printf("The address I am listening on is: %s\n",inet_ntoa(servaddr.sin_addr));
/*
if(getsockname(sockfd, (struct sockaddr *)&name, &namelen)<0) if(getsockname(sockfd, (struct sockaddr *)&name, &namelen)<0)
{ {
perror("getsockname\n"); perror("getsockname\n");
} }
printf("No I am listening on: \"%s\"\n",sock_ntop(&name,name.sa_len)); printf("No I am listening on: \"%s\"\n",sock_ntop(&name,name.sa_len));
*/
serv_listen(sockfd, (struct sockaddr *) &cliaddr, sizeof(cliaddr)); serv_listen(sockfd, (struct sockaddr *) &cliaddr, sizeof(cliaddr));
/* We'll never get here */ /* We'll never get here */
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: serv_listen.c,v 1.7 2001-06-18 01:41:19 ikumar Exp $ * $Id: serv_listen.c,v 1.8 2001-07-19 19:55:57 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -41,6 +41,8 @@ extern topd_inqid_t inqid_current; ...@@ -41,6 +41,8 @@ extern topd_inqid_t inqid_current;
* as the nodeID. * as the nodeID.
*/ */
u_char myNodeID[ETHADDRSIZ]; u_char myNodeID[ETHADDRSIZ];
u_char parent_nodeIF[ETHADDRSIZ];
u_char receivingIF[ETHADDRSIZ];
/* /*
* Return 0 if the inquiry is not from us, 1 if it is. * Return 0 if the inquiry is not from us, 1 if it is.
...@@ -60,11 +62,17 @@ from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead) ...@@ -60,11 +62,17 @@ from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead)
int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead) int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead)
{ {
char *name1,*name2; char *name1,*name2,*name_tmp;
struct ifi_info *ifi; struct ifi_info *ifi;
for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next) { for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next) {
name1=inet_ntoa(((struct sockaddr_in *)ifi->ifi_addr)->sin_addr); name_tmp=inet_ntoa(((struct sockaddr_in *)ifi->ifi_addr)->sin_addr);
name2=inet_ntoa(((struct sockaddr_in *)pcliaddr)->sin_addr); if((name1 = (char*)malloc(sizeof(char)*strlen(name_tmp)))==NULL)
perror("is_my_packet: problem in malloc");
strcpy(name1,name_tmp);
name_tmp=inet_ntoa(((struct sockaddr_in *)pcliaddr)->sin_addr);
if((name2 = (char*)malloc(sizeof(char)*strlen(name_tmp)))==NULL)
perror("is_my_packet: problem in malloc");
strcpy(name2,name_tmp);
//printf("name1:\"%s\" name2:\"%s\"\n",name1,name2); //printf("name1:\"%s\" name2:\"%s\"\n",name1,name2);
if(strcmp(name1,name2)==0) if(strcmp(name1,name2)==0)
return 1; return 1;
...@@ -72,6 +80,22 @@ int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead) ...@@ -72,6 +80,22 @@ int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead)
return 0; return 0;
} }
void
get_recvIFADDR(char *name,struct ifi_info * ifihead)
{
struct ifi_info * ifi=NULL;
for (ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next)
{
if(strcmp(name,ifi->ifi_name)==0)
//Will do this once know the conversion from MAC address to hostname
//-ik
//memcpy(&receivingIF,&(ifi->ifi_haddr),ETHADDRSIZ);
memcpy(&receivingIF,&myNodeID,ETHADDRSIZ);
}
}
/* /*
* Return 0 if the two inquiries are identical, non-zero if not. * Return 0 if the two inquiries are identical, non-zero if not.
*/ */
...@@ -116,7 +140,7 @@ print_ifi_info(struct ifi_info *ifihead) ...@@ -116,7 +140,7 @@ print_ifi_info(struct ifi_info *ifihead)
void void
serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
{ {
int flags, class; int flags, class=NEW;
const int on = 1; const int on = 1;
socklen_t len; socklen_t len;
ssize_t n; ssize_t n;
...@@ -141,7 +165,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -141,7 +165,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
* is supported on FreeBSD. -lkw * is supported on FreeBSD. -lkw
*/ */
if (setsockopt(sockfd, IPPROTO_IP, IP_RECVIF, &on, sizeof(on)) < 0) { if (setsockopt(sockfd, IPPROTO_IP, IP_RECVIF, &on, sizeof(on)) < 0) {
printf("setsockopt of IP_RECVIF"); fprintf(stderr,"setsockopt of IP_RECVIF");
return; return;
} }
...@@ -153,7 +177,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -153,7 +177,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*/ */
//ik: get the list of interfaces using the function "get_ifi_info" into the //ik: get the list of interfaces using the function "get_ifi_info" into the
//link list "ifi" //link list "ifi" and the max hardware address of all the i/fs is the Node ID
for (ifihead = ifi = get_ifi_info(AF_INET, 0); for (ifihead = ifi = get_ifi_info(AF_INET, 0);
ifi != NULL; ifi = ifi->ifi_next) { ifi != NULL; ifi = ifi->ifi_next) {
if ( ifi->ifi_hlen > 0) { if ( ifi->ifi_hlen > 0) {
...@@ -161,7 +185,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -161,7 +185,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
} }
} }
memcpy(&myNodeID, myNodeIDtmp, ETHADDRSIZ); memcpy(&myNodeID, myNodeIDtmp, ETHADDRSIZ);
printf("My node id:"); printf("My node id:");
print_nodeID(myNodeID); print_nodeID(myNodeID);
print_ifi_info(ifihead); print_ifi_info(ifihead);
...@@ -173,7 +197,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -173,7 +197,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
*/ */
i=0; i=0;
for ( ; ; ) { for ( ; ; ) {
printf("**********for==>%d\n",i++); //printf("**********for==>%d\n",i++);
len = clilen; len = clilen;
flags = 0; flags = 0;
n = recvfrom_flags(sockfd, mesg, MAXLINE, &flags, n = recvfrom_flags(sockfd, mesg, MAXLINE, &flags,
...@@ -208,6 +232,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -208,6 +232,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
* *
* We now classify each inquiry. * We now classify each inquiry.
*/ */
ifihead = get_ifi_info(AF_INET, 0);
if(inqhead==NULL) class = NEW; if(inqhead==NULL) class = NEW;
j=0; j=0;
...@@ -243,14 +268,22 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -243,14 +268,22 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
/* /*
* Save the inquiry ID into inqid_current. * Save the inquiry ID into inqid_current.
*/ */
get_recvIFADDR(if_indextoname(pktinfo.ipi_ifindex, ifname),ifihead);
//printf(">>>>>>>The receiving interface is:");
//print_nodeID(receivingIF);
memcpy(&inqid_current, mesg, sizeof(topd_inqid_t)); memcpy(&inqid_current, mesg, sizeof(topd_inqid_t));
/* Send string to all interfaces. forward_request() will /* Send string to all interfaces. forward_request() will
* stuff reply into ifi_info. * stuff reply into ifi_info.
*/ */
ifihead = get_ifi_info(AF_INET, 0); //ifihead = get_ifi_info(AF_INET, 0);
temp_inqid = (struct topd_inqid *)mesg; temp_inqid = (struct topd_inqid *)mesg;
memcpy(&parent_nodeIF, &(temp_inqid->tdi_p_nodeIF), ETHADDRSIZ);
//printf("Parents interface:");
//print_nodeID(parent_nodeIF);
t_int = ntohs(temp_inqid->tdi_ttl); t_int = ntohs(temp_inqid->tdi_ttl);
if(t_int==0) if(t_int==0)
printf("The TTL is zero so i will not forward!!\n"); printf("The TTL is zero so i will not forward!!\n");
...@@ -273,8 +306,8 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -273,8 +306,8 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
//temp->tdi_ttl = htons(t_int); //temp->tdi_ttl = htons(t_int);
ifihead=forward_request(ifihead, &pktinfo, mesg, n ); ifihead=forward_request(ifihead, &pktinfo, mesg, n );
printf("printing after forward===>\n"); //printf("printing after forward===>\n");
print_tdifinbrs(ifihead); //print_tdifinbrs(ifihead);
} }
...@@ -288,7 +321,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -288,7 +321,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
printf("done!\n"); printf("done!\n");
free_ifi_info(ifihead); free_ifi_info(ifihead);
printf("I am sending the response to: %s\n",sock_ntop(pcliaddr,sizeof(struct sockaddr))); printf("Sending response to: %s\n",sock_ntop(pcliaddr,sizeof(struct sockaddr)));
/* send response back to original sender */