147{
148 int rc;
149
150 char *host_idna = NULL;
151
152#ifdef HAVE_GETADDRINFO
153
154
155
156 char port[6] = { 0 };
157 struct addrinfo hints = { 0 };
158 struct addrinfo *res = NULL;
159 struct addrinfo *cur = NULL;
160
161
163 if (c_use_ipv6)
164 hints.ai_family = AF_UNSPEC;
165 else
166 hints.ai_family = AF_INET;
167
168 hints.ai_socktype = SOCK_STREAM;
169
170 snprintf(port,
sizeof(port),
"%d", conn->
account.
port);
171
172#ifdef HAVE_LIBIDN
174 {
176 return -1;
177 }
178#else
180#endif
181
184
185 rc = getaddrinfo(host_idna, port, &hints, &res);
186
187#ifdef HAVE_LIBIDN
189#endif
190
191 if (rc)
192 {
194 return -1;
195 }
196
199
200 rc = -1;
201 for (cur = res; cur; cur = cur->ai_next)
202 {
203 int fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
204 if (fd >= 0)
205 {
207 if (rc == 0)
208 {
209 (void) fcntl(fd, F_SETFD, FD_CLOEXEC);
211 break;
212 }
213 else
214 {
215 close(fd);
216 }
217 }
218 }
219
220 freeaddrinfo(res);
221#else
222
223
224 struct hostent *he = NULL;
225 struct sockaddr_in sin = { 0 };
227 sin.sin_family = AF_INET;
228
229#ifdef HAVE_LIBIDN
231 {
233 return -1;
234 }
235#else
237#endif
238
241
242 he = gethostbyname(host_idna);
243
244#ifdef HAVE_LIBIDN
246#endif
247
248 if (!he)
249 {
251
252 return -1;
253 }
254
257
258 rc = -1;
259 for (int i = 0; he->h_addr_list[i]; i++)
260 {
261 memcpy(&sin.sin_addr, he->h_addr_list[i], he->h_length);
262 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_IP);
263
264 if (fd >= 0)
265 {
267 if (rc == 0)
268 {
269 fcntl(fd, F_SETFD, FD_CLOEXEC);
271 break;
272 }
273 else
274 {
275 close(fd);
276 }
277 }
278 }
279#endif
280 if (rc)
281 {
283 (rc > 0) ? strerror(rc) :
_(
"unknown error"));
284 return -1;
285 }
286
287 return 0;
288}
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.