Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8478463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:45:10+00:00 2026-06-10T18:45:10+00:00

BOOL sendHTTPdata(char* data){ //MessageBox(NULL,data, aaa!,MB_ICONEXCLAMATION | MB_OK); char *s=malloc(sizeof(char)*5000); WSADATA wsaData; SOCKET ConnectSocket =

  • 0
BOOL sendHTTPdata(char* data){
    //MessageBox(NULL,data, "aaa!",MB_ICONEXCLAMATION | MB_OK);

    char  *s=malloc(sizeof(char)*5000);
    WSADATA wsaData;
    SOCKET ConnectSocket = INVALID_SOCKET;
    struct addrinfo *result= NULL,
                    *ptr = NULL,
                    hints={0};
    char recvbuf[DEFAULT_BUFLEN];
    int iResult;
    int recvbuflen = DEFAULT_BUFLEN;

    // Initialize Winsock
    iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    if (iResult != 0) {
        //printf("WSAStartup failed with error: %d\n", iResult);
        MessageBox(NULL,"WSAStartup failed with error: %d\n", "Error!",MB_ICONEXCLAMATION | MB_OK);
        return FALSE;
    }

    memset (&hints, 0, (sizeof (hints)+1000));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;
    // Resolve the server address and port
    //MessageBox(NULL,"test2", "Error!",MB_ICONEXCLAMATION | MB_OK);

    iResult = getaddrinfo("example.com","80", &hints, &result);
    //return FALSE;
    if ( iResult != 0) {
        sprintf(s, "getaddrinfo failed with error: %d\n",iResult);
        MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);
        WSACleanup();
        return FALSE;
    }
    MessageBox(NULL,"test", "Error!",MB_ICONEXCLAMATION | MB_OK);
    // Attempt to connect to an address until one succeeds
    //return FALSE;
    for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) {

        // Create a SOCKET for connecting to server
        ConnectSocket = socket(ptr->ai_family, ptr->ai_socktype, 
            ptr->ai_protocol);
        if (ConnectSocket == INVALID_SOCKET) {
           sprintf(s, "socket failed with error: %ld\n",WSAGetLastError());
        MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);
        WSACleanup();
        return FALSE;
        }

        // Connect to server.
        iResult = connect( ConnectSocket, ptr->ai_addr, (int)ptr->ai_addrlen);
        if (iResult == SOCKET_ERROR) {
            closesocket(ConnectSocket);
            ConnectSocket = INVALID_SOCKET;
            continue;
        }
        break;
    }

    freeaddrinfo(result);

    if (ConnectSocket == INVALID_SOCKET) {
       MessageBox(NULL,"Unable to connect to server!\n", "Error!",MB_ICONEXCLAMATION | MB_OK);
        WSACleanup();
        return FALSE;

    }

    // Send an initial buffer
    iResult = send( ConnectSocket, data, (int)strlen(data), 0 );
    if (iResult == SOCKET_ERROR) {
        sprintf(s,"send failed with error: %d\n",WSAGetLastError());
        MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);
        closesocket(ConnectSocket);
        WSACleanup();
        return FALSE;
    }

    //printf("Bytes Sent: %ld\n", iResult);
    sprintf(s,"Bytes Sent: %ld\n",iResult);
    MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);

    // shutdown the connection since no more data will be sent
    iResult = shutdown(ConnectSocket, SD_SEND);
    if (iResult == SOCKET_ERROR) {
        //printf("shutdown failed with error: %d\n", WSAGetLastError());
        sprintf(s,"shutdown failed with error: %d\n", WSAGetLastError());
        MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);

        closesocket(ConnectSocket);
        WSACleanup();
        return 1;
    }

    // Receive until the peer closes the connection
    do {

        iResult = recv(ConnectSocket, recvbuf, recvbuflen, 0);
        if ( iResult > 0 )
        {
            MessageBox(NULL,recvbuf, "success!",MB_ICONEXCLAMATION | MB_OK);
        }
        else if ( iResult == 0 )
            MessageBox(NULL,"Connection closed\n", "Error!",MB_ICONEXCLAMATION | MB_OK);
        else {
            sprintf(s,"recv failed with error: %d\n", WSAGetLastError());
            MessageBox(NULL,s, "Error!",MB_ICONEXCLAMATION | MB_OK);
        }
    } while( iResult > 0 );

    // cleanup
    closesocket(ConnectSocket);
    WSACleanup();

    return TRUE;
}

When i compile it with Visual C++ 2010 gives Access violation error but if I compile it with Visual C++ 6.0 it works…

this is what i can see in error log:

First-chance exception at 0x1027d22f (msvcr100d.dll) in Work Time Managment.exe: 0xC0000005: Access violation writing location 0x00130000.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
First-chance exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
Unhandled exception at 0xfefefefe in Work Time Managment.exe: 0xC0000005: Access violation reading location 0xfefefefe.
The program '[1456] Work Time Managment.exe: Native' has exited with code 0 (0x0).

what is wrong… ? why cannt work getaddrinfo in Visual C++ 2010 ????
This libraries i use in my code:

#define WIN32_LEAN_AND_MEAN
#define _WSPIAPI_COUNTOF
#include "windows.h"
#include "winsock2.h"
#include "ws2tcpip.h"
#include "stdio.h"
#pragma comment (lib, "Ws2_32.lib")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:45:12+00:00Added an answer on June 10, 2026 at 6:45 pm

    This is a problem:

    memset (&hints, 0, (sizeof (hints)+1000)); 
    

    as it will be writing to 1000 bytes of memory it should not, causing undefined behaviour. The call to memset() is unrequired as hints has already been initialised. However, the correct use is:

    memset (&hints, 0, sizeof(hints));
    

    I think the problem is elsewhere in the code as getaddrinfo() executed successfully for me using VC2010. This is the source I used:

    #include <winsock2.h>
    #include <Ws2tcpip.h>
    #include <stdio.h>
    #include <string.h>
    
    int main()
    {
        WSADATA wsaData;
        struct addrinfo *result= NULL, hints={0}; 
        int iResult;
    
        iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
    
        if (iResult != 0)
        {
            fprintf(stderr, "Startup failure: %d\n", iResult);
        }
        else
        {
            /* Identical behaviour with and without the memset(). 
            memset(&hints, 0, sizeof(hints)); */
    
            hints.ai_family = AF_UNSPEC;
            hints.ai_socktype = SOCK_STREAM;
            hints.ai_protocol = IPPROTO_TCP;
    
            iResult = getaddrinfo("localhost", "80", &hints, &result);
            if (0 != iResult)
            {
                fprintf(stderr, "failure: %d\n", iResult);
            }
            else
            {
                printf("Success\n");
            }
    
            WSACleanup();
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

-(BOOL)createTimer { stRs232Timer* pEvent = malloc(sizeof(stRs232Timer)); pEvent->bPersistent = YES; // setup timer structure pEvent->wAppTimerId
Does bool value false == 0 and true == 1 Does Null value in
Here is my code: bool Character::keyPress(char c) { switch(c) { case up_key: move(0, -1);
bool QDomDocument::setContent ( const QByteArray & data, bool namespaceProcessing, QString * errorMsg = 0,
- (BOOL)parserJSONString:(NSString *)jsonString error:(NSError **)anError { //some data getting //error handle NSString *description =
bool Win64bit = (sizeof(int*) == 8) ? 1 : 0; I need this so
a bool variable could hold true or false, while bool? could be null as
bool ret = false; try { SQLiteConnection sqlConn = new SQLiteConnection("Data Source=" + m_dbName);
bool ok = query.exec(CREATE TABLE person ( IdTable INTEGER IDENTITY(1,1) NOT NULL PRIMARY KEY,
bool print_date(Date *d, char **argv) { if (isdigit(*argv+1)) { return printf(is d); } else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.