tfRawSocket

Jump to: navigation, search

Table of Contents >> Programmer's Reference


#include <trsocket.h>


int tfRawSocket (
ttUserIpAddress ipAddress,
int protocol
);


Function Description

This function creates a raw socket. A raw socket enables the user to either send data above the IP layer, or to send data with the IP header. In the latter case, the user must set the IPO_HDRINCL option at the IP level in the setsockopt() call. When the user receives data on the raw socket, the IP header is always included. Given a transport layer protocol and IP address, tfRawSocket() returns a raw socket bound to TM_RAW_IP_PORT and ipAddress. Note that ipAddress can be a zero IP address if the user does not want to bind to a specific IP address. The user can use this function only if TM_USE_RAW_SOCKET has been defined in <trsystem.h>. An example of tfRawSocket() usage is shown in the loopback test module txscatlp.c.


Parameters

  • ipAddress
    User IP address to bind the raw socket with.
  • protocol
    Protocol above IP. Examples include (but are not limited to): IPPROTO_IGMP, IPPROTO_ICMP, IPPROTO_OSPF.


Returns

  • >= 0
    Success
  • TM_SOCKET_ERROR
    Failure


Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).


Possible socket errors

  • TM_EINVAL
    Invalid protocol for raw socket send/receive. IPPROTO_UDP and IPPROTO_TCP are not allowed.
  • TM_EINVAL
    There is no interface configured with the specified IP address (if the ipAddress parameter is not zero).
  • TM_EADDRINUSE
    A raw socket has already been opened for this protocol.


Table of Contents >> Programmer's Reference