libgpac
Documentation of the core library of GPAC
os_net.c File Reference
#include <gpac/network.h>
#include <gpac/utf.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <errno.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <gpac/bitstream.h>
#include <gpac/list.h>
#include <assert.h>
+ Include dependency graph for os_net.c:

Data Structures

struct  NetCapInfo
 
struct  GF_Socket
 abstracted socket object More...
 
struct  NetFilterRule
 
struct  GF_NetcapFilter
 
struct  GetIPInfo
 
struct  GF_SockGroup
 abstracted socket group object More...
 

Macros

#define INADDR_NONE   ((unsigned long)-1)
 
#define SOCKET_INVALID(_s)   (_s<0)
 
#define INVALID_SOCKET   -1
 
#define SOCKET_ERROR   -1
 
#define LASTSOCKERROR   errno
 
#define closesocket(v)   close(v)
 
#define my_inet_ntop   inet_ntop
 
#define SSO_CAST   (const char *)
 
#define GF_GPC_MAGIC   GF_4CC('G','P','C', 0)
 
#define SKIP_PCAP_PCK
 
#define sock_close(_s)
 
#define gf_gethostbyname   gethostbyname
 

Typedefs

typedef s32 SOCKET
 

Enumerations

enum  {
  GF_SOCK_IS_TCP = 1<<9 , GF_SOCK_IS_IPV6 = 1<<10 , GF_SOCK_NON_BLOCKING = 1<<11 , GF_SOCK_IS_MULTICAST = 1<<12 ,
  GF_SOCK_IS_LISTENING = 1<<13 , GF_SOCK_HAS_PEER = 1<<14 , GF_SOCK_IS_UN = 1<<15 , GF_SOCK_HAS_CONNECT = 1<<16
}
 
enum  {
  NETCAP_IS_MCAST = 1 , NETCAP_IS_TCP = 1<<1 , NETCAP_HAS_PEER = 1<<2 , NETCAP_IS_IPV6 = 1<<3 ,
  NETCAP_HAS_EXT = 1<<6 , NETCAP_DROP = 1<<7
}
 
enum  { NETCAP_NONE = 0 , NETCAP_GPAC = 1 , NETCAP_PCAP = 2 , NETCAP_PCAPNG = 3 }
 
enum  { PCAP_LT_LOOPBACK =0 , PCAP_LT_ETHERNET =1 , PCAP_LT_CHAOS =5 }
 

Functions

static GF_NetcapFilter * gf_net_filter_get (const char *id)
 
GF_EXPORT u32 gf_net_has_ipv6 ()
 gets ipv6 support More...
 
GF_EXPORT Bool gf_net_is_ipv6 (const char *address)
 checks address type More...
 
GF_EXPORT GF_Err gf_sk_get_host_name (char *buffer)
 get local host name More...
 
GF_EXPORT GF_Err gf_sk_get_local_ip (GF_Socket *sock, char *buffer)
 get local IP More...
 
GF_BitStream * gf_bs_from_fd (int fd, u32 mode)
 
void gf_net_close_capture ()
 
static GF_Err gf_netcap_record (GF_NetcapFilter *nf)
 
static void gf_netcap_load_pck_gpac (GF_NetcapFilter *nf)
 
static GF_Err pcapng_load_shb (GF_NetcapFilter *nf, Bool is_init)
 
static void pcapng_load_idb (GF_NetcapFilter *nf)
 
static void gf_netcap_load_pck_pcap (GF_NetcapFilter *nf)
 
static GF_Err gf_netcap_playback (GF_NetcapFilter *nf)
 
GF_Err gf_netcap_setup (char *rules)
 
static Bool netcap_filter_pck (GF_Socket *sock, u32 pck_len, Bool for_send)
 
static void gf_netcap_load_pck (GF_NetcapFilter *nf, u64 now)
 
static GF_Err gf_netcap_send_pcap (GF_NetcapFilter *nf, GF_Socket *sock, const u8 *buffer, u32 length, u32 *written, Bool is_ng)
 
static GF_Err gf_netcap_send_gpac (GF_NetcapFilter *nf, GF_Socket *sock, const u8 *buffer, u32 length, u32 *written)
 
static GF_Err gf_netcap_send (GF_Socket *sock, const u8 *buffer, u32 length, u32 *written)
 
Bool gf_sk_has_nrt_netcap (GF_Socket *sk)
 
GF_EXPORT GF_Socket * gf_sk_new_ex (u32 SocketType, const char *netcap_id)
 socket constructor More...
 
GF_EXPORT GF_Socket * gf_sk_new (u32 SocketType)
 socket constructor More...
 
GF_EXPORT GF_Err gf_sk_set_buffer_size (GF_Socket *sock, Bool SendBuffer, u32 NewSize)
 socket buffer size control More...
 
GF_EXPORT GF_Err gf_sk_set_block_mode (GF_Socket *sock, Bool NonBlockingOn)
 blocking mode control More...
 
static void gf_sk_free (GF_Socket *sock)
 
GF_EXPORT void gf_sk_del (GF_Socket *sock)
 socket destructor More...
 
GF_EXPORT void gf_sk_reset (GF_Socket *sock)
 reset internal buffer More...
 
GF_EXPORT s32 gf_sk_get_handle (GF_Socket *sock)
 gets socket handle More...
 
GF_EXPORT void gf_sk_set_usec_wait (GF_Socket *sock, u32 usec_wait)
 
static u32 inet_addr_from_name (const char *local_interface)
 
GF_EXPORT GF_Err gf_sk_connect (GF_Socket *sock, const char *PeerName, u16 PortNumber, const char *ifce_ip_or_name)
 connects a socket More...
 
GF_EXPORT GF_Err gf_sk_bind (GF_Socket *sock, const char *ifce_ip_or_name, u16 port, const char *peer_name, u16 peer_port, u32 options)
 socket binding More...
 
static GF_Err poll_select (GF_Socket *sock, GF_SockSelectMode mode, u32 usec, Bool force_select)
 
GF_EXPORT GF_Err gf_sk_send_ex (GF_Socket *sock, const u8 *buffer, u32 length, u32 *written)
 data emission More...
 
GF_EXPORT GF_Err gf_sk_send (GF_Socket *sock, const u8 *buffer, u32 length)
 data emission More...
 
GF_Err gf_sk_select (GF_Socket *sock, GF_SockSelectMode mode)
 
GF_EXPORT u32 gf_sk_is_multicast_address (const char *multi_IPAdd)
 multicast address test More...
 
static GF_Err sk_join_ipv4 (GF_Socket *sock, struct ip_mreq *M_req, u32 TTL, const char **src_ip_inc, u32 nb_src_ip_inc, const char **src_ip_exc, u32 nb_src_ip_exc)
 
GF_EXPORT Bool gf_net_enum_interfaces (gf_net_ifce_enum do_enum, void *enum_cbk)
 enumerate network interfaces More...
 
static Bool get_ifce_enum (void *cbk, const char *name, const char *IP, u32 flags)
 
Bool gf_net_get_adapter_ip (const char *ip_or_name, char **ipv4, char **ipv6)
 
GF_EXPORT GF_Err gf_sk_setup_multicast_ex (GF_Socket *sock, const char *multi_IPAdd, u16 MultiPortNumber, u32 TTL, Bool NoBind, const char *ifce_ip_or_name, const char **src_ip_inc, u32 nb_src_ip_inc, const char **src_ip_exc, u32 nb_src_ip_exc)
 source-specific multicast setup More...
 
GF_EXPORT GF_Err gf_sk_setup_multicast (GF_Socket *sock, const char *multi_IPAdd, u16 MultiPortNumber, u32 TTL, Bool NoBind, const char *ifce_ip_or_name)
 multicast setup More...
 
GF_SockGroup * gf_sk_group_new ()
 
void gf_sk_group_del (GF_SockGroup *sg)
 
void gf_sk_group_register (GF_SockGroup *sg, GF_Socket *sk)
 
void gf_sk_group_unregister (GF_SockGroup *sg, GF_Socket *sk)
 
GF_Err gf_sk_group_select (GF_SockGroup *sg, u32 usec_wait, GF_SockSelectMode mode)
 
Bool gf_sk_group_sock_is_set (GF_SockGroup *sg, GF_Socket *sk, GF_SockSelectMode mode)
 
GF_Err gf_sk_receive_internal (GF_Socket *sock, char *buffer, u32 length, u32 *BytesRead, Bool do_select)
 
GF_EXPORT GF_Err gf_sk_receive (GF_Socket *sock, u8 *buffer, u32 length, u32 *BytesRead)
 data reception More...
 
GF_EXPORT GF_Err gf_sk_receive_no_select (GF_Socket *sock, u8 *buffer, u32 length, u32 *BytesRead)
 
GF_EXPORT GF_Err gf_sk_listen (GF_Socket *sock, u32 MaxConnection)
 socket listening More...
 
GF_EXPORT GF_Err gf_sk_accept (GF_Socket *sock, GF_Socket **newConnection)
 socket accept More...
 
GF_EXPORT GF_Err gf_sk_get_local_info (GF_Socket *sock, u16 *Port, u32 *Familly)
 get local info More...
 
GF_EXPORT GF_Err gf_sk_server_mode (GF_Socket *sock, Bool serverOn)
 server socket mode More...
 
GF_EXPORT GF_Err gf_sk_get_remote_address_port (GF_Socket *sock, char *buf, u32 *port)
 get remote address More...
 
GF_EXPORT GF_Err gf_sk_get_remote_address (GF_Socket *sock, char *buf)
 get remote address More...
 
GF_EXPORT GF_Err gf_sk_probe (GF_Socket *sock)
 
GF_EXPORT char * gf_net_bump_ip_address (const char *in_ip, u32 increment)
 
GF_EXPORT u32 gf_htonl (u32 val)
 
GF_EXPORT u32 gf_ntohl (u32 val)
 
GF_EXPORT u16 gf_htons (u16 val)
 
GF_EXPORT u16 gf_ntohs (u16 val)
 
GF_EXPORT const char * gf_errno_str (int errnoval)
 error code description More...
 

Variables

u16 first_tcp_port =30000
 
static GF_List * netcap_filters =NULL
 
Bool gpac_use_poll =GF_TRUE
 

Data Structure Documentation

◆ NetCapInfo

struct NetCapInfo
Data Fields
u32 host_addr_v4
bin128 host_addr_v6
u32 host_port
u32 peer_addr_v4
bin128 peer_addr_v6
u32 peer_port
u32 pck_idx_r
u32 pck_idx_w
u32 next_pck_range
u32 next_rand
u32 patch_offset
u32 patch_val
GF_NetcapFilter * nf

◆ __tag_socket

struct __tag_socket

The abstracted socket object allows you to build client and server applications very simply with support for unicast and multicast Available tools are socket and socket groups and some helper functions for network time

+ Collaboration diagram for GF_Socket:
Data Fields
u32 flags
SOCKET socket
struct sockaddr_in dest_addr
u32 dest_addr_len
u32 usec_wait
NetCapInfo * cap_info

◆ NetFilterRule

struct NetFilterRule
Data Fields
u32 send_recv
u32 pck_start
u32 pck_end
s32 rand_every
u32 nb_pck
u32 port
s32 patch_offset
s32 patch_val
s32 delay

◆ __netcap_filter

struct __netcap_filter
Data Fields
char * id
char * src
char * dst
s32 loops
Bool rt
GF_List * rules
u32 nb_rules
GF_BitStream * cap_bs
GF_List * read_socks
GF_Socket * read_sock_selected
FILE * file
int fd
u64 init_time
Bool is_eos
u64 pck_start_offset
s32 pck_len
u8 pck_flags
u64 pck_time
u16 dst_port
u32 dst_v4
bin128 dst_v6
u16 src_port
u32 src_v4
bin128 src_v6
u32 cap_mode
Bool pcap_le
Bool pcap_nano
u32 pcap_num_interfaces
u32 link_types[20]
u32 pcapng_trail
u32 pcap_trail
u32 pck_idx_r
u32 pck_idx_w
u32 next_pck_range
u32 next_rand
u32 reorder_max_pck
u32 reorder_nb_pck
u32 delay_nb_pck
u64 reorder_seek_pos
u64 reorder_resume_pos

◆ GetIPInfo

struct GetIPInfo
Data Fields
const char * ip_or_name
char * res_v6
char * res_v4

◆ __tag_sock_group

struct __tag_sock_group

The abstracted socket group object allows querying multiple sockets in a group

Data Fields
GF_List * sockets
fd_set rgroup
fd_set wgroup
u32 nb_nfs
u32 nb_socks

Macro Definition Documentation

◆ INADDR_NONE

#define INADDR_NONE   ((unsigned long)-1)

◆ SOCKET_INVALID

#define SOCKET_INVALID (   _s)    (_s<0)

◆ INVALID_SOCKET

#define INVALID_SOCKET   -1

◆ SOCKET_ERROR

#define SOCKET_ERROR   -1

◆ LASTSOCKERROR

#define LASTSOCKERROR   errno

◆ closesocket

#define closesocket (   v)    close(v)

◆ my_inet_ntop

#define my_inet_ntop   inet_ntop

◆ SSO_CAST

#define SSO_CAST   (const char *)

◆ GF_GPC_MAGIC

#define GF_GPC_MAGIC   GF_4CC('G','P','C', 0)

◆ SKIP_PCAP_PCK

#define SKIP_PCAP_PCK
Value:
if (clen<0) {\
GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[NetCap] Corrupted PCAP file, aborting\n"));\
nf->is_eos = GF_TRUE;\
return;\
}\
gf_bs_skip_bytes(nf->cap_bs, clen);\
clen=0;\
goto refetch_pcap;
@ GF_LOG_NETWORK
Definition: tools.h:782
@ GF_LOG_ERROR
Definition: tools.h:741
@ GF_TRUE
Definition: setup.h:474

◆ sock_close

#define sock_close (   _s)
Value:
closesocket(_s->socket);\
_s->socket = INVALID_SOCKET;\
if (_s->cap_info) _s->cap_info->host_port = 0; \
#define INVALID_SOCKET
Definition: os_net.c:146
#define closesocket(v)
Definition: os_net.c:152

◆ gf_gethostbyname

#define gf_gethostbyname   gethostbyname

Typedef Documentation

◆ SOCKET

typedef s32 SOCKET

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GF_SOCK_IS_TCP 
GF_SOCK_IS_IPV6 
GF_SOCK_NON_BLOCKING 
GF_SOCK_IS_MULTICAST 
GF_SOCK_IS_LISTENING 
GF_SOCK_HAS_PEER 
GF_SOCK_IS_UN 
GF_SOCK_HAS_CONNECT 

◆ anonymous enum

anonymous enum
Enumerator
NETCAP_IS_MCAST 
NETCAP_IS_TCP 
NETCAP_HAS_PEER 
NETCAP_IS_IPV6 
NETCAP_HAS_EXT 
NETCAP_DROP 

◆ anonymous enum

anonymous enum
Enumerator
NETCAP_NONE 
NETCAP_GPAC 
NETCAP_PCAP 
NETCAP_PCAPNG 

◆ anonymous enum

anonymous enum
Enumerator
PCAP_LT_LOOPBACK 
PCAP_LT_ETHERNET 
PCAP_LT_CHAOS 

Function Documentation

◆ gf_net_filter_get()

static GF_NetcapFilter * gf_net_filter_get ( const char *  id)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_bs_from_fd()

GF_BitStream* gf_bs_from_fd ( int  fd,
u32  mode 
)
+ Here is the caller graph for this function:

◆ gf_net_close_capture()

void gf_net_close_capture ( )
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_record()

static GF_Err gf_netcap_record ( GF_NetcapFilter *  nf)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_load_pck_gpac()

static void gf_netcap_load_pck_gpac ( GF_NetcapFilter *  nf)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pcapng_load_shb()

static GF_Err pcapng_load_shb ( GF_NetcapFilter *  nf,
Bool  is_init 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pcapng_load_idb()

static void pcapng_load_idb ( GF_NetcapFilter *  nf)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_load_pck_pcap()

static void gf_netcap_load_pck_pcap ( GF_NetcapFilter *  nf)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_playback()

static GF_Err gf_netcap_playback ( GF_NetcapFilter *  nf)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_setup()

GF_Err gf_netcap_setup ( char *  rules)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ netcap_filter_pck()

static Bool netcap_filter_pck ( GF_Socket *  sock,
u32  pck_len,
Bool  for_send 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_load_pck()

static void gf_netcap_load_pck ( GF_NetcapFilter *  nf,
u64  now 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_send_pcap()

static GF_Err gf_netcap_send_pcap ( GF_NetcapFilter *  nf,
GF_Socket *  sock,
const u8 buffer,
u32  length,
u32 written,
Bool  is_ng 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_send_gpac()

static GF_Err gf_netcap_send_gpac ( GF_NetcapFilter *  nf,
GF_Socket *  sock,
const u8 buffer,
u32  length,
u32 written 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_netcap_send()

static GF_Err gf_netcap_send ( GF_Socket *  sock,
const u8 buffer,
u32  length,
u32 written 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_sk_has_nrt_netcap()

Bool gf_sk_has_nrt_netcap ( GF_Socket *  sk)
+ Here is the caller graph for this function:

◆ gf_sk_free()

static void gf_sk_free ( GF_Socket *  sock)
static
+ Here is the caller graph for this function:

◆ inet_addr_from_name()

static u32 inet_addr_from_name ( const char *  local_interface)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ poll_select()

static GF_Err poll_select ( GF_Socket *  sock,
GF_SockSelectMode  mode,
u32  usec,
Bool  force_select 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sk_join_ipv4()

static GF_Err sk_join_ipv4 ( GF_Socket *  sock,
struct ip_mreq *  M_req,
u32  TTL,
const char **  src_ip_inc,
u32  nb_src_ip_inc,
const char **  src_ip_exc,
u32  nb_src_ip_exc 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_ifce_enum()

static Bool get_ifce_enum ( void *  cbk,
const char *  name,
const char *  IP,
u32  flags 
)
static
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gf_sk_receive_internal()

GF_Err gf_sk_receive_internal ( GF_Socket *  sock,
char *  buffer,
u32  length,
u32 BytesRead,
Bool  do_select 
)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ first_tcp_port

u16 first_tcp_port =30000

◆ netcap_filters

GF_List* netcap_filters =NULL
static

◆ gpac_use_poll

Bool gpac_use_poll =GF_TRUE