network.h 1.7 KB
Newer Older
1
/*
2
 * Copyright (c) 2007 The FFmpeg Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

21 22
#ifndef AVFORMAT_NETWORK_H
#define AVFORMAT_NETWORK_H
23

24 25
#include "config.h"

26
#if HAVE_WINSOCK2_H
27 28 29 30 31 32 33
#include <winsock2.h>
#include <ws2tcpip.h>

#define ff_neterrno() WSAGetLastError()
#define FF_NETERROR(err) WSA##err
#define WSAEAGAIN WSAEWOULDBLOCK
#else
34 35 36 37 38
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

39 40
#define ff_neterrno() errno
#define FF_NETERROR(err) err
41 42
#endif

43
#if HAVE_ARPA_INET_H
44 45
#include <arpa/inet.h>
#endif
46

47 48
int ff_socket_nonblock(int socket, int enable);

49 50
static inline int ff_network_init(void)
{
51
#if HAVE_WINSOCK2_H
52 53 54 55 56 57 58 59 60
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(1,1), &wsaData))
        return 0;
#endif
    return 1;
}

static inline void ff_network_close(void)
{
61
#if HAVE_WINSOCK2_H
62 63 64 65
    WSACleanup();
#endif
}

66
#if !HAVE_INET_ATON
67 68 69 70
/* in os_support.c */
int inet_aton (const char * str, struct in_addr * add);
#endif

71
#endif /* AVFORMAT_NETWORK_H */