socket: Socket functions like initializing the socket, send and receive. (p_socket_...)


Enumerations

enum  P_SOCKET_OPTIONS { ,
  SOCKET_BOUND = 0x01, SOCKET_AUTOACK = 0x02, SOCKET_RECV_ALL = 0x04, SOCKET_FRAG = 0x08 ,
  SOCKET_BROADCAST = 0x10, SOCKET_BLOCKING = 0x20, SOCKET_FILTER_DUPS = 0x40
}
enum  P_FRAG_FLAG_MASKS { FRAG_STATEFLAG = 0x03, FRAG_ROLEFLAG = 0x04 }
enum  P_FRAG_STATUS { FRAG_ACTIVE = 0x00, FRAG_FINISHED = 0x01, FRAG_ABORTED = 0x02 }
enum  P_FRAG_ROLE { FRAG_SENDER = 0x00, FRAG_RECEIVER = 0x04 }
enum  P_SOCKET_SENDSTATUS { P_SEND_FINISHED = 1, P_SEND_ACTIVE = 2, P_SEND_ABORTED = 3 }

Functions

int p_socket_open (uint32_t localip, uint32_t broadcast_add, int port)
 Create a particle socket.
int p_socket_close (int sock)
 Close a particle socket.
int p_socket_set_lastacks (int counter)
 Set the number of packets, which should be stored to find doublets of acking-packets.
int p_socket_set_lastdups (int counter)
 Set the number of packets, which should be stored to find doublets.
int p_socket_set_ipdest (int sock, const struct in_addr *address)
 Set the destination-add for a socket.
int p_socket_set_ipdest_str (int sock, const char *address)
 Set the destination-add for a socket [string].
int p_socket_set_ipdest_all (int fd)
 Set the destination-add for a socket [string].
int p_socket_set_ipsrc_all (int sock)
 Set a Socket to receive all-mode.
int p_socket_set_ipsrc (int sock, const struct in_addr *address)
 Set the source-add for a socket.
int p_socket_set_ipsrc_str (int sock, const char *address)
 Set the source-add for a socket [string].
int p_socket_set_id (int sock, const uint8_t *add)
 Sets a particle sockets own net ID.
int p_socket_set_id_str (int sock, const char *addstr)
 Sets a particle sockets own net ID.
int p_socket_set_loc (int sock, const uint8_t *loc)
 Sets a particle sockets location-ID.
int p_socket_set_loc_str (int sock, const char *locstr)
 Sets a particle sockets location-ID.
int p_socket_set_option (int fd, int option, int mode)
 Sets a socket-option.
int p_socket_set_retry (int sock, uint8_t retries, uint32_t timeout)
 Sets the parameters for acknowledged sending.
void p_describe_socket (int sock)
 Prints out all information about a socket.
int p_socket_get_lastacks (void)
 Get the number of packets, which should be stored to find doublets of acking packets.
uint8_t * p_socket_get_id (int fd)
 Get the net ID of a socket.
uint8_t * p_socket_get_loc (int fd)
 Get the location-ID of a socket.
uint8_t * p_socket_get_ipdest (int fd, int device_number)
 Get an IP-address, the socket sends to.
int p_socket_get_num_interfaces (int fd)
 Get the number of interfaces the socket sends to.
int p_socket_set_num_interfaces (int fd, int counter)
 Sets the number of interfaces, a socket will send to.
uint8_t * p_socket_get_ipsrc (int fd)
 Get the IP-address the socket receives from.
int p_socket_get_retry (int fd)
 Get the number of retrys, the socket currently makes when sending acked.
uint32_t p_socket_get_timeout (int fd)
 Get the timeout [ms], the socket currently waits for acknowledges.
uint16_t p_socket_get_port (int fd)
 Get the port-number of a socket.
int p_socket_get_option (int fd, int option)
 Tests, if a socket-option is set to 0 or 1.
int p_socket_get_blocking (int fd)
 Is a socket currently blocking?
int p_socket_get_broadcast (int fd)
 Is a socket currently sending to broadcast?
uint8_t p_socket_get_last_seq (int fd)
 Get the last sequence-ID of a socket.
p_packet * p_socket_recv (int recv_sock, int send_sock)
 Receive data.
p_packet * p_socket_recv_filtered (int recv_sock, int send_sock, int recv_filter)
 Receive data filtered.
int p_socket_recv_raw (int sock, char *data, size_t maxlen)
 Receive raw data.
int p_socket_send (int send_sock, struct p_packet *send_data)
 Send data. Send CL-packet send_data on socket send_sock.
int p_socket_send_addressed (int send_sock, struct p_packet *send_data, uint8_t *add)
 Send data to a particle specified by its ID.
int p_socket_send_addressed_str (int send_sock, struct p_packet *send_data, const char *add_str)
 Send data to a particle specified by its ID.
int p_socket_send_acked (int send_sock, int recv_sock, struct p_packet *send_data, const uint8_t *add)
 Send data to a particle specified by its ID and wait for ACK control message.
int p_socket_send_acked_str (int send_sock, int recv_sock, struct p_packet *send_data, const char *addstr)
 Send data to a particle specified by its ID and wait for ACK control message.
int p_socket_send_buffer (int fd_out, int fd_in, const char *buf, uint32_t len, const uint8_t *sendto, const uint8_t *acl_type)
 Sending a data puffer to a particle.
int p_socket_send_buffer_str (int fd_out, int fd_in, const char *buf, uint32_t len, const char *sendto, const char *acl_type)
 Sending a data puffer to a particle [ID and ACL as string].
int p_socket_send_file (int fd_out, int fd_in, const char *filename, const uint8_t *sendto, const uint8_t *acl_type)
 Sending data from a file to a particle.
int p_socket_send_raw (int sock, const char *data, size_t len)
 Send raw data.
int p_socket_get_send_status (int sendticket)
 Get the status for a send-ticket.
int p_socket_delete_send_context (int sendticket)
 Deletes the context of a send-ticket.
int p_socket_set_broadcast ()
int p_socket_set_blocking ()
int p_socket_set_autoack ()
int p_socket_set_recv_option ()
int p_socket_set_frag_option ()

Enumeration Type Documentation

enum P_FRAG_FLAG_MASKS

fragmentation status return masks

Enumerator:
FRAG_STATEFLAG  status mask
FRAG_ROLEFLAG  role mask

Definition at line 90 of file socket_enum.h.

enum P_FRAG_ROLE

fragmentation role enumeration (status & FRAG_ROLEFLAG)

Enumerator:
FRAG_SENDER  if fragmentation handler is sending
FRAG_RECEIVER  if fragmentation handler is receiving

Definition at line 110 of file socket_enum.h.

enum P_FRAG_STATUS

fragmentation status enumeration (status & FRAG_STATEFLAG)

Enumerator:
FRAG_ACTIVE  if fragmentation handler is still active
FRAG_FINISHED  if fragmentation handler has finished successfully
FRAG_ABORTED  if fragmentation handler failed

Definition at line 99 of file socket_enum.h.

enum P_SOCKET_OPTIONS

An enum for the socket options, you can change

Enumerator:
SOCKET_BOUND  True if the socket is bound, false if not
SOCKET_AUTOACK  Decides, if the recv-function should send an ack-packet if a packet which is calling for an ack-packet was received. True if acking should be done automatically, false if the user makes his own ack-packets
SOCKET_RECV_ALL  True if you want to receive all packets, false if you only want to receive those which aren't addressed or addressed with your own ID.

If set to true, all packets will be received, also such which weren't addressed to this computer If set to false (default value), only such packets will be received, which were send to broadcast or which had been addressed to us. p_socket_recv will return NULL, if a package, which was not addressed to us, was received

Also, the socket_recv option decides, if you will see all packets of an active fragmentation. If it is set to false, only the last data will be returned to you, indicating that you have received some data. If set to true, you will see all packets of the running fragmentation.

SOCKET_FRAG  True if sending or receiving fragmented data should be enabled
SOCKET_BROADCAST  True if outgoing packets will be send to broadcast
SOCKET_BLOCKING  True if the socket is in blocking mode, false if the socket is currently non-blocking
SOCKET_FILTER_DUPS  True if the socket filters out double received packets, false if the socket returns all packets

Definition at line 53 of file socket_enum.h.

enum P_SOCKET_SENDSTATUS

send status enumeration

Enumerator:
P_SEND_FINISHED  if sending was successful
P_SEND_ACTIVE  if still sending
P_SEND_ABORTED  if sending failed

Definition at line 119 of file socket_enum.h.


Function Documentation

void p_describe_socket ( int  sock  ) 

Prints out all information about a socket.

Debug function, which prints out all internal information of socket sock to stdout.

Parameters:
sock Particle socket

int p_socket_close ( int  sock  ) 

Close a particle socket.

Closes an open UDP sockets and frees memory allocated for internal structures.

Parameters:
sock Particle socket descriptor

int p_socket_delete_send_context ( int  sendticket  ) 

Deletes the context of a send-ticket.

This function deletes all information about a send-context specified by the send-ticket.

Parameters:
sendticket The ticket of the send-context you want to delete.
Returns:
1 on success, -1 and EINVAL if the send ticket was not found

int p_socket_get_blocking ( int  fd  ) 

Is a socket currently blocking?

Parameters:
fd Pointer to the socket from which you want to get the blocking-mode.
Returns:
-1 on Error, 1 if socket is currently blocking, 0 if socket is currently non-blocking.
See also:
p_socket_set_option

int p_socket_get_broadcast ( int  fd  ) 

Is a socket currently sending to broadcast?

Parameters:
fd Pointer to the socket from which you want to get the sending-mode.
Returns:
-1 on Error, 1 if socket is currently sending to broadcast, 0 if socket is currently not sending to broadcast.
See also:
p_socket_set_socket_option

uint8_t* p_socket_get_id ( int  fd  ) 

Get the net ID of a socket.

Parameters:
fd Pointer to the socket from which you want to get the net ID
Returns:
NULL on Error, Pointer to the Socket-ID on success.
See also:
p_socket_set_id

p_socket_set_id_str

uint8_t* p_socket_get_ipdest ( int  fd,
int  device_number 
)

Get an IP-address, the socket sends to.

Gets the local broadcast address of the 1st / 2nd / 3rd / ... device, the socket sends to.

Parameters:
fd Pointer to the socket from which you want to get the IP-destination.
device_number,: Specifies the device, from that you want to get the address.
Returns:
NULL on Error, Pointer to the IP-destination on success.
See also:
p_socket_set_ipdest

p_socket_set_ipdest_str

uint8_t* p_socket_get_ipsrc ( int  fd  ) 

Get the IP-address the socket receives from.

Parameters:
fd Pointer to the socket from which you want to get the IP-source.
Returns:
NULL on Error, Pointer to the IP-source on success.
See also:
p_socket_set_ipsrc

p_socket_set_ipsrc_str

uint8_t p_socket_get_last_seq ( int  fd  ) 

Get the last sequence-ID of a socket.

Note: if you set the sequence number of the last packet with p_pkt_set_seq, p_socket_get_last_seq will not return you this special value!

Parameters:
fd Pointer to the socket from which you want to get the port-number.
Returns:
-1 on Error, sequence-number of the last packet on success.

int p_socket_get_lastacks ( void   ) 

Get the number of packets, which should be stored to find doublets of acking packets.

Get the number of acked packets, which should be hold in a queue an be compared with new received ack-packets to find doublets.

Returns:
Maximum number of packets, which will be stored.

uint8_t* p_socket_get_loc ( int  fd  ) 

Get the location-ID of a socket.

Parameters:
fd Pointer to the socket from which you want to get the location-ID
Returns:
NULL on Error, Pointer to the location-ID on success.
See also:
p_socket_set_loc

p_socket_set_loc_str

int p_socket_get_num_interfaces ( int  fd  ) 

Get the number of interfaces the socket sends to.

Parameters:
fd Pointer to the socket from which you want to get the number of interfaces.
Returns:
numer of interfaces on success, -1 on error

int p_socket_get_option ( int  fd,
int  option 
)

Tests, if a socket-option is set to 0 or 1.

See p_socket_set_option for available options. In addition to the options listed there, you can also get the state of SOCKET_BOUND with p_socket_get_option

Parameters:
fd Pointer to the socket from which you want to get the state of socket-option option.
option The option, you want to look after.
Returns:
-1 on Error, state of the socket-option option on success.
See also:
p_socket_set_option

uint16_t p_socket_get_port ( int  fd  ) 

Get the port-number of a socket.

Parameters:
fd Pointer to the socket from which you want to get the port-number.
Returns:
-1 on Error, port of fd on success.

int p_socket_get_retry ( int  fd  ) 

Get the number of retrys, the socket currently makes when sending acked.

Parameters:
fd Pointer to the socket from which you want to get the number of retries.
Returns:
-1 on Error, number of retries on success.
See also:
p_socket_set_retry

int p_socket_get_send_status ( int  sendticket  ) 

Get the status for a send-ticket.

This function will return the current state for a packet that has been send with ticket sendticket

Parameters:
sendticket The ticket of the packet you want the status for.
Returns:
0, 1 and -1 will be imediatly returned. -1 and EINVAL if the ticket was not found. P_SEND_FINISHE if the data has been send, P_SEND_ACTIVE if the send process is still active, P_SEND_ABORTED if sending was aborted

uint32_t p_socket_get_timeout ( int  fd  ) 

Get the timeout [ms], the socket currently waits for acknowledges.

Parameters:
fd Pointer to the socket from which you want to get the timeout.
Returns:
-1 on Error, timeout in ms on success.
See also:
p_socket_set_retry

int p_socket_open ( uint32_t  localip,
uint32_t  broadcast_add,
int  port 
)

Create a particle socket.

This function creates a UDP socket.

If both localip and broadcast_add are 0, the socket_open function will call p_util_get_local_addresses to get all local IP-address and the according local broadcast-address. Libparticle will then send packets to all found network devices. If you set one specified address, libparticle will send packets only to this single network device.

The first time a receive- or send-function is called, the socket will be bound.

Parameters:
port Port for sending or receiving.
localip IP-address of the computer, which runs the libparticle.
broadcast_add Broadcast-address of the local network.
localip and broadcast_add must be in network byte order. Use the socket function "htonl" if they aren't.

Default values for the socket options: SOCKET_BROADCAST -> On (1)
SOCKET_BLOCKING -> On (1)
SOCKET_RECV_ALL -> Off (0)
SOCKET_FRAG -> Off (0)
SOCKET_FILTER_DUPS -> Off (0)
SOCKET_AUTOACK -> Off (0)

Returns:
Particle socket descriptor
See also:
p_util_get_local_interfaces

p_socket_set_option

struct p_packet* p_socket_recv ( int  recv_sock,
int  send_sock 
)

Receive data.

Receive data from socket sock. Received data will be parsed to a CL-packet before it will be passed to the user. Acknowledges will be send automatically if autoack was set to 1.

Parameters:
recv_sock Particle socket descriptor used for receiving
send_sock Particle socket descriptor used for sending ACK packets...
Returns:
Pointer to a cl-packet on success or NULL on error.
If recv_socket is in blocking mode, p_socket_recv will not finish until a package was received. If the socket is not in blocking mode, p_socket_recv will return NULL if no incoming data is available at the socket.

Throws exception EAGAIN if no data has been received (you can ignore this [in most cases] when receiving with a non-blocking socket) or if a received packet was addressed to an other particle-ID. Throws exception EILSEQ if libparticle could not parse received data into a CL-packet. Throws exception EILSEQ if the received packet was not for your particle-ID and you didn't set the option "receive all".

struct p_packet* p_socket_recv_filtered ( int  recv_sock,
int  send_sock,
int  recv_filter 
)

Receive data filtered.

Receive data from socket sock. Received data will be filtered with recv_filter.

Parameters:
recv_sock Particle socket descriptor used for receiving
send_sock Particle socket descriptor used for sending ACK packets...
recv_filter Filter, with which the received data should be filtered
Returns:
Pointer to a cl-packet on success or NULL on error. Also NULL if a packet was received but the recv_filter didn't match.
If recv_socket is in blocking mode, p_socket_recv_filtered will not finish until a package was received. If the socket is not in blocking mode, p_socket_recv_filtered will return NULL if no incoming data is available at the socket.

Throws exception EAGAIN when a packet was received, but it did not match with the given filter or when no data was received.

int p_socket_recv_raw ( int  sock,
char *  data,
size_t  maxlen 
)

Receive raw data.

Receive raw data from socket sock.

Parameters:
sock Particle socket descriptor
*data Pointer to the data buffer where received data is stored
maxlen Size of data buffer
Returns:
Number of received bytes on success or -1 on error.
If sock is in blocking mode, p_socket_recv_raw will not finish until a package was received. If the socket is not in blocking mode, p_socket_recv_raw will return 0 if no incoming data is available at the socket.

Throws exception ENOTCONN when sock is not bound and it was not possible to bind it.

int p_socket_send ( int  send_sock,
struct p_packet *  send_data 
)

Send data. Send CL-packet send_data on socket send_sock.

Parameters:
send_sock Particle socket descriptor
send_data Pointer to a CL packet that should be send.
Returns:
1 if send to at least on network device (even if it was a loopback-device) was successfull or -1 on error.
Throws exception EPROTO when send_data has no ACL-tuple (please add an ACL-tuple and try again) or while trying to send a fragmented packet (please use p_socket_send_acked or p_socket_send_addressed).

int p_socket_send_acked ( int  send_sock,
int  recv_sock,
struct p_packet *  send_data,
const uint8_t *  add 
)

Send data to a particle specified by its ID and wait for ACK control message.

Send data to a particle specified by its ID and wait for ACK control message. Resend packet if ACK is not received within timeout. The necessary control message ACL Types will be added automatically.

Parameters:
send_sock Particle socket descriptor used for sending CL packets
recv_sock Particle socket descriptor used for receiving ACK packets
send_data Pointer to a CL packet that should be send.
add Pointer to an array containing the receivers ID, can be NULL iff the packet already contains a CAD tuple.
See also:
p_socket_set_retry

p_socket_send_raw

Returns:
1 if a not-fragmented packet has been send and sending to at least on network device (even if it was a loopback-device) was successfull or -1 on error. Returns a sendticket if a large (fragmented) packet has been send. Please use p_socket_get_send_status to get the current state of your fragmentation.
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception ENOMEM when attaching the CAD- and/or CAC-tuple to the packet failed. Probably the packet is to large. Throws exception EPROTO when packet was not acked.

int p_socket_send_acked_str ( int  send_sock,
int  recv_sock,
struct p_packet *  send_data,
const char *  addstr 
)

Send data to a particle specified by its ID and wait for ACK control message.

Send data to a particle specified by its ID and wait for ACK control message. Resend packet if ACK is not received within timeout. The necessary control message ACL Types will be added automatically.

Parameters:
send_sock Particle socket descriptor used for sending CL packets
recv_sock Particle socket descriptor used for receiving ACK packets
send_data Pointer to a CL packet that should be send.
addstr Dotted string containing the receivers ID can be NULL, iff the packet already contains a CAD tuple.
See also:
p_socket_set_retry

p_socket_send_raw

Returns:
1 if a not-fragmented packet has been send and sending to at least on network device (even if it was a loopback-device) was successfull or -1 on error. Returns a sendticket if a large (fragmented) packet has been send. Please use p_socket_get_send_status to get the current state of your fragmentation.
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception ENOMEM when attaching the CAD- and/or CAC-tuple to the packet failed. Probably the packet is to large. Throws exception EPROTO when packet was not acked.

int p_socket_send_addressed ( int  send_sock,
struct p_packet *  send_data,
uint8_t *  add 
)

Send data to a particle specified by its ID.

Send Data addressed to one particle, specified by its net ID. The necessary control message ACL Types will be added automatically.

If you send packets with large data (ACL-payload > 64 Byte, mayfrag must be set to 1 while adding the ACL-touple to the packet), p_socket_send_addressed will init an fragmented data transfer. That means, that the data for this packet will be send in more than one packets and will get re-assambled at the receiver. p_socket_send_addressed will send the first part of the data, and each time your program gets an ack from the receiver, it will send the next part until the complete data has been transfered.

Socket option SOCKET_FRAG msut be set to 1 at the sender as well as the receiver!

For sending the complete data, you need a program like this:

 p_socket_set_option(sendsock, SOCKET_FRAG, 1);
 sendticket = p_socket_send_addressed(sendsock, packet, address);
 do
 {
      p_socket_recv(recvsock, sendsock);
 }
 while (p_socket_get_send_status(sendticket) == P_SEND_ACTIVE)

Parameters:
send_sock Particle socket descriptor
send_data Pointer to a CL packet that should be send.
add Array containing the receivers ID
Returns:
1 if a not-fragmented packet has been send and sending to at least on network device (even if it was a loopback-device) was successfull or -1 on error. Returns a sendticket if a large (fragmented) packet has been send. Please use p_socket_get_send_status to get the current state of your fragmentation.
See also:
p_socket_send_raw

p_socket_get_send_status

p_socket_set_option

Throws exception ENOMEM when attaching the CAD-tuple to the packet failed. Probably the packet is to large.

int p_socket_send_addressed_str ( int  send_sock,
struct p_packet *  send_data,
const char *  add_str 
)

Send data to a particle specified by its ID.

Send Data addressed to one particle, specified by its net ID. The necessary control message ACL Types will be added automatically.

Parameters:
send_sock Particle socket descriptor
send_data Pointer to a CL packet that should be send.
add_str dotted string containing the receivers ID
Returns:
1 if a not-fragmented packet has been send and sending to at least on network device (even if it was a loopback-device) was successfull or -1 on error. Returns a sendticket if a large (fragmented) packet has been send. Please use p_socket_get_send_status to get the current state of your fragmentation.
See also:
p_socket_send_raw
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception ENOMEM when attaching the CAD-tuple to the packet failed. Probably the packet is to large.

int p_socket_send_buffer ( int  fd_out,
int  fd_in,
const char *  buf,
uint32_t  len,
const uint8_t *  sendto,
const uint8_t *  acl_type 
)

Sending a data puffer to a particle.

Send a data-buffer to a particle specified by its ID. The buffer will be send in fragments.

The socket frag-option will be set to 1 for both sockets before sending the first packet.

Parameters:
fd_out Particle socket descriptor used for sending the frag-packets
fd_in Particle socket descriptor used for receiving frag-packets. NOTE: You can place NULL in here, but then you have to set the frag_option yourself!
buf Pointer to the buffer, which holds the data you want to send.
len Length of the data stored in buf
sendto Pointer to an array containing the receivers ID
acl_type Pointer to an array containing the ACL-type, which should be the subject of all packets send for this fragmentation.
See also:
p_socket_set_option

P_SOCKET_OPTIONS

p_socket_send_raw

Returns:
Returns a sendticket. Please use p_socket_get_send_status to get the current state of your fragmentation.
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception EBADF fd_out is in blocking mode.

int p_socket_send_buffer_str ( int  fd_out,
int  fd_in,
const char *  buf,
uint32_t  len,
const char *  sendto,
const char *  acl_type 
)

Sending a data puffer to a particle [ID and ACL as string].

Send a data-buffer to a particle specified by its ID. The buffer will be send in fragments.

The socket frag-option will be set to 1 for both sockets before sending the first packet.

Parameters:
fd_out Particle socket descriptor used for sending the frag-packets
fd_in Particle socket descriptor used for receiving frag-packets. NOTE: You can place NULL in here, but then you have to set the frag_option yourself!
buf Pointer to the buffer, which holds the data you want to send.
len Length of the data stored in buf
sendto dotted string containing the receivers ID
acl_type ACL-Type which should be the subject of all packets send for this fragmentation.
See also:
p_socket_set_option

P_SOCKET_OPTIONS

p_socket_send_raw

p_frag_get_status

Returns:
Returns a sendticket. Please use p_socket_get_send_status to get the current state of your fragmentation.
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception EBADF fd_out is in blocking mode.

int p_socket_send_file ( int  fd_out,
int  fd_in,
const char *  filename,
const uint8_t *  sendto,
const uint8_t *  acl_type 
)

Sending data from a file to a particle.

Sends the data stored in a file to the particle specified by ID. The file will be copied to a buffer and send in fragments.

The socket frag-option will be set to 1 for both sockets before sending the first packet.

Parameters:
fd_out Particle socket descriptor used for sending the frag-packets
fd_in Particle socket descriptor used for receiving frag-packets. NOTE: You can place NULL in here, but then you have to set the frag_option yourself!
filename Name of the file, from that the data should be send.
sendto Pointer to an array containing the receivers ID
acl_type Pointer to an array containing the ACL-type, which should be the subject of all packets send for this fragmentation.
See also:
p_socket_set_option

P_SOCKET_OPTIONS

p_socket_send_raw

p_frag_get_status

Returns:
Returns a sendticket. Please use p_socket_get_send_status to get the current state of your fragmentation.
see p_socket_send_addressed for mor information about sending large data
See also:
p_socket_send_addressed
Throws exception EBADF fd_out is in blocking mode.

int p_socket_send_raw ( int  sock,
const char *  data,
size_t  len 
)

Send raw data.

This function will be used by all other send functions (p_socket_send*) for sending a packet to the network. The packet will be sond on ALL devices specified at dest_addr of the socket sock. If you want to send the packet only on one single network device, you have to set this device explicit by using p_socket_set_ipdest

Parameters:
sock Particle socket descriptor
*data Pointer to the data buffer that should be send
len Size of data buffer
Returns:
1 if send to at least on network device (even if it was a loopback-device) was successfull or -1 on error.
See also:
p_socket_set_ipdest

int p_socket_set_autoack (  ) 

Function only available at libparticle older then V1.0.0. Replaced by p_socket_set_option

See also:
p_socket_set_option

int p_socket_set_blocking (  ) 

Function only available at libparticle older then V1.0.0. Replaced by p_socket_set_option

See also:
p_socket_set_option

int p_socket_set_broadcast (  ) 

Function only available at libparticle older then V1.0.0. Replaced by p_socket_set_option

See also:
p_socket_set_option

int p_socket_set_frag_option (  ) 

Function only available at libparticle older then V1.0.0. Replaced by p_socket_set_option

See also:
p_socket_set_option

int p_socket_set_id ( int  sock,
const uint8_t *  add 
)

Sets a particle sockets own net ID.

Sets the own net ID for socket sock to the value of the byte-array add. add must be the base address of an 8 byte long array.

Parameters:
sock Particle socket
add* Location, must be an 8 byte long array
Returns:
Zero on success or -1 on error

int p_socket_set_id_str ( int  sock,
const char *  addstr 
)

Sets a particle sockets own net ID.

Sets the own net ID for socket sock to the value of the dotted string addstr. addstr must be a dotted string including either 8 or 4 numbers between 0 and 255. If addstr includes 8 numbers, the net ID of socket sock will be set to exactly this net ID. If addstr includes only 4 numbers, the net ID will be set to the virtual net ID "1.1.1.1.addstr".

Parameters:
sock Particle socket
addstr Location, must be a dotted string including 44 numbers
Returns:
Zero on success or -1 on error

int p_socket_set_ipdest ( int  sock,
const struct in_addr *  address 
)

Set the destination-add for a socket.

Sets the IP-address, where the packets will be send to (broadcast, local broadcast, ...) Don't mix up with addressed sending!

Parameters:
sock Particle socket descriptor
address Address, where the packets should be brought to.
Returns:
0 on success, -1 on error

int p_socket_set_ipdest_all ( int  fd  ) 

Set the destination-add for a socket [string].

Sets the IP-address, where the packets will be send to (broadcast, local broadcast, ...) Don't mix up with addressed sending!

Parameters:
fd Particle socket
Returns:
0 on success, -1 on error

int p_socket_set_ipdest_str ( int  sock,
const char *  address 
)

Set the destination-add for a socket [string].

Sets the IP-address, where the packets will be send to (broadcast, local broadcast, ...) Don't mix up with addressed sending!

Parameters:
sock Particle socket descriptor
address Address, where the packets should be brought to. Must be a Pointer to a dotted string.
Returns:
0 on success, -1 on error

int p_socket_set_ipsrc ( int  sock,
const struct in_addr *  address 
)

Set the source-add for a socket.

Sets the IP-address, from where packets will be received. Don't mix up with addressed sending!

Parameters:
sock Particle socket descriptor
address Address, from where packets should be received.
Returns:
0 on success, -1 on error

int p_socket_set_ipsrc_all ( int  sock  ) 

Set a Socket to receive all-mode.

Socket will receive packets from any source-address.

Parameters:
sock Particle socket descriptor
Returns:
0 on success, -1 on error

int p_socket_set_ipsrc_str ( int  sock,
const char *  address 
)

Set the source-add for a socket [string].

Sets the IP-address, from where packets will be received. Don't mix up with addressed sending!

Parameters:
sock Particle socket descriptor
address Address, from where packets should be received. Must be a Pointer to a dotted string.
Returns:
0 on success, -1 on error

int p_socket_set_lastacks ( int  counter  ) 

Set the number of packets, which should be stored to find doublets of acking-packets.

Set the number of acked packets, which should be hold in a queue an be compared with new received ack-packets to find doublets.

Parameters:
counter Maximum number of packets that should be hold in the queue
Returns:
Always 1

int p_socket_set_lastdups ( int  counter  ) 

Set the number of packets, which should be stored to find doublets.

Set the number of acked packets, which should be hold in a queue an be compared with new received packets to find doublets.

Parameters:
counter Maximum number of packets that should be hold in the queue
Returns:
Always 1

int p_socket_set_loc ( int  sock,
const uint8_t *  loc 
)

Sets a particle sockets location-ID.

Sets the Location-ID for socket sock to the value of the byte-array loc. loc must be the base address of a 44 byte long array.

Parameters:
sock Particle socket
loc* Location, must be a 44 byte long array
Returns:
Zero on success or -1 on error

int p_socket_set_loc_str ( int  sock,
const char *  locstr 
)

Sets a particle sockets location-ID.

Sets the Location-ID for socket sock to the value of the dotted string locstr. locstr must be a dotted string including 44 numbers between 0 and 255.

Parameters:
sock Particle socket
locstr Location, must be a dotted string including 44 numbers
Returns:
Zero on success or -1 on error

int p_socket_set_num_interfaces ( int  fd,
int  counter 
)

Sets the number of interfaces, a socket will send to.

Sets the number of interfaces, a socket sends to. Counter must be smaller than the current number of interfaces. This function is especially usefull, if you want a socket, which has been opened by default values, only to send to the first found network device.

Parameters:
fd Pointer to the socket from which you want to set the number of interfaces
counter New number of interfaces the socket will send to.

int p_socket_set_option ( int  fd,
int  option,
int  mode 
)

Sets a socket-option.

Sets the state of the socket-option specified by option to 0 or 1 (specified by mode). For Available options, see P_SOCKET_OPTIONS If you want to set more than one option to the same value at one time, you can concated them with |

p_socket_set_option replaces several funtions from libparticle < 1.0.0:

p_socket_set_broadcast, p_socket_set_blocking, p_socket_set_recv_option, p_socket_set_frag_option and p_socket_set_autoack. Please make the following changes in your programs:

You can also set several options at the same time if you want to set them to the same value. For example:

can be done by

Parameters:
fd Particle socket
option The option you want to set
mode 1 if option should be set to "YES" or 0 if option should be set to "no"
Returns:
0 on success or -1 on error
See also:
P_SOCKET_OPTIONS

int p_socket_set_recv_option (  ) 

Function only available at libparticle older then V1.0.0. Replaced by p_socket_set_option

See also:
p_socket_set_option

int p_socket_set_retry ( int  sock,
uint8_t  retries,
uint32_t  timeout 
)

Sets the parameters for acknowledged sending.

Sets the number of retries and the time until timeout (per retry) for acknowledged sending.

Parameters:
sock Particle socket
retries Number of retries which should be done if no ack-packet is received
timeout Time (in milliseconds), how long the particle waits for the ack-packet after each retry.
Returns:
Zero on success or -1 on error


Generated on Tue Apr 10 15:22:26 2007 for libparticle by  doxygen 1.5.1