blob: 75acf5ece6bda96b6dad962b3329c4ffb2a533b2 [file] [log] [blame]
Zeng Linggang370a3a42015-10-21 11:15:23 +08001/*
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +01002 * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
Zeng Linggang370a3a42015-10-21 11:15:23 +08003 * Copyright (c) 2015 Fujitsu Ltd.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +01007 * the Free Software Foundation, either version 2 of the License, or
Zeng Linggang370a3a42015-10-21 11:15:23 +08008 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010016 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Zeng Linggang370a3a42015-10-21 11:15:23 +080017 */
18
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010019#ifndef SAFE_NET_FN_H__
20#define SAFE_NET_FN_H__
Zeng Linggang370a3a42015-10-21 11:15:23 +080021
22#include <sys/types.h>
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26#include <sys/un.h>
27
28char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
29 size_t len);
30
31int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
32 int domain, int type, int protocol);
Zeng Linggang370a3a42015-10-21 11:15:23 +080033
Alexey Kodanev5c189fc2017-02-27 13:53:34 +030034int safe_setsockopt(const char *file, const int lineno, int sockfd, int level,
35 int optname, const void *optval, socklen_t optlen);
36
37ssize_t safe_send(const char *file, const int lineno, char len_strict,
38 int sockfd, const void *buf, size_t len, int flags);
39
40ssize_t safe_sendto(const char *file, const int lineno, char len_strict,
41 int sockfd, const void *buf, size_t len, int flags,
42 const struct sockaddr *dest_addr, socklen_t addrlen);
43
Zeng Linggang370a3a42015-10-21 11:15:23 +080044int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
45 int socket, const struct sockaddr *address,
46 socklen_t address_len);
Zeng Linggang370a3a42015-10-21 11:15:23 +080047
48int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
49 int socket, int backlog);
Zeng Linggang370a3a42015-10-21 11:15:23 +080050
51int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
52 int sockfd, const struct sockaddr *addr, socklen_t addrlen);
Zeng Linggang370a3a42015-10-21 11:15:23 +080053
54int safe_getsockname(const char *file, const int lineno,
55 void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
56 socklen_t *addrlen);
Zeng Linggang370a3a42015-10-21 11:15:23 +080057
Alexey Kodanev5065a9e2016-06-16 13:14:52 +030058int safe_gethostname(const char *file, const int lineno,
59 char *name, size_t size);
60
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010061#endif /* SAFE_NET_FN_H__ */