static void next_lookup(struct host_query *hquery) { int status; const char *p; struct hostent *host; for (p = hquery->remaining_lookups; *p; p++) { switch (*p) { case 'b': /* DNS lookup */ hquery->remaining_lookups = p + 1; ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback, hquery); return; case 'f': /* Host file lookup */ status = file_lookup(hquery->name, &host); if (status != ARES_ENOTFOUND) { end_hquery(hquery, status, host); return; } break; } } end_hquery(hquery, ARES_ENOTFOUND, NULL); }
static void next_lookup(struct addr_query *aquery) { const char *p; char name[128]; int status; struct hostent *host; for (p = aquery->remaining_lookups; *p; p++) { switch (*p) { case 'b': ptr_rr_name(name, &aquery->addr); aquery->remaining_lookups = p + 1; ares_query(aquery->channel, name, C_IN, T_PTR, addr_callback, aquery); return; case 'f': status = file_lookup(&aquery->addr, &host); /* this status check below previously checked for !ARES_ENOTFOUND, but we should not assume that this single error code is the one that can occur, as that is in fact no longer the case */ if (status == ARES_SUCCESS) { end_aquery(aquery, status, host); return; } break; } } end_aquery(aquery, ARES_ENOTFOUND, NULL); }
/* This is an API method */ int ares_gethostbyname_file(ares_channel channel, const char *name, int family, struct hostent **host) { int result; /* We only take the channel to ensure that ares_init() been called. */ if(channel == NULL) { /* Anything will do, really. This seems fine, and is consistent with other error cases. */ *host = NULL; return ARES_ENOTFOUND; } /* Just chain to the internal implementation we use here; it's exactly * what we want. */ result = file_lookup(name, family, host); if(result != ARES_SUCCESS) { /* We guarantee a NULL hostent on failure. */ *host = NULL; } return result; }
static void next_lookup(struct host_query *hquery, int status_code) { const char *p; struct hostent *host; int status = status_code; for (p = hquery->remaining_lookups; *p; p++) { switch (*p) { case 'b': /* DNS lookup */ hquery->remaining_lookups = p + 1; if ((hquery->want_family == AF_INET6) || (hquery->want_family == AF_UNSPEC)) { /* if inet6 or unspec, start out with AAAA */ hquery->sent_family = AF_INET6; ares_search(hquery->channel, hquery->name, C_IN, T_AAAA, host_callback, hquery); } else { hquery->sent_family = AF_INET; ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback, hquery); } return; case 'f': /* Host file lookup */ status = file_lookup(hquery->name, hquery->want_family, &host); /* this status check below previously checked for !ARES_ENOTFOUND, but we should not assume that this single error code is the one that can occur, as that is in fact no longer the case */ if (status == ARES_SUCCESS) { end_hquery(hquery, status, host); return; } status = status_code; /* Use original status code */ break; } } end_hquery(hquery, status, NULL); }
int hostfile_lookup(const char *name, struct hostent **host) { return file_lookup(name, host); }
/*Makes sure that all ports to the underlying filesystem of `node` are up to date*/ error_t node_update (node_t * node) { error_t err = 0; /*The full path to this node */ char *path; /*Stat information for `node` */ io_statbuf_t stat; /*The port to the file corresponding to `node` */ file_t port; /*If the specified node is the root node or if it must not be updated */ if (NODE_IS_ROOT (node) || (node->nn->flags & FLAG_NODE_ULFS_FIXED)) /*do nothing */ return err; /*return 0; actually */ /*Gain exclusive access to the root node of the filesystem */ mutex_lock (&netfs_root_node->lock); /*Construct the full path to `node` */ err = lnode_path_construct (node->nn->lnode, &path); if (err) { mutex_unlock (&netfs_root_node->lock); return err; } /*Deallocate `node`'s port to the underlying filesystem */ if (node->nn->port) PORT_DEALLOC (node->nn->port); /*Try to lookup the file for `node` in its untranslated version */ err = file_lookup (netfs_root_node->nn->port, path, O_READ | O_NOTRANS, O_NOTRANS, 0, &port, &stat); if (err) { node->nn->port = MACH_PORT_NULL; err = 0; /*failure (?) */ return err; } /*If the node looked up is actually the root node of the proxy filesystem */ if ((stat.st_ino == underlying_node_stat.st_ino) && (stat.st_fsid == underlying_node_stat.st_fsid)) /*set `err` accordingly */ err = ELOOP; else { /*deallocate the obtained port */ PORT_DEALLOC (port); /*obtain the translated version of the required node */ err = file_lookup (netfs_root_node->nn->port, path, O_READ, 0, 0, &port, &stat); } /*If there have been errors */ if (err) /*reset the port */ port = MACH_PORT_NULL; /*Store the port in the node */ node->nn->port = port; /*Remove the flag about the invalidity of the current node and set the flag that the node is up-to-date */ node->nn->flags &= ~FLAG_NODE_INVALIDATE; node->nn->flags |= FLAG_NODE_ULFS_UPTODATE; /*Release the lock on the root node of proxy filesystem */ mutex_unlock (&netfs_root_node->lock); /*Return the result of operations */ return err; } /*node_update */