3. Unpackaging function of data structures

The function smpp34_unpack( ... ) takes four parameters and returns an integer value that describes the operation result. A value distinct of 0 (zero) is an internal error in the unpackaging attempt. Then there is a text description in the global variable smpp34_strerror.

extern int smpp34_errno;
extern char smpp34_strerror[2048];

int smpp34_unpack( uint32_t type,   /* in  */
                   void    *tt,     /* out */
                   uint8_t *ptrBuf, /* in  */
                   int     ptrLen,  /* in  */ )
    
Where:

type: This parameter is the PDU command_id that we want to unpack, the value of this parameter is related to data structure described in the introduction.

tt: It's a pointer to one of the data structures listed in the introduction and it corresponds to the first parameter value. The pointer to that structure describes where the content of the buffer is to be stored.

ptrBuf: Is a buffer pointer, where the packaged PDU is stored and is ready to be processed.

ptrLen: This variable refers to the buffer lenght above described.

3.1. An example

Here you have a small example on how to use the function. The creation of a buffer with binary data, the unpack function call and the information load over a data structure is showed.

Example 2. Unpack and dumpPdu examples.

#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <netinet/in.h>
#include "smpp34.h"
#include "smpp34_structs.h"
#include "smpp34_params.h"

char bufPDU[] = { 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x01, 
                  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 
                  0x73, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x5F, 0x69, 
                  0x64, 0x00, 0x70, 0x61, 0x73, 0x73, 0x00, 0x73, 
                  0x79, 0x73, 0x74, 0x65, 0x00, 0x00, 0x02, 0x01, 
                  0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x5F, 
                  0x72, 0x61, 0x6E, 0x67, 0x65, 0x00 };

int  bufPDULen = 0;
char bPrint[2048];

int main( int argc, char *argv[] )
{

    int  ret = 0;
    bind_receiver_t pdu;
    uint32_t tempo;
    uint32_t cmd_id;

    /* Init PDU ***********************************************************/
    memset(&pdu, 0, sizeof(bind_receiver_t));
    memset(&bPrint, 0, sizeof(bPrint));
    memcpy(&tempo, bufPDU+4, sizeof(uint32_t));
    cmd_id = ntohl( tempo );

    /* unpack PDU *********************************************************/
    ret = smpp34_unpack(cmd_id, (void*)&pdu, bufPDU, sizeof(bufPDU));
    if( ret != 0){
        printf( "Error in smpp34_unpack():%d:%s\n",
                smpp34_errno, smpp34_strerror);
        return( -1 );
    };

    /* Print PDU **********************************************************/
    memset(bPrint, 0, sizeof(bPrint));
    ret = smpp34_dumpPdu(cmd_id, bPrint, sizeof(bPrint), (void*)&pdu );
    if( ret != 0){
        printf( "Error in smpp34_dumpPdu():%d:%s\n",
                smpp34_errno, smpp34_strerror );
        return( -1 );
    };
    printf("The received PDU: \n%s\n", bPrint);

    return( 0 );
};

    
At the last, this example is refered from the description of smpp34_dumpPdu( ... ).

This example is compiled by:

[rtremsal@localhost dist]$ gcc -o ll ll.c -I ./include -static -L ./lib -lsmpp34
[rtremsal@localhost dist]$ ./ll
El PDU recibido es: 
command_length                [00000036] - [54]
command_id                    [00000001] - [BIND_RECEIVER]
command_status                [00000000] - [ESME_ROK]
sequence_number               [00000001] - [1]
system_id                     [system_id]
password                      [pass]
system_type                   [syste]
interface_version             [00]       - [0]
addr_ton                      [02]       - [TON_National]
addr_npi                      [01]       - [NPI_ISDN_E163_E164]
address_range                 [address_range]