-/*
- c-ares beim connect zum nameserver: if (channel->sock_create_cb)
-
- SOCK_STATE_CALLBACK(channel, s, 1, 0); -> void Channel::SockStateCb(void *data, int sock, int read, int write) {
-
-
-
-lesen der antwort:
-#0 node::Channel::QueryCb (arg=0x8579268, status=0x0, timeouts=0x0, abuf=0xbffff0ef "\356|\201\200", alen=0x48) at ../src/node_cares.cc:453
-#1 0x08181884 in qcallback (arg=0x8579278, status=0x857b5a0, timeouts=0x0, abuf=0xbffff0ef "\356|\201\200", alen=0x48) at ../deps/c-ares/ares_query.c:180
-#2 0x0817fbf5 in end_query (channel=<value optimized out>, query=0x85790b0, status=0x1, abuf=0xbffff0ef "\356|\201\200", alen=0x48) at ../deps/c-ares/ares_process.c:1233
-#3 0x08180898 in process_answer (channel=<value optimized out>, abuf=<value optimized out>, alen=<value optimized out>, whichserver=0x0, tcp=0x0, now=0xbffff388) at ../deps/c-ares/ares_process.c:612
-#4 0x08180cf8 in read_udp_packets (channel=<value optimized out>, read_fds=<value optimized out>, read_fd=<value optimized out>, now=0xbffff388) at ../deps/c-ares/ares_process.c:498
-#5 0x08181021 in processfds (channel=0x85a9888, read_fds=<value optimized out>, read_fd=<value optimized out>, write_fds=0x0, write_fd=0xffffffff) at ../deps/c-ares/ares_process.c:153
-
-->
-static void ParseAnswerMX(QueryArg *arg, unsigned char* abuf, int alen) {
- HandleScope scope;
-
-
-
- */
-
-/*
-
-static Local<Array> HostEntToAddresses(struct hostent* hostent) {
- Local<Array> addresses = Array::New();
-
-
- char ip[INET6_ADDRSTRLEN];
- for (int i = 0; hostent->h_addr_list[i]; ++i) {
- inet_ntop(hostent->h_addrtype, hostent->h_addr_list[i], ip, sizeof(ip));
-
- Local<String> address = String::New(ip);
- addresses->Set(Integer::New(i), address);
- }
-
- return addresses;
-}
-
-
-static Local<Array> HostEntToNames(struct hostent* hostent) {
- Local<Array> names = Array::New();
-
- for (int i = 0; hostent->h_aliases[i]; ++i) {
- Local<String> address = String::New(hostent->h_aliases[i]);
- names->Set(Integer::New(i), address);
- }
-
- return names;
-}
-
-static inline const char *ares_errno_string(int errorno) {
-#define ERRNO_CASE(e) case ARES_##e: return #e;
- switch (errorno) {
- ERRNO_CASE(SUCCESS)
- ERRNO_CASE(ENODATA)
- ERRNO_CASE(EFORMERR)
- ERRNO_CASE(ESERVFAIL)
- ERRNO_CASE(ENOTFOUND)
- ERRNO_CASE(ENOTIMP)
- ERRNO_CASE(EREFUSED)
- ERRNO_CASE(EBADQUERY)
- ERRNO_CASE(EBADNAME)
- ERRNO_CASE(EBADFAMILY)
- ERRNO_CASE(EBADRESP)
- ERRNO_CASE(ECONNREFUSED)
- ERRNO_CASE(ETIMEOUT)
- ERRNO_CASE(EOF)
- ERRNO_CASE(EFILE)
- ERRNO_CASE(ENOMEM)
- ERRNO_CASE(EDESTRUCTION)
- ERRNO_CASE(EBADSTR)
- ERRNO_CASE(EBADFLAGS)
- ERRNO_CASE(ENONAME)
- ERRNO_CASE(EBADHINTS)
- ERRNO_CASE(ENOTINITIALIZED)
- ERRNO_CASE(ELOADIPHLPAPI)
- ERRNO_CASE(EADDRGETNETWORKPARAMS)
- ERRNO_CASE(ECANCELLED)
- default:
- assert(0 && "Unhandled c-ares errno");
- return "(UNKNOWN)";
- }
-}
-
-
-static void ResolveError(Persistent<Function> &cb, int status) {
- HandleScope scope;
-
- Local<String> code = String::NewSymbol(ares_errno_string(status));
- Local<String> message = String::NewSymbol(ares_strerror(status));
-
- Local<String> cons1 = String::Concat(code, String::NewSymbol(", "));
- Local<String> cons2 = String::Concat(cons1, message);
-
- Local<Value> e = Exception::Error(cons2);
-
- Local<Object> obj = e->ToObject();
- obj->Set(String::NewSymbol("errno"), Integer::New(status));
-
- TryCatch try_catch;
-
- cb->Call(v8::Context::GetCurrent()->Global(), 1, &e);
-
- if (try_catch.HasCaught()) {
- FatalException(try_catch);
- }
-}
-
-static void HostByNameCb(void *data,
- int status,
- int timeouts,
- struct hostent *hostent) {
- HandleScope scope;
-
- Persistent<Function> *cb = cb_unwrap(data);
-
- if (status != ARES_SUCCESS) {
- ResolveError(*cb, status);
- cb_destroy(cb);
- return;
- }
-
- TryCatch try_catch;
-
- Local<Array> addresses = HostEntToAddresses(hostent);
-
- Local<Value> argv[2] = { Local<Value>::New(Null()), addresses};
-
- (*cb)->Call(v8::Context::GetCurrent()->Global(), 2, argv);
-
- if (try_catch.HasCaught()) {
- FatalException(try_catch);
- }
-
- cb_destroy(cb);
-}
-
-
-
-
-static void cb_call(Persistent<Function> &cb, int argc, Local<Value> *argv) {
- TryCatch try_catch;
-
- cb->Call(v8::Context::GetCurrent()->Global(), argc, argv);
-
- if (try_catch.HasCaught()) {
- FatalException(try_catch);
- }
-}
-
-Handle<Value> Channel::GetHostByAddr(const Arguments& args) {
- HandleScope scope;
- Channel *c = ObjectWrap::Unwrap<Channel>(args.Holder());
- assert(c);
-
- if (!args[0]->IsString()) {
- return ThrowException(Exception::Error(
- String::New("First argument must be a address")));
- }
-
- if (!args[1]->IsInt32()) {
- return ThrowException(Exception::Error(
- String::New("Second argument must be an address family")));
- }
-
- if (!args[2]->IsFunction()) {
- return ThrowException(Exception::Error(
- String::New("Third argument must be a callback")));
- }
-
- int family = args[1]->Int32Value();
- if (family != AF_INET6 && family != AF_INET) {
- return ThrowException(Exception::Error(
- String::New("Unsupported address family")));
- }
-
- String::Utf8Value address_s(args[0]->ToString());
-
- char address_b[sizeof(struct in6_addr)];
- int r = inet_pton(family, *address_s, address_b);
- if (r != 1) {
- return ThrowException(Exception::Error(
- String::New("Invalid network address")));
- }
-
- int length;
- if (family == AF_INET6)
- length = sizeof(struct in6_addr);
- else
- length = sizeof(struct in_addr);
-
- ares_gethostbyaddr(c->channel, address_b, length, family, HostByAddrCb, cb_persist(args[2]));
-
- return Undefined();
-}
-
-
-
-Handle<Value> Channel::GetHostByName(const Arguments& args) {
- HandleScope scope;
- Channel *c = ObjectWrap::Unwrap<Channel>(args.Holder());
- assert(c);
-
- if (!args[0]->IsString()) {
- return ThrowException(Exception::Error(
- String::New("First argument must be a name")));
- }
-
- if (!args[1]->IsInt32()) {
- return ThrowException(Exception::Error(
- String::New("Second argument must be a family")));
- }
-
- if (!args[2]->IsFunction()) {
- return ThrowException(Exception::Error(
- String::New("Third argument must be a callback")));
- }
-
- int family = args[1]->Int32Value();
- if (family != AF_INET6 && family != AF_INET) {
- return ThrowException(Exception::Error(
- String::New("Unsupported address family")));
- }
-
- String::Utf8Value name(args[0]->ToString());
-
- ares_gethostbyname(c->channel, *name, family, HostByNameCb, cb_persist(args[2]));
-
- return Undefined();
-}
-
-*/
-
-