1 /*
2 Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
3 file at the top-level directory of this distribution.
4
5 Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 option. This file may not be copied, modified, or distributed
9 except according to those terms.
10 */
11 #include "sock.h"
12
13 #include <stdio.h>
14 #include <string.h>
15
sock_init(enum sock_type sock_t,const char * addr_str,enum ip_addr_type ip_t,void * servaddr,size_t servaddr_len,int * sockfd)16 int sock_init(enum sock_type sock_t, const char *addr_str,
17 enum ip_addr_type ip_t, void *servaddr, size_t servaddr_len,
18 int *sockfd)
19 {
20 int r;
21 if (ip_t == IPv4) {
22 r = ipv4_sock_init(sock_t, addr_str,
23 (struct sockaddr_in *)servaddr, servaddr_len,
24 sockfd);
25 if (r < 0)
26 return r;
27 } else {
28 r = ipv6_sock_init(sock_t, addr_str,
29 (struct sockaddr_in6 *)servaddr,
30 servaddr_len, sockfd);
31 if (r < 0)
32 return r;
33 }
34 return 0;
35 }
36