130{
131 int rc;
132
133 char *host_idna = NULL;
134
135#ifdef HAVE_GETADDRINFO
136
137
138
139 char port[6] = { 0 };
140 struct addrinfo hints;
141 struct addrinfo *res = NULL;
142 struct addrinfo *cur = NULL;
143
144
145 memset(&hints, 0, sizeof(hints));
146
148 if (c_use_ipv6)
149 hints.ai_family = AF_UNSPEC;
150 else
151 hints.ai_family = AF_INET;
152
153 hints.ai_socktype = SOCK_STREAM;
154
155 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
156
157#ifdef HAVE_LIBIDN
159 {
161 return -1;
162 }
163#else
165#endif
166
169
170 rc = getaddrinfo(host_idna, port, &hints, &res);
171
172#ifdef HAVE_LIBIDN
174#endif
175
176 if (rc)
177 {
179 return -1;
180 }
181
184
185 rc = -1;
186 for (cur = res; cur; cur = cur->ai_next)
187 {
188 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
189 if (fd >= 0)
190 {
192 if (rc == 0)
193 {
194 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
196 break;
197 }
198 else
199 {
200 close(fd);
201 }
202 }
203 }
204
205 freeaddrinfo(res);
206#else
207
208
209 struct sockaddr_in sin;
210 struct hostent *he = NULL;
211
212 memset(&sin, 0, sizeof(sin));
214 sin.sin_family = AF_INET;
215
216#ifdef HAVE_LIBIDN
218 {
220 return -1;
221 }
222#else
224#endif
225
228
229 he = gethostbyname(host_idna);
230
231#ifdef HAVE_LIBIDN
233#endif
234
235 if (!he)
236 {
238
239 return -1;
240 }
241
244
245 rc = -1;
246 for (int i = 0; he->h_addr_list[i]; i++)
247 {
248 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
249 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
250
251 if (fd >= 0)
252 {
254 if (rc == 0)
255 {
256 fcntl(fd, F_SETFD, FD_CLOEXEC);
258 break;
259 }
260 else
261 {
262 close(fd);
263 }
264 }
265 }
266#endif
267 if (rc)
268 {
270 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
271 return -1;
272 }
273
274 return 0;
275}
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.