/* * Composes "<host> login: "******"login: "******"login: "******"%s %s", host, dflt_prompt); return prompt; }
/* * This is called for the -h option, initializes cxt->{hostname,hostaddress}. */ static void init_remote_info(struct login_context *cxt, char *remotehost) { const char *domain; char *p; struct addrinfo hints, *info = NULL; cxt->remote = 1; get_thishost(cxt, &domain); if (domain && (p = strchr(remotehost, '.')) && strcasecmp(p + 1, domain) == 0) *p = '\0'; cxt->hostname = xstrdup(remotehost); memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_ADDRCONFIG; cxt->hostaddress[0] = 0; if (getaddrinfo(cxt->hostname, NULL, &hints, &info) == 0 && info) { if (info->ai_family == AF_INET) { struct sockaddr_in *sa = (struct sockaddr_in *) info->ai_addr; memcpy(cxt->hostaddress, &(sa->sin_addr), sizeof(sa->sin_addr)); } else if (info->ai_family == AF_INET6) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *) info->ai_addr; #ifdef IN6_IS_ADDR_V4MAPPED if (IN6_IS_ADDR_V4MAPPED(&sa->sin6_addr)) { const uint8_t *bytes = sa->sin6_addr.s6_addr; struct in_addr addr = { *(const in_addr_t *) (bytes + 12) }; memcpy(cxt->hostaddress, &addr, sizeof(struct in_addr)); } else #endif memcpy(cxt->hostaddress, &(sa->sin6_addr), sizeof(sa->sin6_addr)); } freeaddrinfo(info); } }
/* * Composes "<host> login: "******"login: "******"login: "******"LOGIN_PLAIN_PROMPT", 0) == 1) return dflt_prompt; if (!(host = get_thishost(cxt, NULL))) return dflt_prompt; sz = strlen(host) + 1 + strlen(dflt_prompt) + 1; prompt = xmalloc(sz); snprintf(prompt, sz, "%s %s", host, dflt_prompt); return prompt; }