Defines | Functions
host_netutil.h File Reference
#include "build.h"
#include "list.h"
#include "ipcam_packet.h"
#include <sys/socket.h>
#include <netinet/in.h>
Include dependency graph for host_netutil.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define SEC_TO_USEC(sec)   (1000*1000*sec)

Functions

int wge100ArpAdd (IpCamList *camInfo)
int wge100ArpDel (IpCamList *camInfo)
int wge100CmdSocketCreate (const char *ifName, NetHost *localHost)
int wge100EthGetLocalMac (const char *ifName, struct sockaddr *macAddr)
int wge100IpGetLocalAddr (const char *ifName, struct in_addr *addr)
int wge100IpGetLocalBcast (const char *ifName, struct in_addr *bcast)
int wge100IpGetLocalNetmask (const char *ifName, struct in_addr *bcast)
int wge100SendUDP (int s, const IPAddress *ip, const void *data, size_t dataSize)
int wge100SendUDPBcast (int s, const char *ifName, const void *data, size_t dataSize)
int wge100SocketConnect (int s, const IPAddress *ip)
int wge100SocketCreate (const struct in_addr *addr, uint16_t port)
int wge100WaitForPacket (int *s, int nums, uint32_t type, size_t pktLen, uint32_t *wait_us)

Define Documentation

#define SEC_TO_USEC (   sec)    (1000*1000*sec)

Definition at line 65 of file host_netutil.h.


Function Documentation

int wge100ArpAdd ( IpCamList camInfo)

Add a 'permanent' ARP to IP mapping in the system ARP table for one camera. Since the cameras do not support ARP, this step is necessary so that the host can find them.

Warning:
Under Linux, this function requires superuser privileges (or CAP_NET_ADMIN)
Parameters:
camInfoAn IpCamList element that describes the IP and MAC of the camera
Returns:
Returns 0 for success, -1 with errno set for failure.

Definition at line 61 of file host_netutil.c.

int wge100ArpDel ( IpCamList camInfo)

Remove an to IP mapping from the system ARP table for one camera. This function can be used to prevent cluttering the ARP table with unused 'permanent' mappings.

Warning:
Under Linux, this function requires superuser privileges (or CAP_NET_ADMIN)
Parameters:
camInfoAn IpCamList element that describes the IP and MAC of the camera
Returns:
Returns 0 for success, -1 with errno set for failure.

Definition at line 107 of file host_netutil.c.

int wge100CmdSocketCreate ( const char *  ifName,
NetHost localHost 
)

Creates and binds a new command packet socket for communicating to a camera. Will always bind to an ephemeral local port number.

Parameters:
ifNameInterface name to bind to. Null terminated string (e.g., "eth0")
localHostOptional pointer to a structure to receive the local host (MAC/IP/Port) information
Returns:
Returns the socket if successful, -1 otherwise

Definition at line 387 of file host_netutil.c.

int wge100EthGetLocalMac ( const char *  ifName,
struct sockaddr *  macAddr 
)

Utility function to retrieve the MAC address asssociated with a specified Ethernet interface name.

Parameters:
ifNameA null-terminated string containing the name of the Ethernet address (e.g., eth0)
macAddrA sockaddr structure to contain the MAC
Returns:
Returns 0 if successful, -1 with errno set otherwise

Definition at line 154 of file host_netutil.c.

int wge100IpGetLocalAddr ( const char *  ifName,
struct in_addr *  addr 
)

Utility function to retrieve the local IPv4 address asssociated with a specified Ethernet interface name.

Parameters:
ifNameA null-terminated string containing the name of the Ethernet address (e.g., eth0)
macAddrA in_addr structure to contain the local interface IP
Returns:
Returns 0 if successful, -1 with errno set otherwise

Definition at line 231 of file host_netutil.c.

int wge100IpGetLocalBcast ( const char *  ifName,
struct in_addr *  bcast 
)

Utility function to retrieve the broadcast IPv4 address asssociated with a specified Ethernet interface name.

Parameters:
ifNameA null-terminated string containing the name of the Ethernet address (e.g., eth0)
macAddrA in_addr structure to contain the broadcast IP
Returns:
Returns 0 if successful, -1 with errno set otherwise

Definition at line 193 of file host_netutil.c.

int wge100IpGetLocalNetmask ( const char *  ifName,
struct in_addr *  addr 
)

Utility function to retrieve the local IPv4 netmask asssociated with a specified Ethernet interface name.

Parameters:
ifNameA null-terminated string containing the name of the Ethernet address (e.g., eth0)
macAddrA in_addr structure to contain the local interface IP
Returns:
Returns 0 if successful, -1 with errno set otherwise

Definition at line 269 of file host_netutil.c.

int wge100SendUDP ( int  s,
const IPAddress ip,
const void *  data,
size_t  dataSize 
)

Utility function to send 'dataSize' bytes of 'data' to remote address 'ip'. This function always sends to the WG_CAMCMD_PORT port.

Parameters:
sBound socket to send on
ipIPv4 Address of remote camera to send to
dataArray of at least dataSize bytes, containing payload to send
dataSizeSize of payload to send, in bytes
Returns:
Returns 0 if successful. -1 with errno set otherwise. Caller is responsible for closing the socket when finished.

Definition at line 435 of file host_netutil.c.

int wge100SendUDPBcast ( int  s,
const char *  ifName,
const void *  data,
size_t  dataSize 
)

Utility function that wraps wge100SendUDP to send a packet to the broadcast address on the specified interface.

Parameters:
sBound socket to send on
ifNameName of interface socket is bound on. (Null terminated string, e.g., "eth0")
dataArray of at least dataSize bytes, containing payload to send
dataSizeSize of payload to send, in bytes
Returns:
Returns 0 if successful. -1 with errno set otherwise. Caller is responsible for closing the socket when finished.

Definition at line 464 of file host_netutil.c.

int wge100SocketConnect ( int  s,
const IPAddress ip 
)

Utility wrapper to 'connect' a datagram socket to a specific remote host. Once connected, the socket can only receive datagrams from that host.

Parameters:
sThe open and bound local socket to connect.
ipThe remote IP address to connect to.
Returns:
Returns the result from the connect() system call.
Todo:
Not sure why this hack is needed. I'm pretty sure it used to

Definition at line 353 of file host_netutil.c.

int wge100SocketCreate ( const struct in_addr *  addr,
uint16_t  port 
)

Utility function to create a UDP socket and bind it to a specified address & port.

Parameters:
addrThe host IP address to bind to.
portThe host UDP port to bind to. Host byte order. Port of 0 causes bind() to assign an ephemeral port.
Returns:
Returns the bound socket if successful, -1 with errno set otherwise

Definition at line 306 of file host_netutil.c.

int wge100WaitForPacket ( int *  s,
int  nums,
uint32_t  type,
size_t  pktLen,
uint32_t *  wait_us 
)

Waits for a specified amount of time for a WGE100 packet that matches the specified length and type criteria.

On return, the wait_us argument is updated to reflect the amount of time still remaining in the original timeout. This can be useful when calling wge100WaitForPacket() in a loop.

Parameters:
sThe datagram sockets to listen on. It must be opened, bound, and connected.
numsThe number of sockets to listen on.
typeThe WGE100 packet type to listen for. Packets that do not match this type will be discarded
pktLenThe length of WGE100 packet to listen for. Packets that do not match this length will be discarded.
wait_usThe duration of time to wait before timing out. Is adjusted upon return to reflect actual time remaning on the timeout.
Returns:
Returns -1 with errno set for system call failures, index of socket that is ready otherwise. If wait_us is set to zero, then the wait has timed out.

Definition at line 493 of file host_netutil.c.



wge100_camera
Author(s): Blaise Gassend, Patrick Mihelich, Eric MacIntosh, David Palchak
autogenerated on Mon Oct 6 2014 08:59:04