The function smpp34_pack( ... )
takes five parameters
and returns an integer value that describes the operation result. A value
distinct of 0 (zero) is represetative of an error in the packaging attempt.
Then there is a description in text mode in the global variable
smpp34_strerror
.
extern int smpp34_errno; extern char smpp34_strerror[2048]; int smpp34_pack( uint32_t type, /* in */ uint8_t *ptrBuf, /* out */ int ptrSize, /* out */ int *ptrLen, /* out */ void *tt /* in */ ) |
type: is the PDU command_id that we want to pack, the parameter value is related to a specific data structure.
ptrBuf: is a buffer reference, where we will store the PDU packaged. The memory must be reserved externally, it would be dynamic or static memory, but the function is not responsible for free any dynamic memory passed as a parameter.
ptrSize: This parameter is a integer that describes the buffer lenght where we will store de PDU packaged (the previus parameter).
ptrLen: In a success case, this variable keep the data lenght in the buffer. Obviously always ptrLen < ptrSize.
tt: It's a reference to any data structure listed in the introduction, and corresponds to the value of the first parameter.
We'll see a small example to use this function, the creation of data object, the load of information in data structure and the pack in a buffer are detailed in this example.
Example 1. Pack and dumpBuff example.
#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[2048]; int bufPDULen = 0; char bPrint[2048]; int main( int argc, char *argv[] ) { int ret = 0; bind_transmitter_t pdu; /* Init PDU */ memset(&pdu, 0, sizeof(bind_transmitter_t)); pdu.command_length = 0; pdu.command_id = BIND_TRANSMITTER; /* defined in smpp34.h */ pdu.command_status = ESME_ROK; /* defined in smpp34.h */ pdu.sequence_number = 1; snprintf(pdu.system_id, sizeof(pdu.system_id), "%s", "user"); snprintf(pdu.password, sizeof(pdu.password), "%s", "pass"); snprintf(pdu.system_type, sizeof(pdu.system_type), "%s", "type"); pdu.interface_version = SMPP_VERSION; pdu.addr_ton = 2; pdu.addr_npi = 1; snprintf(pdu.address_range, sizeof(pdu.address_range), "%s", "123"); /* Linealize PDU to buffer */ memset(&bufPDU, 0, sizeof(bufPDU)); ret = smpp34_pack( pdu.command_id, bufPDU, sizeof(bufPDU), &bufPDULen, (void*)&pdu); if( ret != 0 ){ printf("Error in smpp34_pack():%d:\n%s\n", smpp34_errno, smpp34_strerror); return( -1 ); }; /* Print Buffer */ memset(bPrint, 0, sizeof(bPrint)); ret = smpp34_dumpBuf(bPrint, sizeof(bPrint), bufPDU, bufPDULen); if( ret != 0 ){ printf("Error in smpp34_dumpBuf():%d:\n%s\n", smpp34_errno, smpp34_strerror ); return( -1 ); }; printf("The PDU bind_transmitter is packet in\n%s", bPrint); return( 0 ); }; |
[rtremsal@localhost dist]$ gcc -o lo lo.c -I./include -static -L./lib -lsmpp34 [rtremsal@localhost dist]$ ./lo The PDU bind_transmitter is packet in 00 00 00 26 00 00 00 02 00 00 00 00 00 00 00 01 ...&.... ........ 75 73 65 72 00 70 61 73 73 00 74 79 70 65 00 34 user.pas s.type.4 02 01 31 32 33 00 ..123. |