From 99a28d474234a07081ea1beb28bb774169390314 Mon Sep 17 00:00:00 2001 From: fredrik Date: Wed, 5 Jul 2006 18:40:37 +0000 Subject: [PATCH] Check hub addresses for sources hubs. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/doldaconnect@667 959494ce-11ee-0310-bf91-de5d638817bd --- daemon/fnet-dc.c | 33 +++++++++++++++++++++++++++++++++ daemon/net.c | 34 ++++++++++++++++++++++++++++++++++ daemon/net.h | 1 + 3 files changed, 68 insertions(+) diff --git a/daemon/fnet-dc.c b/daemon/fnet-dc.c index ed34272..1e4406c 100644 --- a/daemon/fnet-dc.c +++ b/daemon/fnet-dc.c @@ -2724,6 +2724,7 @@ static void udpread(struct socket *sk, void *data) char *buf, *p, *p2, *hashbuf; size_t buflen, hashlen; char *nick, *filename, *hubname; + struct sockaddr_in hubaddr; int size, slots; struct fnetnode *fn, *myfn; struct dchub *hub; @@ -2783,6 +2784,27 @@ static void udpread(struct socket *sk, void *data) return; } *p2 = 0; + p = p2 + 2; + if((p2 = strchr(p, ':')) == NULL) + { + free(buf); + return; + } + *(p2 + 1) = 0; + hubaddr.sin_family = AF_INET; + if(!inet_aton(p, &hubaddr.sin_addr)) + { + free(buf); + return; + } + p = p2; + if((p2 = strchr(p, ')')) == NULL) + { + free(buf); + return; + } + *p2 = 0; + hubaddr.sin_port = htons(atoi(p)); if((wnick = icmbstowcs(nick, DCCHARSET)) == NULL) { free(buf); @@ -2822,6 +2844,17 @@ static void udpread(struct socket *sk, void *data) } } } + if(myfn == NULL) + { + for(fn = fnetnodes; fn != NULL; fn = fn->next) + { + if((fn->fnet == &dcnet) && addreq(fn->sk->remote, (struct sockaddr *)&hubaddr)) + { + myfn = fn; + break; + } + } + } sr = newsrchres(&dcnet, wfile, wnick); if(sr->peernick != NULL) free(sr->peernick); diff --git a/daemon/net.c b/daemon/net.c index 866e136..576ea6f 100644 --- a/daemon/net.c +++ b/daemon/net.c @@ -1092,6 +1092,40 @@ int sockgetremotename(struct socket *sk, struct sockaddr **namebuf, socklen_t *l } } +int addreq(struct sockaddr *x, struct sockaddr *y) +{ + struct sockaddr_un *u1, *u2; + struct sockaddr_in *n1, *n2; +#ifdef HAVE_IPV6 + struct sockaddr_in6 *s1, *s2; +#endif + + if(x->sa_family != y->sa_family) + return(0); + switch(x->sa_family) { + case AF_UNIX: + u1 = (struct sockaddr_un *)x; u2 = (struct sockaddr_un *)y; + if(strncmp(u1->sun_path, u2->sun_path, sizeof(u1->sun_path))) + return(0); + break; + case AF_INET: + n1 = (struct sockaddr_in *)x; n2 = (struct sockaddr_in *)y; + if(n1->sin_port != n2->sin_port) + return(0); + if(n1->sin_addr.s_addr != n2->sin_addr.s_addr) + return(0); + break; + case AF_INET6: + s1 = (struct sockaddr_in6 *)x; s2 = (struct sockaddr_in6 *)y; + if(s1->sin6_port != s2->sin6_port) + return(0); + if(memcmp(s1->sin6_addr.s6_addr, s2->sin6_addr.s6_addr, sizeof(s1->sin6_addr.s6_addr))) + return(0); + break; + } + return(1); +} + char *formataddress(struct sockaddr *arg, socklen_t arglen) { struct sockaddr_un *UNIX; /* Some wise guy has #defined unix with diff --git a/daemon/net.h b/daemon/net.h index 582d9aa..106ac81 100644 --- a/daemon/net.h +++ b/daemon/net.h @@ -108,6 +108,7 @@ struct socket *wrapsock(int fd); size_t sockgetdatalen(struct socket *sk); int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf); int socksettos(struct socket *sk, int tos); +int addreq(struct sockaddr *x, struct sockaddr *y); char *formataddress(struct sockaddr *arg, socklen_t arglen); void sockpushdata(struct socket *sk, void *buf, size_t size); -- 2.11.0