LIBSSDP
 All Classes Files Functions Variables Typedefs Macros
Functions
net_utils.h File Reference
#include <sys/socket.h>
#include <netinet/in.h>
#include "common_definitions.h"
Include dependency graph for net_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int parse_address (const char *raw_address, struct sockaddr_storage *address)
 
BOOL parse_url (const char *url, char *ip, int ip_size, int *port, char *rest, int rest_size)
 
int find_interface (struct sockaddr_storage *saddr, const char *interface, const char *address)
 
char * get_mac_address_from_socket (const SOCKET sock, const struct sockaddr_storage *sa_ip, const char *ip, char *mac_buffer)
 
BOOL is_address_multicast (const char *address)
 
char * get_ip_from_sock_address (const struct sockaddr_storage *saddr, char *ip_buffer)
 
BOOL is_address_ipv6 (const char *ip)
 
BOOL is_address_ipv6_ex (const char *ip, struct sockaddr_in6 *saddr6)
 
BOOL is_address_ipv4 (const char *ip)
 
BOOL is_address_ipv4_ex (const char *ip, struct sockaddr_in *saddr)
 
BOOL set_ip_and_port_in_sock_address (const char *ip, int port, struct sockaddr_storage *saddr)
 
int get_port_from_sock_address (const struct sockaddr_storage *saddr)
 

Detailed Description

Header file for net_utils.c

Definition in file net_utils.h.

Function Documentation

int find_interface ( struct sockaddr_storage *  saddr,
const char *  interface,
const char *  address 
)

Tries to find an interface with the specified name or IP address

Parameters
saddrA pointer to the buffer of the address that should be updated.
interfaceThe interface name we want to find.
addressThe address name we want to find.
Returns
The interface index (int).

Definition at line 192 of file net_utils.c.

char* get_ip_from_sock_address ( const struct sockaddr_storage *  saddr,
char *  ip_buffer 
)

Retrieve the IP in printable format from a socket address struct.

Parameters
saddrThe socket addres struct.
ip_bufferIf set, the resulting IP will be stored in it and no new allocation will be made. The returned pointer will equal this one.
Returns
The IP address in printable format. If ip_buffer was NULL, the returned value must be freed.

Definition at line 621 of file net_utils.c.

char* get_mac_address_from_socket ( const SOCKET  sock,
const struct sockaddr_storage *  sa_ip,
const char *  ip,
char *  mac_buffer 
)

Get the remote MAC address from a given sock.

Parameters
sockThe socket to extract the MAC address from.
sa_ipThe socket address to extract for.
ipThe IP address to extract for. If sa_ip is set this will be ignored.
mac_bufferA buffer to store the resulting MAC in. If empty a new allocation will be returned as a return value, otherwise the returned value will point to the mac_buffer.
Returns
The remote MAC address as a string. If mac_buffer was NULL, the returned value must be freed.

Definition at line 455 of file net_utils.c.

int get_port_from_sock_address ( const struct sockaddr_storage *  saddr)

Retrieve the port from a socket address.

Parameters
saddrThe socket address to get the port from.
Returns
The port number.

Definition at line 729 of file net_utils.c.

BOOL is_address_ipv4 ( const char *  ip)
inline

Check whether an IP address is of version 4.

Parameters
ipThe IP address to check.
Returns
TRUE if it is an IPv4 address, FALSE otherwise.

Definition at line 674 of file net_utils.c.

BOOL is_address_ipv4_ex ( const char *  ip,
struct sockaddr_in *  saddr 
)

Check whether an IP address is of version 4. This function will also fill the given socket address structure with the network form of the IP address.

Parameters
ipThe IP address to check.
saddrThe socket address to fill.
Returns
TRUE if it is an IPv4 address, FALSE otherwise.

Definition at line 680 of file net_utils.c.

BOOL is_address_ipv6 ( const char *  ip)
inline

Check whether an IP address is of version 6.

Parameters
ipThe IP address to check.
Returns
TRUE if it is an IPv6 address, FALSE otherwise.

Definition at line 659 of file net_utils.c.

BOOL is_address_ipv6_ex ( const char *  ip,
struct sockaddr_in6 *  saddr6 
)

Check whether an IP address is of version 6. This function will also fill the given socket address structure with the network form of the IP address.

Parameters
ipThe IP address to check.
saddr6The socket address to fill.
Returns
TRUE if it is an IPv6 address, FALSE otherwise.

Definition at line 665 of file net_utils.c.

BOOL is_address_multicast ( const char *  address)

Check whether a given IP is a multicast IP (if IPV6 checks for UPnP multicast IP, should be changed to check if multicast at all).

Parameters
addressThe address to check.
Returns
TRUE on success, FALSE otherwise.

Definition at line 583 of file net_utils.c.

int parse_address ( const char *  raw_address,
struct sockaddr_storage *  address 
)

Parse a string containing an IP address.

Parameters
raw_addressThe string containing the IP address.
addressThe sockaddr_storage buffer to store the address.
Returns
0 on success, 1 on error.

Definition at line 33 of file net_utils.c.

BOOL parse_url ( const char *  url,
char *  ip,
int  ip_size,
int *  port,
char *  rest,
int  rest_size 
)

Parse a URL into an IP, port and rest. This function does not work with domain names, only with IP addresses.

Parameters
urlThe URL to parse.
ipthe IP in the URL.
Thesize of the ip.
portThe port in the URL.
restThe rest of the URL.
rest_sizeThe size of the rest data.
Returns
TRUE on success, FALSE otherwise.

Definition at line 107 of file net_utils.c.

BOOL set_ip_and_port_in_sock_address ( const char *  ip,
int  port,
struct sockaddr_storage *  saddr 
)

Set the network form of the given IP address in the given socket address buffer.

Parameters
ipThe IP to set.
portThe port to set.
saddrThe socket address buffer to set the IP in.
Returns
TRUE on success, FALSE otherwise.

Definition at line 689 of file net_utils.c.