Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
298 additions
and
111 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
** JNetLib | ||
** Copyright (C) 2000-2001 Nullsoft, Inc. | ||
** Author: Justin Frankel | ||
** File: asyncdns.h - JNL portable asynchronous DNS interface | ||
** License: see jnetlib.h | ||
** | ||
** Usage: | ||
** 1. Create JNL_AsyncDNS object, optionally with the number of cache entries. | ||
** 2. call resolve() to resolve a hostname into an address. The return value of | ||
** resolve is 0 on success (host successfully resolved), 1 on wait (meaning | ||
** try calling resolve() with the same hostname in a few hundred milliseconds | ||
** or so), or -1 on error (i.e. the host can't resolve). | ||
** 3. call reverse() to do reverse dns (ala resolve()). | ||
** 4. enjoy. | ||
*/ | ||
|
||
#ifndef _ASYNCDNS_H_ | ||
#define _ASYNCDNS_H_ | ||
|
||
class JNL_AsyncDNS | ||
{ | ||
public: | ||
JNL_AsyncDNS(int max_cache_entries=64); | ||
~JNL_AsyncDNS(); | ||
|
||
int resolve(char *hostname, unsigned long *addr); // return 0 on success, 1 on wait, -1 on unresolvable | ||
int reverse(unsigned long addr, char *hostname); // return 0 on success, 1 on wait, -1 on unresolvable. hostname must be at least 256 bytes. | ||
|
||
private: | ||
typedef struct | ||
{ | ||
int last_used; // timestamp. | ||
char resolved; | ||
char mode; // 1=reverse | ||
char hostname[256]; | ||
unsigned long addr; | ||
} | ||
cache_entry; | ||
|
||
cache_entry *m_cache; | ||
int m_cache_size; | ||
volatile int m_thread_kill; | ||
#ifdef _WIN32 | ||
HANDLE m_thread; | ||
static unsigned long WINAPI _threadfunc(LPVOID _d); | ||
#else | ||
pthread_t m_thread; | ||
static unsigned int _threadfunc(void *_d); | ||
#endif | ||
void makesurethreadisrunning(void); | ||
|
||
}; | ||
|
||
#endif //_ASYNCDNS_H_ |