void DnsProxyListener::GetAddrInfoHandler::run() { if (DBG) { ALOGD("GetAddrInfoHandler, now for %s / %s", mHost, mService); } struct addrinfo* result = NULL; uint32_t rv = getaddrinfo(mHost, mService, mHints, &result); if (rv) { // getaddrinfo failed mClient->sendBinaryMsg(ResponseCode::DnsProxyOperationFailed, &rv, sizeof(rv)); } else { bool success = !mClient->sendCode(ResponseCode::DnsProxyQueryResult); struct addrinfo* ai = result; while (ai && success) { success = sendLenAndData(mClient, sizeof(struct addrinfo), ai) && sendLenAndData(mClient, ai->ai_addrlen, ai->ai_addr) && sendLenAndData(mClient, ai->ai_canonname ? strlen(ai->ai_canonname) + 1 : 0, ai->ai_canonname); ai = ai->ai_next; } success = success && sendLenAndData(mClient, 0, ""); if (!success) { ALOGW("Error writing DNS result to client"); } } if (result) { freeaddrinfo(result); } mClient->decRef(); }
void DnsProxyListener::GetAddrInfoHandler::run() { if (DBG) { ALOGD("GetAddrInfoHandler, now for %s / %s / %s", mHost, mService, mIface); } char tmp[IF_NAMESIZE + 1]; int mark = mMark; if (mIface == NULL) { //fall back to the per uid interface if no per pid interface exists if(!_resolv_get_pids_associated_interface(mPid, tmp, sizeof(tmp))) if(!_resolv_get_uids_associated_interface(mUid, tmp, sizeof(tmp))) mark = -1; // if we don't have a targeted iface don't use a mark } struct addrinfo* result = NULL; uint32_t rv = android_getaddrinfoforiface(mHost, mService, mHints, mIface ? mIface : tmp, mark, &result); if (rv) { // getaddrinfo failed mClient->sendBinaryMsg(ResponseCode::DnsProxyOperationFailed, &rv, sizeof(rv)); } else { bool success = !mClient->sendCode(ResponseCode::DnsProxyQueryResult); struct addrinfo* ai = result; while (ai && success) { success = sendLenAndData(mClient, sizeof(struct addrinfo), ai) && sendLenAndData(mClient, ai->ai_addrlen, ai->ai_addr) && sendLenAndData(mClient, ai->ai_canonname ? strlen(ai->ai_canonname) + 1 : 0, ai->ai_canonname); ai = ai->ai_next; } success = success && sendLenAndData(mClient, 0, ""); if (!success) { ALOGW("Error writing DNS result to client"); } } if (result) { freeaddrinfo(result); } mClient->decRef(); }
// Returns true on success static bool sendhostent(SocketClient *c, struct hostent *hp) { bool success = true; int i; if (hp->h_name != NULL) { success &= sendLenAndData(c, strlen(hp->h_name)+1, hp->h_name); } else { success &= sendLenAndData(c, 0, "") == 0; } for (i=0; hp->h_aliases[i] != NULL; i++) { success &= sendLenAndData(c, strlen(hp->h_aliases[i])+1, hp->h_aliases[i]); } success &= sendLenAndData(c, 0, ""); // null to indicate we're done uint32_t buf = htonl(hp->h_addrtype); success &= c->sendData(&buf, sizeof(buf)) == 0; buf = htonl(hp->h_length); success &= c->sendData(&buf, sizeof(buf)) == 0; for (i=0; hp->h_addr_list[i] != NULL; i++) { success &= sendLenAndData(c, 16, hp->h_addr_list[i]); } success &= sendLenAndData(c, 0, ""); // null to indicate we're done return success; }