Click here to Skip to main content
15,898,036 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCrystal Reports 2011 with C++/MFC Dev Studio 2010 Pin
Member 983646924-Apr-13 18:42
Member 983646924-Apr-13 18:42 
QuestionAudio in DirectShow Pin
Sachin k Rajput 24-Apr-13 17:40
Sachin k Rajput 24-Apr-13 17:40 
AnswerRe: Audio in DirectShow Pin
Vaclav_25-Apr-13 3:03
Vaclav_25-Apr-13 3:03 
QuestionHow to create 4 dimenstional array Pin
jothivel k24-Apr-13 9:07
jothivel k24-Apr-13 9:07 
AnswerRe: How to create 4 dimenstional array Pin
Richard MacCutchan24-Apr-13 9:33
mveRichard MacCutchan24-Apr-13 9:33 
AnswerRe: How to create 4 dimenstional array Pin
pasztorpisti24-Apr-13 9:45
pasztorpisti24-Apr-13 9:45 
GeneralRe: How to create 4 dimenstional array Pin
jothivel k25-Apr-13 7:12
jothivel k25-Apr-13 7:12 
GeneralRe: How to create 4 dimenstional array Pin
pasztorpisti25-Apr-13 20:48
pasztorpisti25-Apr-13 20:48 
AnswerRe: How to create 4 dimenstional array Pin
Stefan_Lang24-Apr-13 22:15
Stefan_Lang24-Apr-13 22:15 
AnswerRe: How to create 4 dimenstional array Pin
Joe Woodbury25-Apr-13 6:47
professionalJoe Woodbury25-Apr-13 6:47 
Questioniso_8583 message Pin
khushboo gupta23-Apr-13 0:16
khushboo gupta23-Apr-13 0:16 
AnswerRe: iso_8583 message Pin
Marco Bertschi23-Apr-13 1:53
protectorMarco Bertschi23-Apr-13 1:53 
GeneralRe: iso_8583 message Pin
khushboo gupta23-Apr-13 20:05
khushboo gupta23-Apr-13 20:05 
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 

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.