-1

I have to send a ISO8583 message to an acquirer server and the switch want me to send the message with the APDU length before my whole message but i do not know how to send. The length is 4 bytes.

Example: i want to send the message (PAN-Expiry Date) 4427680000628820 1014

Header:30353530 Message:44276800006288201014

I want to send this through the socket: 30353530(00000014=20 in decimal) 4427680000628820 (PAN) 1014 (Exp)

Which should give me: 303535300000001444276800006288201014

Actually i do like this

buf[0]=0x30
buf[1]=0x35
buf[2]=0x35
buf[3]=0x30

How to add the length 00000014 after buf[3]?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
knk
  • 45
  • 2
  • 9

2 Answers2

0

You can simply continue as you did with your first 4 bytes: Assuming your total message length, in your example 0x00000014, is stored in the 32 bit variable "len", add the length header with

buf[4] = (uint8_t)((len >> 24ul) & 0xFF);
buf[5] = (uint8_t)((len >> 16ul) & 0xFF);
buf[6] = (uint8_t)((len >> 8ul) & 0xFF);
buf[7] = (uint8_t)(len & 0xFF);
TheMeanMan
  • 11
  • 2
-1

You can't "add length" to a char array in C. Whether static or dynamically allocated, the size is fixed - there is no way to simply make it bigger. You have to make a new larger array and copy the old bytes in.

char oldarray[4];
// fill it with stuff

// oops, too small
char newarray[8];
memcpy(newarray, oldarray, 4);

// move on with things
Rakurai
  • 974
  • 7
  • 15