From ccf606fd9e354886ab41a71a09c1d80745285d9e Mon Sep 17 00:00:00 2001 From: Vladimir Dubrovin <3proxy@3proxy.ru> Date: Sun, 11 May 2014 02:41:13 +0400 Subject: [PATCH] ntoa changed to ntop --- src/3proxy.c | 2 +- src/auth.c | 2 +- src/common.c | 33 +++++++++++++++++++++------------ src/datatypes.c | 2 +- src/icqpr.c | 4 ++-- src/msnpr.c | 2 +- src/plugins.c | 4 ++-- src/proxy.c | 4 ++-- src/proxy.h | 2 +- src/socks.c | 5 +++-- src/structures.h | 2 +- 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/3proxy.c b/src/3proxy.c index 20e8caa..751fcf6 100644 --- a/src/3proxy.c +++ b/src/3proxy.c @@ -727,7 +727,7 @@ static int h_proxy(int argc, unsigned char ** argv){ } static int h_internal(int argc, unsigned char ** argv){ - getip46(46, argv[1], &conf.intsa); + getip46(46, argv[1], (struct sockaddr *)&conf.intsa); return 0; } diff --git a/src/auth.c b/src/auth.c index 9ccb124..5c1999f 100644 --- a/src/auth.c +++ b/src/auth.c @@ -100,7 +100,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, unsigned l len = 8 + sprintf((char *)buf + 8, "%.256s", param->hostname); } else { - len = 8 + myinet_ntoa(ina, (char *)buf+8); + len = 8 + myinet_ntop(AF_INET, &ina, (char *)buf+8, 256); } len += sprintf((char *)buf + len, ":%hu HTTP/1.0\r\nProxy-Connection: keep-alive\r\n", ntohs(port)); diff --git a/src/common.c b/src/common.c index 341967f..96397ca 100644 --- a/src/common.c +++ b/src/common.c @@ -22,13 +22,22 @@ int randomizer = 1; unsigned char **stringtable = NULL; -int myinet_ntoa(struct in_addr in, char * buf){ - unsigned u = ntohl(in.s_addr); - return sprintf(buf, "%u.%u.%u.%u", - ((u&0xFF000000)>>24), - ((u&0x00FF0000)>>16), - ((u&0x0000FF00)>>8), - ((u&0x000000FF))); +int myinet_ntop(int af, const void *src, char *dst, socklen_t size){ +#ifndef NOIPV6 + if(af != AF_INET6){ +#endif + unsigned u = ntohl(((struct in_addr *)src)->s_addr); + return sprintf(dst, "%u.%u.%u.%u", + ((u&0xFF000000)>>24), + ((u&0x00FF0000)>>16), + ((u&0x0000FF00)>>8), + ((u&0x000000FF))); +#ifndef NOIPV6 + } + *dst = 0; + inet_ntop(af, src, dst, size); + return strlen(dst); +#endif } char *rotations[] = { @@ -421,7 +430,7 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char i++; } } - else i += myinet_ntoa(param->sins.sin_addr, (char *)buf + i); + else i += myinet_ntop(*SAFAMILY(¶m->sins), SAADDR(¶m->sins), (char *)buf + i, 64); break; case 'N': @@ -451,16 +460,16 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char break; case 'e': tmpia.s_addr = param->extip; - i += myinet_ntoa(tmpia, (char *)buf + i); + i += myinet_ntop(AF_INET, &tmpia, (char *)buf + i, 64); break; case 'C': - i += myinet_ntoa(param->sinc.sin_addr, (char *)buf + i); + i += myinet_ntop(*SAFAMILY(¶m->sinc), SAADDR(¶m->sinc), (char *)buf + i, 64); break; case 'R': - i += myinet_ntoa(param->sins.sin_addr, (char *)buf + i); + i += myinet_ntop(*SAFAMILY(¶m->sins), SAADDR(¶m->sins), (char *)buf + i, 64); break; case 'Q': - i += myinet_ntoa(param->req.sin_addr, (char *)buf + i); + i += myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + i, 64); break; case 'p': sprintf((char *)buf+i, "%hu", ntohs(*SAPORT(¶m->srv->intsa))); diff --git a/src/datatypes.c b/src/datatypes.c index a80196e..211020d 100644 --- a/src/datatypes.c +++ b/src/datatypes.c @@ -77,7 +77,7 @@ static void pr_sa(struct node *node, CBFUNC cbf, void*cb){ if(node->value)return pr_ip(node, &((struct sockaddr_in *)node->value)->sin_addr.s_addr) #else char buf[64]; - buf[0] = '[' + buf[0] = '['; buf[1] = 0; inet_ntop(*SAFAMILY(node->value), node->value, buf+1, sizeof(buf)-10); sprintf(buf + strlen(buf), "]:hu", (unsigned short)*SAPORT(node->value)); diff --git a/src/icqpr.c b/src/icqpr.c index ee6808a..0cde9c0 100644 --- a/src/icqpr.c +++ b/src/icqpr.c @@ -118,7 +118,7 @@ static void addbuffer(int increment, struct clientparam * param, unsigned char * static int searchcookie(struct clientparam *param, struct flap_header * flap, int len, int * dif, struct tlv_header *tlv, int extra){ struct icq_cookie *ic; - char smallbuf[32]; + char smallbuf[64]; struct tlv_header *bostlv = NULL; struct sockaddr_in sa; SASIZETYPE size = sizeof(sa); @@ -165,7 +165,7 @@ static int searchcookie(struct clientparam *param, struct flap_header * flap, in pthread_mutex_unlock(&icq_cookie_mutex); if(bostlv){ if(so._getsockname(param->clisock, (struct sockaddr *)&sa, &size)==-1) return 1; - len = myinet_ntoa(sa.sin_addr, smallbuf); + len = myinet_ntop(*SAFAMILY(&sa),SAADDR(&sa), smallbuf, 64); if(strchr(ic->connectstring, ':'))sprintf(smallbuf+len, ":%hu", ntohs(sa.sin_port)); len = (int)strlen(smallbuf); *dif = len - (int)ntohs(bostlv->size); diff --git a/src/msnpr.c b/src/msnpr.c index 31895b4..749847e 100644 --- a/src/msnpr.c +++ b/src/msnpr.c @@ -70,7 +70,7 @@ static FILTER_ACTION msn_srv(void *fc, struct clientparam * param, unsigned char len = (int)strlen(tmpbuf); tmpbuf[len++] = ' '; - len+=myinet_ntoa(sa.sin_addr, tmpbuf+len); + len+=myinet_ntop(*SAFAMILY(&sa), SAADDR(&sa), tmpbuf+len, 64); sprintf(tmpbuf+len, ":%hu %s", ntohs(sa.sin_port), sp3 + 1); len = (int)strlen(tmpbuf); memcpy(*buf_p + offset, tmpbuf, len); diff --git a/src/plugins.c b/src/plugins.c index 51a602f..6c21cf4 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -33,7 +33,7 @@ struct symbol symbols[] = { {symbols+5, "sockgetcharcli", (void *) sockgetcharcli}, {symbols+6, "sockgetcharsrv", (void *) sockgetcharsrv}, {symbols+7, "sockgetlinebuf", (void *) sockgetlinebuf}, - {symbols+8, "myinet_ntoa", (void *) myinet_ntoa}, + {symbols+8, "myinet_ntop", (void *) myinet_ntop}, {symbols+9, "dobuf", (void *) dobuf}, {symbols+10, "scanaddr", (void *) scanaddr}, {symbols+11, "getip", (void *) getip}, @@ -103,7 +103,7 @@ struct pluginlink pluginlink = { sockgetcharcli, sockgetcharsrv, sockgetlinebuf, - myinet_ntoa, + myinet_ntop, dobuf, dobuf2, scanaddr, diff --git a/src/proxy.c b/src/proxy.c index c1fe343..6a1a594 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -831,13 +831,13 @@ for(;;){ sprintf((char*)buf+strlen((char *)buf), "Via: 1.1 "); gethostname((char *)(buf+strlen((char *)buf)), 256); sprintf((char*)buf+strlen((char *)buf), ":%d (%s %s)\r\nX-Forwarded-For: ", (int)ntohs(*SAPORT(¶m->srv->intsa)), conf.stringtable?conf.stringtable[2]:(unsigned char *)"", conf.stringtable?conf.stringtable[3]:(unsigned char *)""); - if(!anonymous)myinet_ntoa(param->sinc.sin_addr, (char *)buf + strlen((char *)buf)); + if(!anonymous)myinet_ntop(*SAFAMILY(¶m->sinc), SAADDR(¶m->sinc), (char *)buf + strlen((char *)buf), 64); else { unsigned long tmp; tmp = param->sinc.sin_addr.s_addr; param->sinc.sin_addr.s_addr = ((unsigned long)myrand(param, sizeof(struct clientparam))<<16)^(unsigned long)rand(); - myinet_ntoa(param->sinc.sin_addr, (char *)buf + strlen((char *)buf)); + myinet_ntop(*SAFAMILY(¶m->sinc), SAADDR(¶m->sinc), (char *)buf + strlen((char *)buf), 64); param->sinc.sin_addr.s_addr = tmp; } sprintf((char*)buf+strlen((char *)buf), "\r\n"); diff --git a/src/proxy.h b/src/proxy.h index 829ace8..d539087 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -184,7 +184,7 @@ unsigned bandlimitfunc(struct clientparam *param, unsigned nbytesin, unsigned nb int scanaddr(const unsigned char *s, unsigned long * ip, unsigned long * mask); -int myinet_ntoa(struct in_addr in, char * buf); +int myinet_ntop(int af, const void *src, char *dst, socklen_t size); extern unsigned long nservers[MAXNSERVERS]; extern unsigned long authnserver; unsigned long getip(unsigned char *name); diff --git a/src/socks.c b/src/socks.c index d8c9237..9d980c5 100644 --- a/src/socks.c +++ b/src/socks.c @@ -96,7 +96,7 @@ void * sockschild(struct clientparam* param) { if(command==1 && !param->req.sin_addr.s_addr) { RETURN(422); } - myinet_ntoa(param->sins.sin_addr, (char *)buf); + myinet_ntop(*SAFAMILY(¶m->sins), SAADDR(¶m->sins), (char *)buf + strlen((char *)buf), 64); break; case 3: if ((size = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(451);} /* nmethods */ @@ -400,7 +400,8 @@ fflush(stderr); if(param->hostname){ sprintf((char *)buf + strlen((char *)buf), "%.265s", param->hostname); } - else myinet_ntoa(param->req.sin_addr, (char *)buf+strlen((char *)buf)); + else + myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)buf + strlen((char *)buf), 64); sprintf((char *)buf+strlen((char *)buf), ":%hu", ntohs(param->req.sin_port)); (*param->srv->logfunc)(param, buf); myfree(buf); diff --git a/src/structures.h b/src/structures.h index 9d91ece..dc1c085 100644 --- a/src/structures.h +++ b/src/structures.h @@ -625,7 +625,7 @@ struct pluginlink { int (*sockgetcharcli)(struct clientparam * param, int timeosec, int timeousec); int (*sockgetcharsrv)(struct clientparam * param, int timeosec, int timeousec); int (*sockgetlinebuf)(struct clientparam * param, DIRECTION which, unsigned char * buf, int bufsize, int delim, int to); - int (*myinet_ntoa)(struct in_addr in, char * buf); + int (*myinet_ntop)(int af, const void *src, char *dst, socklen_t size); int (*dobuf)(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec); int (*dobuf2)(struct clientparam * param, unsigned char * buf, const unsigned char *s, const unsigned char * doublec, struct tm* tm, char * format); int (*scanaddr)(const unsigned char *s, unsigned long * ip, unsigned long * mask);