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