xref: /third_party/ltp/include/safe_net_fn.h (revision f08c3bdf)
1/*
2 * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
3 * 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
7 * the Free Software Foundation, either version 2 of the License, or
8 * (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
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef SAFE_NET_FN_H__
20#define SAFE_NET_FN_H__
21
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
28int safe_socket(const char *file, const int lineno, void (cleanup_fn)(void),
29		int domain, int type, int protocol);
30
31int safe_socketpair(const char *file, const int lineno, int domain, int type,
32		    int protocol, int sv[]);
33
34int safe_getsockopt(const char *file, const int lineno, int sockfd, int level,
35		    int optname, void *optval, socklen_t *optlen);
36
37int safe_setsockopt(const char *file, const int lineno, int sockfd, int level,
38		    int optname, const void *optval, socklen_t optlen);
39
40ssize_t safe_send(const char *file, const int lineno, char len_strict,
41		  int sockfd, const void *buf, size_t len, int flags);
42
43ssize_t safe_sendto(const char *file, const int lineno, char len_strict,
44		    int sockfd, const void *buf, size_t len, int flags,
45		    const struct sockaddr *dest_addr, socklen_t addrlen);
46
47ssize_t safe_sendmsg(const char *file, const int lineno, size_t msg_len,
48		  int sockfd, const struct msghdr *msg, int flags);
49
50ssize_t safe_recv(const char *file, const int lineno, size_t len,
51	int sockfd, void *buf, size_t size, int flags);
52
53ssize_t safe_recvmsg(const char *file, const int lineno, size_t msg_len,
54		  int sockfd, struct msghdr *msg, int flags);
55
56int safe_bind(const char *file, const int lineno, void (cleanup_fn)(void),
57	      int socket, const struct sockaddr *address,
58	      socklen_t address_len);
59
60int safe_listen(const char *file, const int lineno, void (cleanup_fn)(void),
61		int socket, int backlog);
62
63int safe_accept(const char *file, const int lineno, void (cleanup_fn)(void),
64		int sockfd, struct sockaddr *addr, socklen_t *addrlen);
65
66int safe_connect(const char *file, const int lineno, void (cleanup_fn)(void),
67		 int sockfd, const struct sockaddr *addr, socklen_t addrlen);
68
69int safe_getsockname(const char *file, const int lineno,
70		     void (cleanup_fn)(void), int sockfd, struct sockaddr *addr,
71		     socklen_t *addrlen);
72
73int safe_gethostname(const char *file, const int lineno,
74		     char *name, size_t size);
75
76int safe_sethostname(const char *file, const int lineno,
77		     const char *name, size_t size);
78
79int tst_getsockport(const char *file, const int lineno, int sockfd);
80
81unsigned short tst_get_unused_port(const char *file, const int lineno,
82	      void (cleanup_fn)(void), unsigned short family, int type);
83
84char *tst_sock_addr(const struct sockaddr *sa, socklen_t salen, char *res,
85		    size_t len);
86
87#endif /* SAFE_NET_FN_H__ */
88