RawIpSocket Sample
The RawIpSocket sample runs one raw IP socket per upper-level protocol. This sample uses the protocol number 250.
This sample binds the socket to the IP port 0x7FFF, which is used as the RAW IP port by the TCP/IP Stack.
The client has a flag for demonstrating how to include the IP header with outgoing packets (/h 1). The sample does not include IP header by default, which is different from standard TCP/IP stack outgoing packets. Received packets always include the IP header.
Building the Sample
Build the sample using either the RTSSRelease or RTSSDebug build configurations.
Running the Sample
- Run the sample as a server on a wRTOS system with the TCP/IP Stack running.
- Run the sample as a client on a second wRTOS system with the TCP/IP Stack running.
Note: Both systems must have a physical Ethernet interface with the configured IPv4 address. The interfaces must be connected via an Ethernet switch or connected directly.
Usage
Server example: rtssrun RawIpSocket
Client example: rtssrun RawIpSocket /c server_ipv4_address
Options
Server options:
/b source_ip_address – the IPv4 address to bind the socket to, if specified
/w socket_window – the socket window, default is 500000 (SO_SNDBUF and SO_RCVBUF socket options)
/m packet_count – the packet count, the default behavior is to run forever
/r report_count – the report count, default is 500
Client Options:
/c destination_ip_address – the server IPv4 address
/b source_ip_address – the IPv4 address to bind the socket to, if specified
/w socket_window – the socket window, the default is 500000 (SO_SNDBUF and SO_RCVBUF socket options)
/m packet_count – the packet count, the default count is 10000
/r report_count – the report count, the default count is 500
/l packet_size – the packet size, the default size is 1024 (4 to 65515, IP header not included)
/t select_tout_ms – the timeout of the select socket call, in milliseconds. If the client does not receive a response before this timeout, it sends the next packet. The default timeout is 1000 (used only on receive).
/h (1/0) – 1 means to include IP header on send, the default is 0 (don’t include the IP header)
Remarks
The RawIpSocket sample only supports the RTSSRelease and RTSSDebug build configurations. This sample cannot be built as a Windows application.
The connect() is not supported by TCP/IP Stack, the application must use sendto() and recvfrom().
There is a known issue where the TCP/IP Stack sends and reassembles IP datagrams for a raw IP socket greater than 64K.
Output
The server prints a startup message and an additional line every 500 received packets:
*** RawIpSocket Server: WinSock started ***
*** RawIpSocket Server: Socket window 500000 ***
*** RawIpSocket Server: Run forever ***
RawIpSocket Server: Received 500 packets
RawIpSocket Server: Received 1000 packets
RawIpSocket Server: Received 1500 packets
RawIpSocket Server: Received 2000 packets
RawIpSocket Server: Received 2500 packets
RawIpSocket Server: Received 3000 packets
RawIpSocket Server: Received 3500 packets
RawIpSocket Server: Received 4000 packets
RawIpSocket Server: Received 4500 packets
RawIpSocket Server: Received 5000 packets
RawIpSocket Server: Received 5500 packets
RawIpSocket Server: Received 6000 packets
RawIpSocket Server: Received 6500 packets
RawIpSocket Server: Received 7000 packets
RawIpSocket Server: Received 7500 packets
RawIpSocket Server: Received 8000 packets
RawIpSocket Server: Received 8500 packets
RawIpSocket Server: Received 9000 packets
RawIpSocket Server: Received 9500 packets
RawIpSocket Server: Received 10000 packets
The client prints a startup message and then prints an additional line every 500 sent packets:
*** RawIpSocket Client: WinSock started ***
*** RawIpSocket Client: Server address 192.168.200.1 ***
*** RawIpSocket Client: Socket window 500000 ***
*** RawIpSocket Client: Run until 10000 packets ***
*** RawIpSocket Client: Data size 1024 ***
*** RawIpSocket Client: Select timeout 1000 MS ***
*** RawIpSocket Client: Don't include IP header ***
RawIpSocket Client: Sent 500 packets of 1024 data bytes
RawIpSocket Client: Sent 1000 packets of 1024 data bytes
RawIpSocket Client: Sent 1500 packets of 1024 data bytes
RawIpSocket Client: Sent 2000 packets of 1024 data bytes
RawIpSocket Client: Sent 2500 packets of 1024 data bytes
RawIpSocket Client: Sent 3000 packets of 1024 data bytes
RawIpSocket Client: Sent 3500 packets of 1024 data bytes
RawIpSocket Client: Sent 4000 packets of 1024 data bytes
RawIpSocket Client: Sent 4500 packets of 1024 data bytes
RawIpSocket Client: Sent 5000 packets of 1024 data bytes
RawIpSocket Client: Sent 5500 packets of 1024 data bytes
RawIpSocket Client: Sent 6000 packets of 1024 data bytes
RawIpSocket Client: Sent 6500 packets of 1024 data bytes
RawIpSocket Client: Sent 7000 packets of 1024 data bytes
RawIpSocket Client: Sent 7500 packets of 1024 data bytes
RawIpSocket Client: Sent 8000 packets of 1024 data bytes
RawIpSocket Client: Sent 8500 packets of 1024 data bytes
RawIpSocket Client: Sent 9000 packets of 1024 data bytes
RawIpSocket Client: Sent 9500 packets of 1024 data bytes
RawIpSocket Client: Sent 10000 packets of 1024 data bytes
*** RawIpSocket Client: Exit ***
APIs Referenced
RTAPI
Supported Windows API
Winsock BSD API
See Also
- Using RAW Sockets