SOCKET Struct Reference

Unique description of a bidirectional network communication channel. More...

#include <net.h>

Data Fields

uint32_t error_code
 
uint32_t dest_addr
 
uint16_t dest_port
 
uint16_t ip_tos
 
uint32_t src_addr
 
uint16_t src_port
 
uint16_t res_align2
 
void * user_pointer
 
uint32_t res_align3 [2]
 
struct in_struct in
 
uint32_t res [SO_SPARE]
 
uint32_t mc_dest_addr
 
uint32_t mc_group_addr
 
uint16_t mc_dest_port
 
uint16_t mc_src_port
 
uint16_t proto
 
uint32_t option
 
uint32_t status
 
struct out_struct out
 
uint8_t data_type
 
uint8_t data_shift
 

Detailed Description

Main structure to hold all information about a current connection (refer to Sockets). Each connection must have its own socket structure. Use socket_open() to acquire a new socket for a new connection. socket_open() returns a pointer to SOCKET, which is an abbreviation to socket_struct.

Not all socket_struct members are user accessible. Please make sure not to use res[SO_SPARE], which holds important internal information about the current connection (such as connection status, DNS sockets, timing and retransmit values, timeouts etc.). However it is possible to use res_align3[2] and *user_pointer as free scratch registers for application specific use.

The most important user accessible member is error_code. If a transmit function returns a SOCKET_ERROR the user should check the reason:

E.g. in a TCP callback function

switch (socket->error_code & SO_ERROR_MASK)
{
//******************************************************************
// data received successfully
//******************************************************************
break;
//******************************************************************
// connection established
//******************************************************************
break;
//******************************************************************
// connection closed
//******************************************************************
break;
//******************************************************************
// connection timed out, peer not available
// shutdown connection to prevent a dangling socket
//******************************************************************
shutdown (so, 10L);
CPrintf (" connection closed\r\n");
break;
default:
//******************************************************************
// else print error
//******************************************************************
net_print_error (socket->error_code, CPrintf);
break;
}

Field Documentation

uint32_t dest_addr

socket destination address information
it can be used to determine destinations address after successful net_recv()

uint16_t dest_port

socket destination port information
it can be used to determine destinations port after successful net_recv()

uint16_t ip_tos

IP type of service
use immediately before net_send() or after net_recv()

  • bit 15..8 : receive TOS
  • bit 7..0 : send TOS
uint32_t src_addr

Local address

uint16_t src_port

Local port

uint16_t res_align2

32 bit alignment.

user_pointer

Free for custom use as a general purpose pointer

Useful to attach additional data to a specific socket
E.g. in example Echo.c:

//**************************************************************************
// attach buffer control structure to socket
// (required for NBufferAcquireBuffer() later)
//**************************************************************************
uint32_t res_align3[2]

128 bit alignment. Free for custom use as 32 bit scratch registers

struct in_struct in

Data length of incoming packets

uint32_t res[SO_SPARE]

Reserved data space, do not use

mc_dest_addr

Multicast Destination address

See also
Multicast
mc_group_addr

Multicast group address

See also
Multicast
mc_dest_port

Multicast Destination port

See also
Multicast
mc_src_port

Multicast Source port

See also
Multicast
proto

protocol the socket is bound to

See also
IPT_TCP, IPT_UDP
uint32_t option
uint32_t status
struct out_struct out
uint8_t data_type
uint8_t data_shift