Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: iso_8583 message Pin
Marco Bertschi23-Apr-13 21:39
protectorMarco Bertschi23-Apr-13 21:39 
GeneralMessage Closed Pin
23-Apr-13 20:13
khushboo gupta23-Apr-13 20:13 
GeneralRe: iso_8583 message Pin
Richard MacCutchan23-Apr-13 21:50
mveRichard MacCutchan23-Apr-13 21:50 
GeneralMessage Closed Pin
23-Apr-13 22:54
khushboo gupta23-Apr-13 22:54 
GeneralRe: iso_8583 message Pin
Richard MacCutchan23-Apr-13 23:02
mveRichard MacCutchan23-Apr-13 23:02 
GeneralRe: iso_8583 message Pin
khushboo gupta24-Apr-13 20:17
khushboo gupta24-Apr-13 20:17 
GeneralRe: iso_8583 message Pin
Jochen Arndt24-Apr-13 21:13
professionalJochen Arndt24-Apr-13 21:13 
GeneralRe: iso_8583 message Pin
khushboo gupta24-Apr-13 22:32
khushboo gupta24-Apr-13 22:32 
I am using the below code for packing the data in iso 8583 format

00 2E 60 01 23 06 00 08 00 20 20 01 00 00 c0 00
00 92 00 00 00 00 12 01 23 48 30 30 30 30 30 30
39 53 31 30 30 30 30 30 30 30 30 30 30 30 30 35

C++
#include <WS2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#include <WinSock.h>
#include <wchar.h>
#include <string.h>

char cHexDigit_to_Nibble1(unsigned char c)
{
if(!isxdigit(c))
    return (0);
if(isdigit(c))
    return (c - '0');
c = toupper(c);

return (c - 55);
}

void vAscii2BCD(unsigned char *pucSrc, unsigned char *pucDst, int inSize)
{

for (; inSize > 0; inSize -= 2, pucDst++)
{
    if(!memcmp(pucSrc, "3D", 2))
    {
        pucSrc += 2;
        *pucDst = '=';
    }

    else
    {
        *pucDst = cHexDigit_to_Nibble1(*pucSrc++) << 4;
        *pucDst |= cHexDigit_to_Nibble1(*pucSrc++);
    }
}
printf("data is %s\n\n",pucDst);
}

int main()
{
int sock_desc, status;
struct sockaddr_in client;
struct addrinfo hints;
WSADATA Data;
    int bytesSent;
    int bytesRecv = SOCKET_ERROR;

unsigned char *pucSrc  = (unsigned char*) malloc (100) ;
unsigned char *pucDst  = (unsigned char*) malloc (256) ;

memset(pucSrc,0,256);

memset(pucDst,0,256);
vAscii2BCD((unsigned char*)"00" ,pucDst, 1) ;//
strcpy((char*)pucSrc,(char*)pucDst) ;


memset(pucDst,0,256);
vAscii2BCD((unsigned char*)"2E" ,pucDst, 1) ;//
//vAscii2BCD((unsigned char*)"002E" ,pucDst, 4) ;//
strcat((char*)pucSrc,(char*)pucDst) ;


memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)"60012306  " ,pucDst, 12) ;//
vAscii2BCD((unsigned char*)"6001230600" ,pucDst, 5) ;//
strcat((char*)pucSrc,(char*)pucDst) ;

memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)" 8 " ,pucDst, 4) ;//48564848
vAscii2BCD((unsigned char*)"0800" ,pucDst, 2) ;//48564848
strcat((char*)pucSrc,(char*)pucDst);


memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)"2020010000C00000" ,pucDst, 16) ;
vAscii2BCD((unsigned char*)"2020010000" ,pucDst, 5) ;
strcat((char*)pucSrc,(char*)pucDst);



memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)"2020010000C00000" ,pucDst, 16) ;
vAscii2BCD((unsigned char*)"C00000" ,pucDst, 3) ;
strcat((char*)pucSrc,(char*)pucDst);



memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)"92" ,pucDst, 2) ;//575048484848
vAscii2BCD((unsigned char*)"920000" ,pucDst, 3) ;
strcat((char*)pucSrc,(char*)pucDst);
//strcat((char*)pucSrc,"00000000") ;
printf("size of pucSrc = %d\n", strlen((char*)pucSrc));

//memset(pucDst,0,256);
vAscii2BCD((unsigned char*) "0000" ,pucDst, 2) ;
strcat((char*)pucSrc,(char*)pucDst) ;
printf("size of pucSrc = %d\n", strlen((char*)pucSrc));

memset(pucDst,0,256);
vAscii2BCD((unsigned char*) "12" ,pucDst, 1) ;//4848484950
strcat((char*)pucSrc,(char*)pucDst) ;

memset(pucDst,0,256);
//vAscii2BCD((unsigned char*)" 123" ,pucDst, 3) ;//48495051
vAscii2BCD((unsigned char*)"0123" ,pucDst, 3) ;//48495051
strcat((char*)pucSrc,(char*)pucDst) ;
//strcat((char*)pucSrc,"4830303030303039533130303030303030303030303035") ;
strcat((char*)pucSrc,"H0000009S10000000000005");

printf("size of pucSrc = %d\n", strlen((char*)pucSrc));


status = WSAStartup(MAKEWORD(2, 2), &Data);
if(status != 0)
{
    printf("ERROR: WSAStartup unsuccessful");
    return 0;
}
else
{
    printf("WSAStartup Successfull\n");
}

sock_desc = socket(AF_INET,SOCK_STREAM,0);
if ( sock_desc == INVALID_SOCKET ) {
    printf( "Error at socket(): %ld\n", WSAGetLastError() );
    WSACleanup();
    return;
}

// Connect to a server.
client.sin_family = AF_INET;
client.sin_addr.s_addr = inet_addr( "41.208.68.76" );
client.sin_port = htons( 4444 );

if(connect(sock_desc,(struct sockaddr*)&client,sizeof(client)) == SOCKET_ERROR) {
    printf( "Failed to connect.\n" );
    WSACleanup();
    return;
} else{
    printf("connect successfull\n");
}

bytesSent = send( sock_desc, pucSrc, strlen(pucSrc), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );

while( bytesRecv == SOCKET_ERROR ) {
    bytesRecv = recv( sock_desc, recvbuf, 256, 0 );
    if ( bytesRecv == 0 || bytesRecv == WSAECONNRESET ) {
        printf( "Connection Closed.\n");
        break;
    }
    printf( "Bytes Recv: %ld\n", bytesRecv );
    if (bytesRecv < 0)
        return;
    printf( "Bytes Recv: %ld\n", bytesRecv );
  }

  return 0;
}


when I was analyzing the packet through wireshark I was getting the packet in the server side like below :

2E 60 01 23 06 08 20 20 01 c0 00
92 12 01 23 48 30 30 30 30 30 30
39 53 31 30 30 30 30 30 30 30 30
30 30 30 30 35

Why all 00 bytes are not getting sent.
GeneralRe: iso_8583 message Pin
Richard MacCutchan24-Apr-13 22:58
mveRichard MacCutchan24-Apr-13 22:58 
QuestionMCI wave player Pin
Vijay Ku. Soni23-Apr-13 0:15
Vijay Ku. Soni23-Apr-13 0:15 
AnswerRe: MCI wave player Pin
Marco Bertschi23-Apr-13 2:32
protectorMarco Bertschi23-Apr-13 2:32 
QuestionCDaoDatabase for Opening MS-Access Pin
D.Manivelan22-Apr-13 23:32
D.Manivelan22-Apr-13 23:32 
AnswerRe: CDaoDatabase for Opening MS-Access Pin
Jochen Arndt23-Apr-13 0:03
professionalJochen Arndt23-Apr-13 0:03 
QuestionMulti Threaded ::ShowWindow(...) Pin
Bram van Kampen22-Apr-13 13:58
Bram van Kampen22-Apr-13 13:58 
AnswerRe: Multi Threaded ::ShowWindow(...) Pin
«_Superman_»22-Apr-13 17:07
professional«_Superman_»22-Apr-13 17:07 
QuestionRe: Multi Threaded ::ShowWindow(...) Pin
David Crow23-Apr-13 4:53
David Crow23-Apr-13 4:53 
AnswerRe: Multi Threaded ::ShowWindow(...) Pin
«_Superman_»23-Apr-13 17:35
professional«_Superman_»23-Apr-13 17:35 
GeneralRe: Multi Threaded ::ShowWindow(...) Pin
David Crow24-Apr-13 2:07
David Crow24-Apr-13 2:07 
Questionget all domains form adsi forest Pin
venkatesh5286722-Apr-13 0:29
venkatesh5286722-Apr-13 0:29 
QuestionThreads and messages - is this legal? Pin
charlieg21-Apr-13 15:31
charlieg21-Apr-13 15:31 
AnswerRe: Threads and messages - is this legal? Pin
pasztorpisti21-Apr-13 19:28
pasztorpisti21-Apr-13 19:28 
GeneralRe: Threads and messages - is this legal? Pin
charlieg22-Apr-13 4:34
charlieg22-Apr-13 4:34 
GeneralRe: Threads and messages - is this legal? Pin
pasztorpisti22-Apr-13 6:46
pasztorpisti22-Apr-13 6:46 
GeneralRe: Threads and messages - is this legal? Pin
charlieg22-Apr-13 11:20
charlieg22-Apr-13 11:20 
GeneralRe: Threads and messages - is this legal? Pin
PJ Arends22-Apr-13 12:00
professionalPJ Arends22-Apr-13 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.