149{
150 int rc;
151
152 char *host_idna = NULL;
153
154#ifdef HAVE_GETADDRINFO
155
156
157
158 char port[6] = { 0 };
159 struct addrinfo hints = { 0 };
160 struct addrinfo *res = NULL;
161 struct addrinfo *cur = NULL;
162
163
165 if (c_use_ipv6)
166 hints.ai_family = AF_UNSPEC;
167 else
168 hints.ai_family = AF_INET;
169
170 hints.ai_socktype = SOCK_STREAM;
171
172 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
173
174#ifdef HAVE_LIBIDN
176 {
178 return -1;
179 }
180#else
182#endif
183
186
187 rc = getaddrinfo(host_idna, port, &hints, &res);
188
189#ifdef HAVE_LIBIDN
191#endif
192
193 if (rc)
194 {
196 return -1;
197 }
198
201
202 rc = -1;
203 for (cur = res; cur; cur = cur->ai_next)
204 {
205 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
206 if (fd >= 0)
207 {
209 if (rc == 0)
210 {
211 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
213 break;
214 }
215 else
216 {
217 close(fd);
218 }
219 }
220 }
221
222 freeaddrinfo(res);
223#else
224
225
226 struct hostent *he = NULL;
227 struct sockaddr_in sin = { 0 };
229 sin.sin_family = AF_INET;
230
231#ifdef HAVE_LIBIDN
233 {
235 return -1;
236 }
237#else
239#endif
240
243
244 he = gethostbyname(host_idna);
245
246#ifdef HAVE_LIBIDN
248#endif
249
250 if (!he)
251 {
253
254 return -1;
255 }
256
259
260 rc = -1;
261 for (int i = 0; he->h_addr_list[i]; i++)
262 {
263 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
264 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
265
266 if (fd >= 0)
267 {
269 if (rc == 0)
270 {
271 fcntl(fd, F_SETFD, FD_CLOEXEC);
273 break;
274 }
275 else
276 {
277 close(fd);
278 }
279 }
280 }
281#endif
282 if (rc)
283 {
285 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
286 return -1;
287 }
288
289 return 0;
290}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
bool OptNoCurses
(pseudo) when sending in batch mode
#define mutt_message(...)
int mutt_idna_to_ascii_lz(const char *input, char **output, uint8_t flags)
Convert a domain to Punycode.
static int socket_connect(int fd, struct sockaddr *sa)
Set up to connect to a socket fd.
char host[128]
Server to login to.
unsigned short port
Port to connect to.
struct ConnAccount account
Account details: username, password, etc.
int fd
Socket file descriptor.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.