Click here to Skip to main content
15,891,372 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: working with byte arrays Pin
jkirkerx22-Oct-11 15:46
professionaljkirkerx22-Oct-11 15:46 
AnswerRe: working with byte arrays Pin
Albert Holguin22-Oct-11 12:02
professionalAlbert Holguin22-Oct-11 12:02 
GeneralRe: working with byte arrays Pin
jkirkerx22-Oct-11 15:51
professionaljkirkerx22-Oct-11 15:51 
AnswerRe: working with byte arrays Pin
Richard MacCutchan22-Oct-11 21:46
mveRichard MacCutchan22-Oct-11 21:46 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 8:07
professionaljkirkerx23-Oct-11 8:07 
GeneralRe: working with byte arrays Pin
Richard MacCutchan23-Oct-11 8:26
mveRichard MacCutchan23-Oct-11 8:26 
AnswerRe: working with byte arrays Pin
Erudite_Eric23-Oct-11 1:58
Erudite_Eric23-Oct-11 1:58 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 8:22
professionaljkirkerx23-Oct-11 8:22 
I write in vb, and without a doubt, I would pass the data to another function for processing, or just store the data, and process it later. In straight c++, most of the stuff seems pretty easy, but there are some really low level stuff you can get into that gets tricky.

I've never asked anyone to write code for me, but I'm really stuck trying to figure out how to pass the data to a another function. I will post my code, and the byte stream I get back, and perhaps someone could can spot the mistake I made, it might be something really small that I didn't get.

BOOL CA_SQLServer_Scan::_socket_Enumerate_SQLServers( void ) 
{
	int iResult;
    WSADATA wsaData;
	
	char recvbuf[256];
    int rv = 0; 
	int recvbuflen = 256;
	int bytesReceived = 0;
					    
    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (iResult != NO_ERROR) {
        return FALSE;
    }		
	//////////////////////////////////////////////////////////////////////////////////////
	// Send Data Socket
	SOCKET sUDPSocket = INVALID_SOCKET;
	struct sockaddr_in sTargetDevice;
	char cBuffer[] = {0x02};
	
	sUDPSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (sUDPSocket == INVALID_SOCKET) {
        int iSocketError = WSAGetLastError();
		goto wsaCleanup;
    }
   
	ZeroMemory( &sTargetDevice, sizeof(sTargetDevice));
    sTargetDevice.sin_family = AF_INET;
    sTargetDevice.sin_addr.s_addr = inet_addr( "192.168.3.255" );
	sTargetDevice.sin_port = htons( BROADCAST_SND_PORT );

	// Try a Connectionless Send Data first
	iResult = sendto(sUDPSocket, cBuffer, 1, 0, (SOCKADDR *) & sTargetDevice, sizeof (sTargetDevice));
    if (iResult == SOCKET_ERROR) {
        goto closeSocket;        
    }
	    
	// Shutdown the send socket for some reason
    iResult = shutdown(sUDPSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        goto closeSocket;
    }
	// End of Send Data Connection
	//////////////////////////////////////////////////////////////////////////////////////
	// Enumerate Return Packets	
	do {
        bytesReceived = recv(sUDPSocket, recvbuf, recvbuflen, 0);
        if ( bytesReceived > 0 ) {            
			char buf[256];
			recvbuf[bytesReceived] = '\0';
			memcpy(buf, recvbuf, bytesReceived);			
			_process_SQL_BufferData(buf, bytesReceived);						
		}
        else if ( bytesReceived == 0 ) {
            printf("Connection closed\n");
			goto closeSocket;
		}		
		else {
            printf("recv failed: %d\n", WSAGetLastError());
			goto closeSocket;
		}
    }	
	while( bytesReceived > 0 );
	// End of Enumerate Packets
	//////////////////////////////////////////////////////////////////////////////////////
closeSocket:	
	iResult = closesocket(sUDPSocket);
    if (iResult == SOCKET_ERROR) {
        goto wsaCleanup;       
    }	
wsaCleanup:
    WSACleanup();	
	return TRUE;
}

void CA_SQLServer_Scan::_process_SQL_BufferData( char pBuffer[256], int packetSize ) 
{	


}


The first data packet returned from the request, I put the \0 at the end in 87, perhaps not needed.
Bytestream - first 87 bytes of recvbuf.

recvbuf	0x0012f8a0 "T"	char [256]
	[0]	5 ''	char
	[1]	84 'T'	char
	[2]	0	char
	[3]	83 'S'	char
	[4]	101 'e'	char
	[5]	114 'r'	char
	[6]	118 'v'	char
	[7]	101 'e'	char
	[8]	114 'r'	char
	[9]	78 'N'	char
	[10]	97 'a'	char
	[11]	109 'm'	char
	[12]	101 'e'	char
	[13]	59 ';'	char
	[14]	68 'D'	char
	[15]	69 'E'	char
	[16]	76 'L'	char
	[17]	76 'L'	char
	[18]	67 'C'	char
	[19]	53 '5'	char
	[20]	50 '2'	char
	[21]	49 '1'	char
	[22]	45 '-'	char
	[23]	48 '0'	char
	[24]	49 '1'	char
	[25]	59 ';'	char
	[26]	73 'I'	char
	[27]	110 'n'	char
	[28]	115 's'	char
	[29]	116 't'	char
	[30]	97 'a'	char
	[31]	110 'n'	char
	[32]	99 'c'	char
	[33]	101 'e'	char
	[34]	78 'N'	char
	[35]	97 'a'	char
	[36]	109 'm'	char
	[37]	101 'e'	char
	[38]	59 ';'	char
	[39]	83 'S'	char
	[40]	81 'Q'	char
	[41]	76 'L'	char
	[42]	69 'E'	char
	[43]	88 'X'	char
	[44]	80 'P'	char
	[45]	82 'R'	char
	[46]	69 'E'	char
	[47]	83 'S'	char
	[48]	83 'S'	char
	[49]	59 ';'	char
	[50]	73 'I'	char
	[51]	115 's'	char
	[52]	67 'C'	char
	[53]	108 'l'	char
	[54]	117 'u'	char
	[55]	115 's'	char
	[56]	116 't'	char
	[57]	101 'e'	char
	[58]	114 'r'	char
	[59]	101 'e'	char
	[60]	100 'd'	char
	[61]	59 ';'	char
	[62]	78 'N'	char
	[63]	111 'o'	char
	[64]	59 ';'	char
	[65]	86 'V'	char
	[66]	101 'e'	char
	[67]	114 'r'	char
	[68]	115 's'	char
	[69]	105 'i'	char
	[70]	111 'o'	char
	[71]	110 'n'	char
	[72]	59 ';'	char
	[73]	49 '1'	char
	[74]	48 '0'	char
	[75]	46 '.'	char
	[76]	53 '5'	char
	[77]	48 '0'	char
	[78]	46 '.'	char
	[79]	49 '1'	char
	[80]	54 '6'	char
	[81]	48 '0'	char
	[82]	48 '0'	char
	[83]	46 '.'	char
	[84]	49 '1'	char
	[85]	59 ';'	char
	[86]	59 ';'	char
	[87]	0	char

GeneralRe: working with byte arrays Pin
Goto_Label_23-Oct-11 8:44
Goto_Label_23-Oct-11 8:44 
GeneralRe: working with byte arrays Pin
Richard MacCutchan23-Oct-11 9:02
mveRichard MacCutchan23-Oct-11 9:02 
GeneralRe: well done, you cracked the code Pin
App_23-Oct-11 9:06
App_23-Oct-11 9:06 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 9:18
professionaljkirkerx23-Oct-11 9:18 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 9:30
professionaljkirkerx23-Oct-11 9:30 
GeneralRe: working with byte arrays Pin
Richard MacCutchan23-Oct-11 9:38
mveRichard MacCutchan23-Oct-11 9:38 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 9:42
professionaljkirkerx23-Oct-11 9:42 
GeneralRe: working with byte arrays Pin
Richard MacCutchan23-Oct-11 9:56
mveRichard MacCutchan23-Oct-11 9:56 
GeneralRe: working with byte arrays Pin
jkirkerx23-Oct-11 10:06
professionaljkirkerx23-Oct-11 10:06 
GeneralRe: It's like watching a soap on TV! Oh the supense Pin
Goto_Label_23-Oct-11 10:15
Goto_Label_23-Oct-11 10:15 
GeneralRe: It's like watching a soap on TV! Oh the supense Pin
jkirkerx23-Oct-11 10:21
professionaljkirkerx23-Oct-11 10:21 
GeneralRe: working with byte arrays Pin
Richard MacCutchan23-Oct-11 22:19
mveRichard MacCutchan23-Oct-11 22:19 
GeneralRe: pasing byte arrays to functions Pin
App_23-Oct-11 9:09
App_23-Oct-11 9:09 
GeneralRe: pasing byte arrays to functions Pin
jkirkerx23-Oct-11 9:13
professionaljkirkerx23-Oct-11 9:13 
GeneralRe: pasing byte arrays to functions Pin
Richard MacCutchan23-Oct-11 9:35
mveRichard MacCutchan23-Oct-11 9:35 
AnswerRe: working with byte arrays Pin
jschell24-Oct-11 8:36
jschell24-Oct-11 8:36 
GeneralRe: working with byte arrays Pin
jkirkerx24-Oct-11 10:47
professionaljkirkerx24-Oct-11 10:47 

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.