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

C / C++ / MFC

 
AnswerRe: visual studio run time problem Pin
Albert Holguin20-Oct-11 4:01
professionalAlbert Holguin20-Oct-11 4:01 
QuestionI need socket help UDP broadcast, sendbuf Pin
jkirkerx19-Oct-11 14:24
professionaljkirkerx19-Oct-11 14:24 
AnswerRe: I need socket help UDP broadcast, sendbuf Pin
Goto_Label_19-Oct-11 23:01
Goto_Label_19-Oct-11 23:01 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx20-Oct-11 6:25
professionaljkirkerx20-Oct-11 6:25 
AnswerRe: I need socket help UDP broadcast, sendbuf Pin
Albert Holguin20-Oct-11 4:14
professionalAlbert Holguin20-Oct-11 4:14 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx20-Oct-11 6:21
professionaljkirkerx20-Oct-11 6:21 
AnswerRe: I need socket help UDP broadcast, sendbuf Pin
Albert Holguin20-Oct-11 6:50
professionalAlbert Holguin20-Oct-11 6:50 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx20-Oct-11 8:54
professionaljkirkerx20-Oct-11 8:54 
ohhhhhhhhhhh.

I think I'm closer now. I'm sending cc, but I'm suppose to send 20.

I manually altered the buffer size in send to 1, instead of using (int)strlen(sendbuf)
So I think I'm building the data too big.

This is a lot to learn, but I need to learn it. here's what I'm using now, I think I'm on the right track

BOOL CA_SQLServer_Scan::_socket_Broadcast_SQLServers( void ) 
{
	#define DEFAULT_BUFLEN 512
	#define DEFAULT_PORT 1434

    int iResult;
    WSADATA wsaData;

    SOCKET ConnectSocket = INVALID_SOCKET;
    struct sockaddr_in clientService; 

    int recvbuflen = DEFAULT_BUFLEN;	
    char recvbuf[DEFAULT_BUFLEN] = "";

	char mac[5];
	char sendbuf[1];

	memset(sendbuf, 0x00, sizeof(sendbuf)); // I added this to package the data, 
	strcpy(sendbuf, "");
	sprintf(sendbuf+strlen(sendbuf), "", strlen(sendbuf), sendbuf);
	memcpy(sendbuf+strlen(sendbuf), mac, 5); // 
	    
    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (iResult != NO_ERROR) {
        wprintf(L"WSAStartup failed with error: %d\n", iResult);
        return 1;
    }

    ConnectSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (ConnectSocket == INVALID_SOCKET) {
        wprintf(L"socket failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }
   
    clientService.sin_family = AF_INET;
    clientService.sin_addr.s_addr = inet_addr( "255.255.255.255" );
	clientService.sin_port = htons( DEFAULT_PORT );

    iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
    if (iResult == SOCKET_ERROR) {
        wprintf(L"connect failed with error: %d\n", WSAGetLastError() );
        closesocket(ConnectSocket);
        WSACleanup();
        return 1;
  }

    iResult = send( ConnectSocket, sendbuf, 1, 0 ); // I altered it to 1 
    if (iResult == SOCKET_ERROR) {
        wprintf(L"send failed with error: %d\n", WSAGetLastError());
        closesocket(ConnectSocket);
        WSACleanup();
        return 1;
    }

    printf("Bytes Sent: %d\n", iResult);
	    
    iResult = shutdown(ConnectSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        wprintf(L"shutdown failed with error: %d\n", WSAGetLastError());
        closesocket(ConnectSocket);
        WSACleanup();
        return 1;
    }

    do {

        iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
        if ( iResult > 0 )
            wprintf(L"Bytes received: %d\n", iResult);
        else if ( iResult == 0 )
            wprintf(L"Connection closed\n");
        else
            wprintf(L"recv failed with error: %d\n", WSAGetLastError());

    } while( iResult > 0 );


    // close the socket
    iResult = closesocket(ConnectSocket);
    if (iResult == SOCKET_ERROR) {
        wprintf(L"close failed with error: %d\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    WSACleanup();
	
	return TRUE;
}


What I'm trying to copy
0000 ff ff ff ff ff ff 00 13 72 36 67 30 08 00 45 00 ........ r6g0..E.
0010 00 1d 6f 9a 00 00 80 11 07 8a c0 a8 03 04 ff ff ..o..... ........
0020 ff ff 05 8b 05 9a 00 09 2f 0b 02 ........ /..

What I got back with the posted code
0000 ff ff ff ff ff ff 00 13 72 36 67 30 08 00 45 00 ........ r6g0..E.
0010 00 1d 94 48 00 00 80 11 e2 db c0 a8 03 04 ff ff ...H.... ........
0020 ff ff 12 32 05 9a 00 09 58 63 cc ...2.... Xc.
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
Albert Holguin20-Oct-11 11:31
professionalAlbert Holguin20-Oct-11 11:31 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx20-Oct-11 12:39
professionaljkirkerx20-Oct-11 12:39 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx20-Oct-11 12:46
professionaljkirkerx20-Oct-11 12:46 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
Albert Holguin21-Oct-11 4:51
professionalAlbert Holguin21-Oct-11 4:51 
GeneralRe: I need socket help UDP broadcast, sendbuf Pin
jkirkerx21-Oct-11 6:52
professionaljkirkerx21-Oct-11 6:52 
AnswerYou have to use the memset Pin
jkirkerx20-Oct-11 11:05
professionaljkirkerx20-Oct-11 11:05 
AnswerRe: You have to use the memset Pin
Albert Holguin20-Oct-11 11:35
professionalAlbert Holguin20-Oct-11 11:35 
Question#define not const? Pin
Waldermort19-Oct-11 3:58
Waldermort19-Oct-11 3:58 
AnswerRe: #define not const? Pin
TheGreatAndPowerfulOz19-Oct-11 5:14
TheGreatAndPowerfulOz19-Oct-11 5:14 
GeneralRe: #define not const? Pin
Waldermort19-Oct-11 5:48
Waldermort19-Oct-11 5:48 
AnswerRe: #define not const? Pin
«_Superman_»19-Oct-11 16:39
professional«_Superman_»19-Oct-11 16:39 
GeneralRe: #define not const? Pin
Waldermort20-Oct-11 1:42
Waldermort20-Oct-11 1:42 
GeneralRe: #define not const? Pin
«_Superman_»20-Oct-11 2:19
professional«_Superman_»20-Oct-11 2:19 
AnswerRe: #define not const? Pin
Stefan_Lang21-Oct-11 2:55
Stefan_Lang21-Oct-11 2:55 
QuestionPlaying video in particular dimensions Pin
VCProgrammer19-Oct-11 1:55
VCProgrammer19-Oct-11 1:55 
AnswerRe: Playing video in particular dimensions Pin
enhzflep19-Oct-11 2:35
enhzflep19-Oct-11 2:35 
QuestionCHtmlView and Windows 7 Pin
Member 810956018-Oct-11 22:57
Member 810956018-Oct-11 22:57 

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.