P1sec / pysctp

SCTP stack for Python
http://www.p1sec.com
161 stars 67 forks source link

[Query] Received data len from sctp_recv API #28

Closed gchatur closed 5 years ago

gchatur commented 5 years ago

Hi, I am using sctp_recv() API of the sctpsocket class in my server-client program. Can you please let me know to know the length of the received data from the API sctp_recv()?

Thanks

p1-bmu commented 5 years ago

This is the help of the high-level sctpsocket object (obtained with sctp.sctpsocket_tcp() or sctp.sctpsocket_udp()):

 |  sctp_recv(self, maxlen)
 |      Receives an SCTP message and/or a SCTP notification event. The notifications
 |      that can be received are regulated by "events" property and its subproperties.
 |      See event_subscribe() class for details.
 |      
 |      It is important to know that sctp_recv() can return either on data messages or
 |      on subscribed events. If the application just wants data, it must unsubscribe
 |      the other events.
 |      
 |      Parameters;
 |      
 |      maxlen: the maximum message size that can be received. If bigger messages are
 |      received, they will be received in fragments (non-atomically). The application 
 |      must choose this carefully if it wants to keep the atomicity of messages!
 |      
 |      Returns: (fromaddr, flags, msg, notif)
 |      
 |      fromaddr: address/port pair. For some applications, association ID will be more
 |                useful to identify the related association. Fortunately, assoc_id is
 |                a attribute of most notifications received via "notif" (see below)
 |      
 |      flags: a bitmap of lower-level recvmsg() flags (FLAG_* flags).  
 |      
 |              FLAG_NOTIFICATION indicates that an event notification was 
 |              returned, instead of a data message.
 |      
 |              FLAG_EOR indicates that this is the final fragment of a data message.
 |              Ideally, all messages will come with this flag set.
 |      
 |             WARNING: message data-related flags like MSG_UNORDERED are returned
 |             inside sndrcvinfo() notifications, and NOT here!
 |      
 |      msg: the actual data message. Since SCTP does not allow empty messages,
 |           an empty "msg" always means something special, either:
 |      
 |              a) that "notif" contains an event notificatoin, if "flags" has 
 |                 FLAG_NOTIFICATION set;
 |      
 |              b) that association is closing (for TCP-style sockets only)
 |      
 |      notif: notification event object. If "msg" is a data message, it will contain
 |             a sndrcvinfo() object that contains metadata about the message. If 
 |             "flags" has FLAG_NOTIFICATION set, it will contain some notification()
 |             subclass.
 |      
 |             sndrcvinfo() is ALWAYS returned when a data message is received, but
 |             it will only contain useful data IF events.data_io is subscribed True.
 |      
 |      WARNING: the maximum message size that can be received via SCTP is limited:
 |      
 |      * by the underlying implementation. Check your operating system.
 |      
 |      * by the "maxlen" parameter passed. If message is bigger, it will be received
 |        in several fragments. The last fragment will have FLAG_EOR flag set.
 |      
 |      * by the socket's reception buffer (SO_SNDRCV). The application must configure 
 |        this buffer accordingly, otherwise the message will be truncacted.
 |  

From here, if you want to know the length of the received data, you can simply use len(msg) after sctp_recv() returns.