148{
149 int rc;
150
151 char *host_idna = NULL;
152
153#ifdef HAVE_GETADDRINFO
154
155
156
157 char port[6] = { 0 };
158 struct addrinfo hints = { 0 };
159 struct addrinfo *res = NULL;
160 struct addrinfo *cur = NULL;
161
162
164 if (c_use_ipv6)
165 hints.ai_family = AF_UNSPEC;
166 else
167 hints.ai_family = AF_INET;
168
169 hints.ai_socktype = SOCK_STREAM;
170
171 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
172
173#ifdef HAVE_LIBIDN
175 {
177 return -1;
178 }
179#else
181#endif
182
185
186 rc = getaddrinfo(host_idna, port, &hints, &res);
187
188#ifdef HAVE_LIBIDN
190#endif
191
192 if (rc)
193 {
195 return -1;
196 }
197
200
201 rc = -1;
202 for (cur = res; cur; cur = cur->ai_next)
203 {
204 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
205 if (fd >= 0)
206 {
208 if (rc == 0)
209 {
210 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
212 break;
213 }
214 else
215 {
216 close(fd);
217 }
218 }
219 }
220
221 freeaddrinfo(res);
222#else
223
224
225 struct hostent *he = NULL;
226 struct sockaddr_in sin = { 0 };
228 sin.sin_family = AF_INET;
229
230#ifdef HAVE_LIBIDN
232 {
234 return -1;
235 }
236#else
238#endif
239
242
243 he = gethostbyname(host_idna);
244
245#ifdef HAVE_LIBIDN
247#endif
248
249 if (!he)
250 {
252
253 return -1;
254 }
255
258
259 rc = -1;
260 for (int i = 0; he->h_addr_list[i]; i++)
261 {
262 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
263 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
264
265 if (fd >= 0)
266 {
268 if (rc == 0)
269 {
270 fcntl(fd, F_SETFD, FD_CLOEXEC);
272 break;
273 }
274 else
275 {
276 close(fd);
277 }
278 }
279 }
280#endif
281 if (rc)
282 {
284 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
285 return -1;
286 }
287
288 return 0;
289}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
bool OptGui
(pseudo) when the gui (and curses) are started
#define mutt_message(...)
int mutt_idna_to_ascii_lz(const char *input, char **output, uint8_t flags)
Convert a domain to Punycode.
#define FREE(x)
Free memory and set the pointer to NULL.
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.