1 /* $Id$ */
2 /* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Mailer */
4 /* This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16
17
18 #include <netdb.h>
19
20
21 /* prototypes */
22 static int _common_lookup(char const * hostname, uint16_t port,
23 struct addrinfo ** ai);
24
25
26 /* functions */
27 /* common_lookup */
_common_lookup(char const * hostname,uint16_t port,struct addrinfo ** ai)28 static int _common_lookup(char const * hostname, uint16_t port,
29 struct addrinfo ** ai)
30 {
31 struct addrinfo hints;
32 int res;
33
34 if(hostname == NULL)
35 return -error_set_code(1, "%s", strerror(errno));
36 memset(&hints, 0, sizeof(hints));
37 hints.ai_family = AF_UNSPEC;
38 hints.ai_socktype = SOCK_STREAM;
39 hints.ai_protocol = IPPROTO_TCP;
40 if((res = getaddrinfo(hostname, NULL, &hints, ai)) != 0)
41 return -error_set_code(1, "%s", gai_strerror(res));
42 return 0;
43 }
44