blob: b76cdab91c8413926f2b7ec0c1bfe1ca95164116 [file] [log] [blame]
Marton Balint45fa7562018-09-12 22:46:091/*
2 * IP common code
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with FFmpeg; if not, write to the Free Software * Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef AVFORMAT_IP_H
22#define AVFORMAT_IP_H
23
24#include "network.h"
25
26/**
27 * Structure for storing IP (UDP) source filters or block lists.
28 */
29typedef struct IPSourceFilters {
30 int nb_include_addrs;
31 int nb_exclude_addrs;
32 struct sockaddr_storage *include_addrs;
33 struct sockaddr_storage *exclude_addrs;
34} IPSourceFilters;
35
36/**
37 * Checks the source address against a given IP source filter.
38 * @return 0 if packet should be processed based on the filter, 1 if the packet
39 * can be dropped.
40 */
41int ff_ip_check_source_lists(struct sockaddr_storage *source_addr_ptr, IPSourceFilters *s);
42
43/**
44 * Resolves hostname into an addrinfo structure.
45 * @return addrinfo structure which should be freed by the user, NULL in case
46 * of error.
47 */
48struct addrinfo *ff_ip_resolve_host(void *log_ctx,
49 const char *hostname, int port,
50 int type, int family, int flags);
51
52/**
53 * Parses the address[,address] source list in buf and adds it to the filters
54 * in the IPSourceFilters structure.
55 * @return 0 on success, < 0 AVERROR code on error.
56 */
57int ff_ip_parse_sources(void *log_ctx, const char *buf, IPSourceFilters *filters);
58
59/**
60 * Parses the address[,address] source block list in buf and adds it to the
61 * filters in the IPSourceFilters structure.
62 * @return 0 on success, < 0 AVERROR code on error.
63 */
64int ff_ip_parse_blocks(void *log_ctx, const char *buf, IPSourceFilters *filters);
65
66/**
67 * Resets the IP filter list and frees the internal fields of an
68 * IPSourceFilters structure.
69 */
70void ff_ip_reset_filters(IPSourceFilters *filters);
71
72#endif /* AVFORMAT_IP_H */