got rid of getAllIPV4Addresses

pull/14/head
Tom Early 7 years ago
parent 04a620dbe1
commit 254f15e3a0

@ -472,48 +472,8 @@ bool IRCDDBApp::findGateway(const std::string &gwCall)
return true;
}
static void findReflector(const std::string &rptrCall, IRCDDBAppPrivate *d)
{
std::string zonerp_cs;
std::string ipAddr;
#define MAXIPV4ADDR 5
struct sockaddr_in addr[MAXIPV4ADDR];
unsigned int numAddr = 0;
char host_name[80];
std::string host = rptrCall.substr(0,6) + ".reflector.ircddb.net";
safeStringCopy(host_name, host.c_str(), sizeof host_name);
if (getAllIPV4Addresses(host_name, 0, &numAddr, addr, MAXIPV4ADDR) == 0) {
if (numAddr > 0) {
unsigned char *a = (unsigned char *) &addr[0].sin_addr;
char buf[16];
snprintf(buf, 16, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
ipAddr = buf;
zonerp_cs = rptrCall;
zonerp_cs[7] = 'G';
}
}
IRCMessage *m2 = new IRCMessage("IDRT_REPEATER");
m2->addParam(rptrCall);
m2->addParam(zonerp_cs);
m2->addParam(ipAddr);
d->replyQ.putMessage(m2);
}
bool IRCDDBApp::findRepeater(const std::string &rptrCall)
{
if (0==rptrCall.compare(0, 3, "XRF") || 0==rptrCall.compare(0, 3, "REF")) {
findReflector(rptrCall, d);
return true;
}
std::string arearp_cs = rptrCall;
ReplaceChar(arearp_cs, ' ', '_');

@ -35,84 +35,6 @@ std::vector<std::string> stringTokenizer(const std::string &s)
return result;
}
int getAllIPV4Addresses(const char * name, unsigned short port, unsigned int * num, struct sockaddr_in * addr, unsigned int max_addr)
{
struct addrinfo hints;
struct addrinfo * res;
memset(&hints, 0x00, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
int r = getaddrinfo(name, NULL, &hints, &res);
if (r == 0) {
struct addrinfo * rp;
unsigned int numAddr = 0;
for (rp = res; rp != NULL; rp = rp->ai_next) {
if (rp->ai_family == AF_INET)
numAddr ++;
}
if (numAddr > 0) {
if (numAddr > max_addr)
numAddr = max_addr;
int * shuffle = new int[numAddr];
unsigned int i;
for (i=0; i < numAddr; i++)
shuffle[i] = i;
for (i=0; i < (numAddr - 1); i++) {
if (rand() & 1) {
int tmp;
tmp = shuffle[i];
shuffle[i] = shuffle[i+1];
shuffle[i+1] = tmp;
}
}
for (i=(numAddr - 1); i > 0; i--) {
if (rand() & 1) {
int tmp;
tmp = shuffle[i];
shuffle[i] = shuffle[i-1];
shuffle[i-1] = tmp;
}
}
for (rp = res, i=0 ; (rp != NULL) && (i < numAddr); rp = rp->ai_next) {
if (rp->ai_family == AF_INET) {
memcpy( addr+shuffle[i], rp->ai_addr, sizeof (struct sockaddr_in) );
addr[shuffle[i]].sin_port = htons(port);
i++;
}
}
delete[] shuffle;
}
*num = numAddr;
freeaddrinfo(res);
return 0;
} else {
printf("getaddrinfo: %s\n", gai_strerror(r));
return 1;
}
}
void safeStringCopy (char *dest, const char *src, unsigned int buf_size)
{
unsigned int i = 0;

@ -27,8 +27,6 @@ time_t parseTime(const std::string str);
std::vector<std::string> stringTokenizer(const std::string &str);
int getAllIPV4Addresses(const char *name, unsigned short port, unsigned int *num, struct sockaddr_in *addr, unsigned int max_addr);
void safeStringCopy(char * dest, const char * src, unsigned int buf_size);
char *getCurrentTime(void);

Loading…
Cancel
Save

Powered by TurnKey Linux.