Commit 8579daba authored by ikumar's avatar ikumar

This is the first commit from indrajeet.

parent fe113e1a
'td' is a topology discovery program with a client/server
architecture. The design is platform independent, but this
instance of the implementation is not. In order to be detected, each machine in a network must
be running the td server in order to be detected. Closure is provided
using a hint: the user-estimated network diameter provided as a
command-line argument.
td is written such that topology is discovered in a recursive manner.
When a server receives an 'inquiry' packet
A single client broadcasts an 'inquiry' packet to its local server.
across all interfaces
that are
Limitations:
- This implementation is restricted to FreeBSD
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: cli.c,v 1.2 2000-07-13 18:52:51 kwright Exp $ * $Id: cli.c,v 1.3 2001-06-14 23:19:23 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -62,6 +62,8 @@ find_nodeID(void) ...@@ -62,6 +62,8 @@ find_nodeID(void)
* since the above is just a debug clause and may be * since the above is just a debug clause and may be
* compiled out eventually. -lkw * compiled out eventually. -lkw
*/ */
// Why max is being talken ?! -ik
if ( ifi->ifi_hlen > 0) { if ( ifi->ifi_hlen > 0) {
myNodeIDtmp = max_haddr(myNodeIDtmp, ifi->ifi_haddr); myNodeIDtmp = max_haddr(myNodeIDtmp, ifi->ifi_haddr);
} }
...@@ -115,9 +117,10 @@ cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen, ...@@ -115,9 +117,10 @@ cli(int sockfd, const struct sockaddr *pservaddr, socklen_t servlen,
make_inquiry(&ti, ttl, factor); make_inquiry(&ti, ttl, factor);
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);
print_tdreply(recvline, n); //printf("Receiving in client:==>\n");
//print_tdreply(recvline, n);
} }
/* /*
...@@ -143,6 +146,7 @@ main(int argc, char **argv) ...@@ -143,6 +146,7 @@ main(int argc, char **argv)
sockfd = socket(AF_INET, SOCK_DGRAM, 0); sockfd = socket(AF_INET, SOCK_DGRAM, 0);
printf("calling client\n");
cli(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr), atoi(argv[2]), atoi(argv[3])); cli(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr), atoi(argv[2]), atoi(argv[3]));
exit(0); exit(0);
......
/*$Id: discvr.h,v 1.3 2000-07-18 19:19:27 kwright Exp $*/ /*$Id: discvr.h,v 1.4 2001-06-14 23:19:23 ikumar Exp $*/
#ifndef _TOPD_DISCVR_H_ #ifndef _TOPD_DISCVR_H_
#define _TOPD_DISCVR_H_ #define _TOPD_DISCVR_H_
...@@ -62,7 +62,7 @@ struct ifi_info { ...@@ -62,7 +62,7 @@ struct ifi_info {
void void
serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen); serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen);
void struct ifi_info *
forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
const char *mesg, const int mesglen); const char *mesg, const int mesglen);
struct ifi_info * struct ifi_info *
...@@ -90,5 +90,8 @@ get_rtaddrs(int, struct sockaddr *, struct sockaddr **); ...@@ -90,5 +90,8 @@ get_rtaddrs(int, struct sockaddr *, struct sockaddr **);
u_int32_t u_int32_t
compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors); compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors);
int
is_my_packet(struct sockaddr *pcliaddr, 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.5 2000-07-18 17:13:44 kwright Exp $ * $Id: forw_requests.c,v 1.6 2001-06-14 23:19:23 ikumar Exp $
*/ */
#include <math.h> #include <math.h>
...@@ -47,7 +47,7 @@ tod(void) ...@@ -47,7 +47,7 @@ tod(void)
} }
void struct ifi_info *
forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
const char *mesg, int mesglen) const char *mesg, int mesglen)
{ {
...@@ -58,9 +58,14 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -58,9 +58,14 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct topd_inqid *tdi; struct topd_inqid *tdi;
struct topd_nborlist *save; struct topd_nborlist *save;
struct sockaddr_in sin; struct sockaddr_in sin,tempAddr;
struct ifi_info *ifihead; struct ifi_info *ifihead;
struct timeval tv; struct timeval tv;
int selectReturn;
struct sockaddr name;
int namelen=sizeof(name);
printf("The interface on which I received: \"%s\"\n",if_indextoname(pktinfo->ipi_ifindex, ifname));
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) {
...@@ -72,18 +77,37 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -72,18 +77,37 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* *
* Add check for control net? -lkw * Add check for control net? -lkw
*/ */
if (ifi->ifi_flags & !IFF_UP ||
ifi->ifi_flags & IFF_LOOPBACK ||
strcmp(ifi->ifi_name, if_indextoname(pktinfo->ipi_ifindex, ifname)) == 0) { if ((ifi->ifi_flags & !IFF_UP) ||
(ifi->ifi_flags & IFF_LOOPBACK) ||
(strcmp(ifi->ifi_name, if_indextoname(pktinfo->ipi_ifindex, ifname)) == 0)) {
ifi->ifi_myflags |= MY_IFF_RECVIF; /* may be unnec. -lkw */ ifi->ifi_myflags |= MY_IFF_RECVIF; /* may be unnec. -lkw */
continue; continue;
} }
// Adding check for control net... -ik
if(strcmp(ifi->ifi_name,"fxp4")==0) continue;
printf("Forwarding the query to interface: \"%s\"\n",ifi->ifi_name);
bzero(&tempAddr, sizeof(tempAddr));
tempAddr.sin_family = AF_INET;
//inet_aton("192.168.2.2",&tempAddr.sin_addr.s_addr);
tempAddr.sin_addr.s_addr = htonl(INADDR_ANY);
tempAddr.sin_port = htons(0);
s = socket(AF_INET, SOCK_DGRAM, 0); s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == -1) { if (s == -1) {
perror("Unable to get socket"); perror("Unable to get socket");
exit(1); exit(1);
} }
if(bind(s, (struct sockaddr *) &tempAddr, sizeof(tempAddr))<0)
{
perror("bind");
}
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) != 0) { if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) != 0) {
perror("setsockopt died."); perror("setsockopt died.");
/* Do something intelligent. -lkw */ /* Do something intelligent. -lkw */
...@@ -102,8 +126,9 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -102,8 +126,9 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* struct sockaddr *ifi_brdaddr * struct sockaddr *ifi_brdaddr
* -> ifi_brdaddr->sa_data * -> ifi_brdaddr->sa_data
*/ */
sin.sin_addr.s_addr = inet_addr(ifi->ifi_brdaddr->sa_data); /*sin.sin_addr.s_addr = inet_addr(ifi->ifi_brdaddr->sa_data); */
sin.sin_addr = ((struct sockaddr_in *)(ifi->ifi_brdaddr))->sin_addr;
printf("The dest. address: %s\n", inet_ntoa(sin.sin_addr));
/* /*
* though sendto() returns the correct number of bytes, * though sendto() returns the correct number of bytes,
* tcpdump is showing two packets for this one line. -lkw * tcpdump is showing two packets for this one line. -lkw
...@@ -114,11 +139,20 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -114,11 +139,20 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* 15:04:59.357528 eureka.cs.utah.edu.1192 > 155.99.212.255.9877: udp 15 * 15:04:59.357528 eureka.cs.utah.edu.1192 > 155.99.212.255.9877: udp 15
* 15:20:02.075858 kamas.cs.utah.edu.9877 > eureka.cs.utah.edu.1214: udp 15 * 15:20:02.075858 kamas.cs.utah.edu.9877 > eureka.cs.utah.edu.1214: udp 15
*/ */
fprintf(stderr, "$$$forwarding the enquiry: ");
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));
fprintf(stderr, "sent: "); fprintf(stderr, "$$$after forwarding the enquiry: ");
print_tdinq(mesg); print_tdinq(mesg);
if(getsockname(s, (struct sockaddr *)&name, &namelen)<0)
{
perror("getsockname\n");
}
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);
...@@ -128,7 +162,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -128,7 +162,7 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* Can't wait forever because * Can't wait forever because
* there may be either no nodes on this interface or * there may be either no nodes on this interface or
* the nodes that are there may not be responding. * the nodes that are there may not be responding.
* Our wait delay is equal to the factor times the ttl. * Our wait delay is equal to the "factor times the ttl".
* *
* The packet size *might* exceed our buffer size. * The packet size *might* exceed our buffer size.
* Put in some mechanism to check. -lkw * Put in some mechanism to check. -lkw
...@@ -153,16 +187,26 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -153,16 +187,26 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
* slowly. To cover this case, we should continue to try to * slowly. To cover this case, we should continue to try to
* read from the socket until our delay is up. -lkw * read from the socket until our delay is up. -lkw
*/ */
begin = tod(); begin = tod();
select(s + 1, &rset, NULL, NULL, &tv);
printf("entering select for %d, max = %d****\n", s, FD_SETSIZE);
selectReturn = select(FD_SETSIZE, &rset, NULL, NULL, &tv);
if( selectReturn < 0 ) {
printf("Error in Select call\n");
perror("select");
exit(1);
}
else if(selectReturn == 0)
{
printf("Select timed out****\n");
}
end = tod(); end = tod();
if (!FD_ISSET(s, &rset)) { if (!FD_ISSET(s, &rset)) {
/* socket is not readable */ /* socket is not readable */
fprintf(stderr, "Socket not readable before timeout.\n"); fprintf(stderr, "Socket not readable before timeout.\n");
more_time = 0; more_time = 0;
/*continue;*/ /*continue; */
} }
/* get ready for next select */ /* get ready for next select */
...@@ -175,13 +219,27 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -175,13 +219,27 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
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;
fprintf(stderr, "sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec); fprintf(stderr, "sec:%d usec:%d\n", tv.tv_sec, tv.tv_usec);
n = recvfrom(s, recvbuf, BUFSIZ, 0, NULL, NULL);
// receive one of my neighbors' list of neighbors through
// "ifi" interface to which I just forwarded the request -ik
n = recvfrom(s, recvbuf, BUFSIZ, 0, NULL, NULL);
//printf ("recvd %d\n", n);
printf ("received:==>\n");
print_tdreply(recvbuf,n);
/* /*
* Be sure to malloc enough space for all of the mesg. * Be sure to malloc enough space for all of the mesg.
* See note above about possible datagram truncation. -lkw * See note above about possible datagram truncation. -lkw
*/ */
save = ifi->ifi_nbors;
// save the existing list of neighbors which I just received through
// the "ifi" interface... -ik
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"
// -ik
ifi->ifi_nbors = (struct topd_nborlist *)malloc(sizeof(struct topd_nborlist)); ifi->ifi_nbors = (struct topd_nborlist *)malloc(sizeof(struct topd_nborlist));
if ( ifi->ifi_nbors == NULL ) { if ( ifi->ifi_nbors == NULL ) {
perror("Not enough memory for neighbor list."); perror("Not enough memory for neighbor list.");
...@@ -193,9 +251,21 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo, ...@@ -193,9 +251,21 @@ forward_request(struct ifi_info *ifi, const struct in_pktinfo *pktinfo,
perror("Not enough memory for neighbor list."); perror("Not enough memory for neighbor list.");
exit(1); exit(1);
} }
// why "recvbuf + sizeof(topd_inqid_t)" ?
// Ans: The reason we skip this first "sizeof(topd_inqid_t)" is because
// to every message there is a "inquiry ID" attached in the beginning...
// -ik
//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);
// The "tdnbl_n" contains the number of neighbors that the node, along this
// interface, has ... -ik
ifi->ifi_nbors->tdnbl_n = n / sizeof(struct topd_nbor); ifi->ifi_nbors->tdnbl_n = n / 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_tdifinbrs(ifihead);
return ifihead;
} }
...@@ -29,6 +29,10 @@ get_ifi_info(int family, int doaliases) ...@@ -29,6 +29,10 @@ get_ifi_info(int family, int doaliases)
struct sockaddr_dl *sdl; struct sockaddr_dl *sdl;
struct ifi_info *ifi, *ifisave, *ifihead, **ifipnext; struct ifi_info *ifi, *ifisave, *ifihead, **ifipnext;
// Get the temporary list of interfaces in the "buf" buffer and the
// length of the list in "len"...
// there may be some interfaces which are not up... or some may not
// be having network addresses already... -ik
buf = net_rt_iflist(family, 0, &len); buf = net_rt_iflist(family, 0, &len);
ifihead = NULL; ifihead = NULL;
...@@ -37,20 +41,41 @@ get_ifi_info(int family, int doaliases) ...@@ -37,20 +41,41 @@ get_ifi_info(int family, int doaliases)
lim = buf + len; lim = buf + len;
for (next = buf; next < lim; next += ifm->ifm_msglen) { for (next = buf; next < lim; next += ifm->ifm_msglen) {
ifm = (struct if_msghdr *) next; ifm = (struct if_msghdr *) next;
// "ifm_type" is the interface information message type
// RTM_IFINFO: interface going up or down
if (ifm->ifm_type == RTM_IFINFO) { if (ifm->ifm_type == RTM_IFINFO) {
if ( ((flags = ifm->ifm_flags) & IFF_UP) == 0) if ( ((flags = ifm->ifm_flags) & IFF_UP) == 0)
continue; /* ignore if interface not up */ continue; /* ignore if interface not up */
// Interface is up.. get the list of addresses on the back of
// message header and proceed
sa = (struct sockaddr *) (ifm + 1); sa = (struct sockaddr *) (ifm + 1);
// Get the sockadders in the rti_info array after reading from
// "sa" list
get_rtaddrs(ifm->ifm_addrs, sa, rti_info); get_rtaddrs(ifm->ifm_addrs, sa, rti_info);
// The sockaddr at "RTAX_IFP" index has the name and link level
// address for the interface.
if ( (sa = rti_info[RTAX_IFP]) != NULL) { if ( (sa = rti_info[RTAX_IFP]) != NULL) {
// Make a node of the link list "ifi" to store information
// about an interface..
ifi = calloc(1, sizeof(struct ifi_info)); ifi = calloc(1, sizeof(struct ifi_info));
*ifipnext = ifi; /* prev points to this new one */ *ifipnext = ifi; /* prev points to this new one */
ifipnext = &ifi->ifi_next; /* ptr to next one goes here */ ifipnext = &ifi->ifi_next; /* ptr to next one goes here */
ifi->ifi_flags = flags; ifi->ifi_flags = flags;
// If its not a link layer interface then ignore
if (sa->sa_family == AF_LINK) { if (sa->sa_family == AF_LINK) {
// copy the sock adder to link level sockaddr
// coz we now know its a link level address
sdl = (struct sockaddr_dl *) sa; sdl = (struct sockaddr_dl *) sa;
// Now, get the name and address of the link level
// interface...
if (sdl->sdl_nlen > 0) if (sdl->sdl_nlen > 0)
snprintf(ifi->ifi_name, IFNAMSIZ, "%*s", snprintf(ifi->ifi_name, IFNAMSIZ, "%*s",
sdl->sdl_nlen, &sdl->sdl_data[0]); sdl->sdl_nlen, &sdl->sdl_data[0]);
...@@ -63,6 +88,8 @@ get_ifi_info(int family, int doaliases) ...@@ -63,6 +88,8 @@ get_ifi_info(int family, int doaliases)
min(IFHADDRSIZ, sdl->sdl_alen)); min(IFHADDRSIZ, sdl->sdl_alen));
} }
} }
// Check if address is being added to the interface...
} else if (ifm->ifm_type == RTM_NEWADDR) { } else if (ifm->ifm_type == RTM_NEWADDR) {
if (ifi->ifi_addr) { /* already have an IP addr for i/f */ if (ifi->ifi_addr) { /* already have an IP addr for i/f */
if (doaliases == 0) if (doaliases == 0)
......
...@@ -5,26 +5,38 @@ ...@@ -5,26 +5,38 @@
#include "discvr.h" #include "discvr.h"
//
char * char *
net_rt_iflist(int family, int flags, size_t *lenp) net_rt_iflist(int family, int flags, size_t *lenp)
{ {
int mib[6]; int mib[6];
char *buf; char *buf;
mib[0] = CTL_NET; // Meaning of each parameter is explained below -ik
mib[1] = AF_ROUTE; mib[0] = CTL_NET; // network related system information
mib[2] = 0; mib[1] = PF_ROUTE; // get the routing messages
mib[3] = family; /* only addresses of this family */ mib[2] = 0; // protocol number (always zero!)
mib[4] = NET_RT_IFLIST; mib[3] = family; // get addresses of only this family
mib[5] = flags; /* interface index, or 0 */ mib[4] = NET_RT_IFLIST; // return "interface" list
mib[5] = flags; /* interface index, or 0*/ // "man" says NONE?!
// Call "sysctl" to get the length of buffer needed for storing the list
// of interfaces. The "oldp" parameter is supplied with NULL to get just
// the size. -ik
if (sysctl(mib, 6, NULL, lenp, NULL, 0) < 0) if (sysctl(mib, 6, NULL, lenp, NULL, 0) < 0)
return(NULL); return(NULL);
// Allocate a buffer to store the list of interfaces. -ik
if ( (buf = malloc(*lenp)) == NULL) if ( (buf = malloc(*lenp)) == NULL)
return(NULL); return(NULL);
// Get the list of interfaces in the "buf". -ik
if (sysctl(mib, 6, buf, lenp, NULL, 0) < 0) if (sysctl(mib, 6, buf, lenp, NULL, 0) < 0)
return(NULL); return(NULL);
// Return the list of interfaces. -ik
return(buf); return(buf);
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: reply.c,v 1.5 2000-07-18 19:19:28 kwright Exp $ * $Id: reply.c,v 1.6 2001-06-14 23:19:23 ikumar Exp $
*/ */
...@@ -53,7 +53,7 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors ...@@ -53,7 +53,7 @@ compose_reply(struct ifi_info *ifi, char *mesg, const int mesglen, int sendnbors
/* Add check for control net -LKW */ /* Add check for control net -LKW */
if (ifi->ifi_flags & !IFF_UP || if (ifi->ifi_flags & !IFF_UP ||
ifi->ifi_flags & IFF_LOOPBACK) { ifi->ifi_flags & IFF_LOOPBACK || (strcmp(ifi->ifi_name,"fxp4")==0)) {
continue; continue;
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* --------------------------- * ---------------------------
* *
* $Id: serv.c,v 1.2 2000-07-13 18:52:52 kwright Exp $ * $Id: serv.c,v 1.3 2001-06-14 23:19:23 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -32,6 +32,8 @@ main(int argc, char **argv) ...@@ -32,6 +32,8 @@ main(int argc, char **argv)
{ {
int sockfd; int sockfd;
struct sockaddr_in servaddr, cliaddr; struct sockaddr_in servaddr, cliaddr;
struct sockaddr name;
int namelen=sizeof(name);
sockfd = socket(AF_INET, SOCK_DGRAM, 0); sockfd = socket(AF_INET, SOCK_DGRAM, 0);
...@@ -40,8 +42,16 @@ main(int argc, char **argv) ...@@ -40,8 +42,16 @@ main(int argc, char **argv)
servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERV_PORT); servaddr.sin_port = htons(SERV_PORT);
bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); if(bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr))<0)
{
perror("bind");
}
printf("The address I am listening on is: %s\n",inet_ntoa(servaddr.sin_addr));
if(getsockname(sockfd, (struct sockaddr *)&name, &namelen)<0)
{
perror("getsockname\n");
}
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.5 2000-07-18 19:19:28 kwright Exp $ * $Id: serv_listen.c,v 1.6 2001-06-14 23:19:23 ikumar Exp $
*/ */
#include "discvr.h" #include "discvr.h"
...@@ -58,6 +58,20 @@ from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead) ...@@ -58,6 +58,20 @@ from_us(struct in_pktinfo *pktinfo, struct ifi_info *ifihead)
return 0; return 0;
} }
int is_my_packet(struct sockaddr *pcliaddr, struct ifi_info *ifihead)
{
char *name1,*name2;
struct ifi_info *ifi;
for( ifi = ifihead; ifi != NULL; ifi = ifi->ifi_next) {
name1=inet_ntoa(((struct sockaddr_in *)ifi->ifi_addr)->sin_addr);
name2=inet_ntoa(((struct sockaddr_in *)pcliaddr)->sin_addr);
fprintf(stderr,"name1:\"%s\" name2:\"%s\"\n",name1,name2);
if(strcmp(name1,name2)==0)
return 1;
}
return 0;
}
/* /*
* Return 0 if the two inquiries are identical, non-zero if not. * Return 0 if the two inquiries are identical, non-zero if not.
*/ */
...@@ -81,7 +95,7 @@ print_ifi_info(struct ifi_info *ifihead) ...@@ -81,7 +95,7 @@ print_ifi_info(struct ifi_info *ifihead)
if (ifi->ifi_flags & IFF_BROADCAST) printf("BCAST "); if (ifi->ifi_flags & IFF_BROADCAST) printf("BCAST ");
if (ifi->ifi_flags & IFF_MULTICAST) printf("MCAST "); if (ifi->ifi_flags & IFF_MULTICAST) printf("MCAST ");
if (ifi->ifi_flags & IFF_LOOPBACK) printf("LOOP "); if (ifi->ifi_flags & IFF_LOOPBACK) printf("LOOP ");
if (ifi->ifi_flags & IFF_POINTOPOINT) printf("P2P "); if (ifi->ifi_flags & IFF_POINTOPOINT) printf("P2P ");
printf(">\n"); printf(">\n");
print_nodeID(ifi->ifi_haddr); print_nodeID(ifi->ifi_haddr);
...@@ -109,6 +123,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -109,6 +123,7 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
struct ifi_info *ifi, *ifihead; struct ifi_info *ifi, *ifihead;
struct in_pktinfo pktinfo; struct in_pktinfo pktinfo;
struct topd_inqnode *inqn, *inqhead = 0; struct topd_inqnode *inqn, *inqhead = 0;
int i=0,j=0;
/* /*
* Use this option to specify that the receiving interface * Use this option to specify that the receiving interface
...@@ -130,6 +145,9 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -130,6 +145,9 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
/* /*
* Find and set our node ID * Find and set our node ID
*/ */
//ik: get the list of interfaces using the function "get_ifi_info" into the
//link list "ifi"
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) {
...@@ -147,13 +165,16 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen) ...@@ -147,13 +165,16 @@ serv_listen(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
* Wait for requests. When a request comes in, send the request * Wait for requests. When a request comes in, send the request
* on to each interface. * on to each interface.
*/ */
i=0;
for ( ; ; ) { for ( ; ; ) {
fprintf(stderr,"**********for==>%d\n",i++);
len = clilen; len = clilen;