extern int comm_init (void)
| comm_init |
#include <comm_api.h>
Init stuff. Need to be called only once (during startup).
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_ipv4_present (void)
| comm_ipv4_present |
#include <comm_api.h>
Indicate presence of IPv4 support.
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_ipv6_present (void)
| comm_ipv6_present |
#include <comm_api.h>
Indicate presence of IPv6 support.
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_open_tcp (int family, int is_blocking)
| comm_open_tcp |
#include <comm_api.h>
Open a TCP socket.
Parameters:
family | the address family. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwsise XORP_ERROR.
extern int comm_open_udp (int family, int is_blocking)
| comm_open_udp |
#include <comm_api.h>
Open an UDP socket.
Parameters:
family | the address family. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwsise XORP_ERROR.
extern int comm_close (int sock)
| comm_close |
#include <comm_api.h>
Close a socket.
Parameters:
sock | the socket to close. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_bind_tcp4 (const struct in_addr *my_addr,
unsigned short my_port, int is_blocking)
| comm_bind_tcp4 |
#include <comm_api.h>
Open an IPv4 TCP socket and bind it to a local address and a port.
Parameters:
my_addr | the local IPv4 address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the local port to bind to (in network order). |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_tcp6 (const struct in6_addr *my_addr,
unsigned short my_port, int is_blocking)
| comm_bind_tcp6 |
#include <comm_api.h>
Open an IPv6 TCP socket and bind it to a local address and a port.
Parameters:
my_addr | the local IPv6 address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the local port to bind to (in network order). |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_udp4 (const struct in_addr *my_addr,
unsigned short my_port, int is_blocking)
| comm_bind_udp4 |
#include <comm_api.h>
Open an IPv4 UDP socket and bind it to a local address and a port.
Parameters:
my_addr | the local IPv4 address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the local port to bind to (in network order). |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_udp6 (const struct in6_addr *my_addr,
unsigned short my_port, int is_blocking)
| comm_bind_udp6 |
#include <comm_api.h>
Open an IPv6 UDP socket and bind it to a local address and a port.
Parameters:
my_addr | the local IPv6 address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the local port to bind to (in network order). |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_join_udp4 (const struct in_addr *mcast_addr,
const struct in_addr *join_if_addr,
unsigned short my_port,
int reuse_flag, int is_blocking)
| comm_bind_join_udp4 |
#include <comm_api.h>
Open an IPv4 UDP socket on an interface, bind it to a port, and join a multicast group.
Note that we bind to ANY address instead of the multicast address only. If we bind to the multicast address instead, then using the same socket for sending multicast packets will trigger a bug in the FreeBSD kernel: the source IP address will be set to the multicast address. Hence, the application itself may want to filter the UDP unicast packets that may have arrived with a destination address one of the local interface addresses and the same port number.
Parameters:
mcast_addr | the multicast address to join. |
join_if_addr | the local unicast interface address (in network order) to join the multicast group on. If it is NULL, the system will choose the interface each time a datagram is sent. |
my_port | the port to bind to (in network order). |
reuse_flag | if true, allow other sockets to bind to the same multicast address and port, otherwise disallow it. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_join_udp6 (const struct in6_addr *mcast_addr,
unsigned int join_if_index,
unsigned short my_port,
int reuse_flag, int is_blocking)
| comm_bind_join_udp6 |
#include <comm_api.h>
Open an IPv6 UDP socket on an interface, bind it to a port, and join a multicast group.
Note that we bind to ANY address instead of the multicast address only. If we bind to the multicast address instead, then using the same socket for sending multicast packets will trigger a bug in the FreeBSD kernel: the source IP address will be set to the multicast address. Hence, the application itself may want to filter the UDP unicast packets that may have arrived with a destination address one of the local interface addresses and the same port number.
Parameters:
mcast_addr | the multicast address to join. |
join_if_index | the local unicast interface index to join the multicast group on. If it is 0, the system will choose the interface each time a datagram is sent. |
my_port | the port to bind to (in network order). |
reuse_flag | if true, allow other sockets to bind to the same multicast address and port, otherwise disallow it. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_connect_tcp4 (const struct in_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_connect_tcp4 |
#include <comm_api.h>
Open an IPv4 TCP socket, and connect it to a remote address and port. TODO: XXX: because it may take time to connect on a TCP socket, the return value actually is XORP_OK even though the connect did not complete.
Parameters:
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_connect_tcp6 (const struct in6_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_connect_tcp6 |
#include <comm_api.h>
Open an IPv6 TCP socket, and connect it to a remote address and port.
TODO: XXX: because it may take time to connect on a TCP socket, the return value actually is XORP_OK even though the connect did not complete.
Parameters:
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_connect_udp4 (const struct in_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_connect_udp4 |
#include <comm_api.h>
Open an IPv4 UDP socket, and connect it to a remote address and port.
Parameters:
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_connect_udp6 (const struct in6_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_connect_udp6 |
#include <comm_api.h>
Open an IPv6 UDP socket, and connect it to a remote address and port.
Parameters:
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_connect_udp4 (const struct in_addr *local_addr,
unsigned short local_port,
const struct in_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_bind_connect_udp4 |
#include <comm_api.h>
Open an IPv4 UDP socket, bind it to a local address and a port, and connect it to a remote address and port.
Parameters:
local_addr | the local address to bind to. If it is NULL, will bind to `any' local address. |
local_port | the local port to bind to. |
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_bind_connect_udp6 (const struct in6_addr *local_addr,
unsigned short local_port,
const struct in6_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_bind_connect_udp6 |
#include <comm_api.h>
Open an IPv6 UDP socket, bind it to a local address and a port, and connect it to a remote address and port.
Parameters:
local_addr | the local address to bind to. If it is NULL, will bind to `any' local address. |
local_port | the local port to bind to. |
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the new socket on success, otherwise XORP_ERROR.
extern int comm_sock_open (int domain, int type, int protocol,
int is_blocking)
| comm_sock_open |
#include <comm_api.h>
Open a socket of domain = domain, type = type, protocol = @protocol, and blocking = @blocking.
The sending and receiving buffer size are set, and the socket itself is set with TCP_NODELAY (if a TCP socket).
Parameters:
domain | the domain of the socket (e.g., AF_INET, AF_INET6). |
type | the type of the socket (e.g., SOCK_STREAM, SOCK_DGRAM). |
protocol | the particular protocol to be used with the socket. |
is_blocking | if true then the socket will be blocking, otherwise non-blocking. |
Returns: the open socket on success, otherwise XORP_ERROR.
extern int comm_sock_bind4 (int sock, const struct in_addr *my_addr,
unsigned short my_port)
| comm_sock_bind4 |
#include <comm_api.h>
Bind an IPv4 socket to an address and a port.
Parameters:
sock | the socket to bind. |
my_addr | the address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the port to bind to (in network order). |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_bind6 (int sock, const struct in6_addr *my_addr,
unsigned short my_port)
| comm_sock_bind6 |
#include <comm_api.h>
Bind an IPv6 socket to an address and a port.
Parameters:
sock | the socket to bind. |
my_addr | the address to bind to (in network order). If it is NULL, will bind to `any' local address. |
my_port | the port to bind to (in network order). |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_join4 (int sock, const struct in_addr *mcast_addr,
const struct in_addr *my_addr)
| comm_sock_join4 |
#include <comm_api.h>
Join an IPv4 multicast group on a socket (and an interface).
Parameters:
sock | the socket to join the group. |
mcast_addr | the multicast address to join. |
my_addr | the local unicast address of an interface to join. If it is NULL, the interface is chosen by the kernel. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_join6 (int sock, const struct in6_addr *mcast_addr,
unsigned int my_ifindex)
| comm_sock_join6 |
#include <comm_api.h>
Join an IPv6 multicast group on a socket (and an interface).
Parameters:
sock | he socket to join the group. |
mcast_addr | the multicast address to join. |
my_ifindex | the local unicast interface index to join. If it is 0, the interface is chosen by the kernel. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_leave4 (int sock, const struct in_addr *mcast_addr,
const struct in_addr *my_addr)
| comm_sock_leave4 |
#include <comm_api.h>
Leave an IPv4 multicast group on a socket (and an interface).
Parameters:
sock | the socket to leave the group. |
mcast_addr | the multicast address to leave. |
my_addr | the local unicast address of an interface to leave. If it is NULL, the interface is chosen by the kernel. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_leave6 (int sock, const struct in6_addr *mcast_addr,
unsigned int my_ifindex)
| comm_sock_leave6 |
#include <comm_api.h>
Leave an IPv6 multicast group on a socket (and an interface).
Parameters:
sock | he socket to leave the group. |
mcast_addr | the multicast address to leave. |
my_ifindex | the local unicast interface index to leave. If it is 0, the interface is chosen by the kernel. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_connect4 (int sock, const struct in_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_sock_connect4 |
#include <comm_api.h>
Connect to a remote IPv4 address.
XXX: We can use this not only for TCP, but for UDP sockets as well. XXX: if the socket is non-blocking, and the connection cannot be completed immediately, then the return value may be %XORP_OK.
Parameters:
sock | the socket to use to connect. |
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true, the socket is blocking, otherwise non-blocking. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_connect6 (int sock,
const struct in6_addr *remote_addr,
unsigned short remote_port,
int is_blocking)
| comm_sock_connect6 |
#include <comm_api.h>
Connect to a remote IPv6 address.
XXX: We can use this not only for TCP, but for UDP sockets as well. XXX: if the socket is non-blocking, and the connection cannot be completed immediately, then the return value may be %XORP_OK.
Parameters:
sock | the socket to use to connect. |
remote_addr | the remote address to connect to. |
remote_port | the remote port to connect to. |
is_blocking | if true, the socket is blocking, otherwise non-blocking. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_accept (int sock)
| comm_sock_accept |
#include <comm_api.h>
Accept a connection on a listening socket.
Parameters:
sock | the listening socket to accept on. |
Returns: the accepted socket on success, otherwise XORP_ERROR.
extern int comm_sock_close (int sock)
| comm_sock_close |
#include <comm_api.h>
Close a socket.
Parameters:
sock | the socket to close. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_nodelay (int sock, int val)
| comm_set_nodelay |
#include <comm_api.h>
Set/reset the TCP_NODELAY option on a TCP socket.
Parameters:
sock | the socket whose option we want to set/reset. |
val | if non-zero, the option will be set, otherwise will be reset. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_reuseaddr (int sock, int val)
| comm_set_reuseaddr |
#include <comm_api.h>
Set/reset the SO_REUSEADDR option on a socket.
XXX: if the OS doesn't support this option, XORP_ERROR is returned.
Parameters:
sock | the socket whose option we want to set/reset. |
val | if non-zero, the option will be set, otherwise will be reset. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_reuseport (int sock, int val)
| comm_set_reuseport |
#include <comm_api.h>
Set/reset the SO_REUSEPORT option on a socket.
XXX: if the OS doesn't support this option, XORP_ERROR is returned.
Parameters:
sock | the socket whose option we want to set/reset. |
val | if non-zero, the option will be set, otherwise will be reset. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_loopback (int sock, int val)
| comm_set_loopback |
#include <comm_api.h>
Set/reset the multicast loopback option on a socket.
Parameters:
sock | the socket whose option we want to set/reset. |
val | if non-zero, the option will be set, otherwise will be reset. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_tcpmd5 (int sock, int val)
| comm_set_tcpmd5 |
#include <comm_api.h>
Set/reset the TCP_MD5SIG option on a socket.
XXX: if the OS doesn't support this option, XORP_ERROR is returned.
Parameters:
sock | the socket whose option we want to set/reset. |
val | if non-zero, the option will be set, otherwise will be reset. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_ttl (int sock, int val)
| comm_set_ttl |
#include <comm_api.h>
Set the TTL of the outgoing multicast packets on a socket.
Parameters:
sock | the socket whose TTL we want to set. |
val | the TTL of the outgoing multicast packets. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_iface4 (int sock, const struct in_addr *in_addr)
| comm_set_iface4 |
#include <comm_api.h>
Set default interface for IPv4 outgoing multicast on a socket.
Parameters:
sock | the socket whose default multicast interface to set. |
in_addr | the IPv4 address of the default interface to set. If in_addr is NULL, the system will choose the interface each time a datagram is sent. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_set_iface6 (int sock, u_int ifindex)
| comm_set_iface6 |
#include <comm_api.h>
Set default interface for IPv6 outgoing multicast on a socket.
Parameters:
sock | the socket whose default multicast interface to set. |
ifindex | the IPv6 interface index of the default interface to set. If ifindex is 0, the system will choose the interface each time a datagram is sent. |
Returns: XORP_OK on success, otherwise XORP_ERROR.
extern int comm_sock_set_sndbuf (int sock, int desired_bufsize,
int min_bufsize)
| comm_sock_set_sndbuf |
#include <comm_api.h>
Set the sending buffer size of a socket.
Parameters:
sock | the socket whose sending buffer size to set. |
desired_bufsize | the preferred buffer size. |
min_bufsize | the smallest acceptable buffer size. |
Returns: the successfully set buffer size on success, otherwise XORP_ERROR.
extern int comm_sock_set_rcvbuf (int sock, int desired_bufsize,
int min_bufsize)
| comm_sock_set_rcvbuf |
#include <comm_api.h>
Set the receiving buffer size of a socket.
Parameters:
sock | the socket whose receiving buffer size to set. |
desired_bufsize | the preferred buffer size. |
min_bufsize | the smallest acceptable buffer size. |
Returns: the successfully set buffer size on success, otherwise XORP_ERROR.
extern int socket2family (int sock)
| socket2family |
#include <comm_api.h>
Get the address family of a socket.
XXX: idea taken from W. Stevens' UNPv1, 2e (pp 109)
Parameters:
sock | the socket whose address family we need to get. |
Returns: the address family on success, otherwise XORP_ERROR.
void comm_sock_no_ipv6 (const char* method, ...)
| comm_sock_no_ipv6 |
#include <comm_private.h>
Report IPv6 method invoked when IPv6 support is not present. An error message is output via XLOG_ERROR. This function is variadic so it can be used to remove unused variable warnings in non-IPv6 code as well as log the error.
Parameters:
method | ipv6 specific method to report. |