segmentation fault(core dumped)

Below program got compiled properly, but while execution, throws "segmentation fault error. pls help. urgent!!!

#include <cstdio>
#include <iostream>
//#include <cstdint>
#include <stdint.h>
#include <cstring>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/stat.h>
#include <stddef.h>
#include <inttypes.h>
#include <unistd.h>
#include <errno.h>
#include <poll.h>
#include "WfdSupplicantInterface.h"
#include "P2pConnectionHandler.h"
//#include <sys/_system_properties.h>
#include "wpa_ctrl.h"

#define REPLY_BUF_SIZE 4096
#define PROPERTY_VALUE_MAX 92
#define PROPERTY_KEY_MAX 32

char reply[REPLY_BUF_SIZE];
static const char IFACE_DIR[] = "/var/run/wpa_supplicant";
static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *monitor_conn;
static char supplicant_prop_name[PROPERTY_KEY_MAX];
static char primary_iface[PROPERTY_VALUE_MAX];
int errno;
static int exit_sockets[2];



using namespace std;

int wifi_connect_to_supplicant()
{
static char *path;
char supp_status[PROPERTY_VALUE_MAX] = {'\0'};

if (access(IFACE_DIR, F_OK) == 0)
{
snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
}
else
{
snprintf(path, sizeof(path), "wpa_%s", primary_iface);
}
/*
if (!_system_property_get(supplicant_prop_name, supp_status, NULL) || strcmp(supp_status, "running") != 0)
{
cout<<"Supplicant not running, cannot connect";
return -1;
}
*/

ctrl_conn = wpa_ctrl_open(path);
if (ctrl_conn == NULL)
{
cout<<"Unable to open connection to supplicant on \"%s\": %s"<< path << strerror(errno);
return -1;
}
if (wpa_ctrl_attach(monitor_conn) != 0)
{
wpa_ctrl_close(monitor_conn);
wpa_ctrl_close(ctrl_conn);
ctrl_conn = monitor_conn = NULL;
return -1;
}

if (socketpair(AF_UNIX, SOCK_STREAM, 0, exit_sockets) == -1)
{
wpa_ctrl_close(monitor_conn);
wpa_ctrl_close(ctrl_conn);
ctrl_conn = monitor_conn = NULL;
return -1;
}

return 0;

}

int32 WfdSupplicantInterface :: connectToSupplicant(uint8* pCtrlface,ConnectionHandlerListener* pListener)
{
if (wifi_connect_to_supplicant() == 0);
return true;
}

int main(int argc, char *argv[])
{
WfdSupplicantInterface *supp_interface;
//const char* ctrlface = IFACE_DIR;
if(supp_interface->connectToSupplicant((uint8*)"/var/run/wpa_supplicant", NULL))
{
cout<<"Supplicant connected successfully";
return 1;
}
else
{
cout<<"Supplicant not connected";
return -1;
}
}
1
2
3
4
5
6
7
WfdSupplicantInterface *supp_interface;
//const char* ctrlface = IFACE_DIR;
if(supp_interface->connectToSupplicant((uint8*)"/var/run/wpa_supplicant", NULL))
{
cout<<"Supplicant connected successfully";
return 1;
}


supp_interface is uninitialized
May i know, how to initialize it?, becuase i tried few ways of initializing, but failed with it. please help. I am new to c++ development
i modified the code as below in mina function, but still the segmentation fault error exists...pls help
int main(int argc, char *argv[])
{
WfdSupplicantInterface *supp_interface = new WfdSupplicantInterface();
unsigned char str[] = "var/run/wp_supplicant";
unsigned char* ctrlfce = &str[0];
if(supp_interface->connectToSupplicant(ctrlfce, NULL))
{
cout<<"Supplicant connected successfully";
return 1;
}
else
{
cout<<"Supplicant not connected";
return -1;
}

}
I suggest stepping through it with a debugger, to find exactly where it crashes, and what the state of the memory is at that point.

What is WfdSupplicantInterface ? Is it a class you've written?

EDIT: Please use code tags when posting code, to make it more readable:

http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
yes it is a class, with default constructor and member functions. i am trying to call a member function in the main. below is that class's include file.
/*
*******************************************************************************
Copyright Aricent Group, 2014
All rights Reserved, Licensed Software Confidential and Proprietary Information
of Aricent Group Made available under Non-Disclosure Agreement OR
License as applicable.
*******************************************************************************
*/

/*
*******************************************************************************
Product : WFD Primary Sink
Module : Connection Handler
File : WpaSupplicantInterface.h
Description :

Revision Record:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date Id Author Comment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
April 21, 2014 Rajesh Initial code
*******************************************************************************
*/

#ifndef _WPASUPPLICANTINTERFACE_H_
#define _WPASUPPLICANTINTERFACE_H_

#include <stdio.h>

#include "pal_datatypes.h"
#include "ConnectionHandlerListener.h"
#include "WifiP2pDevice.h"
#include "WifiP2pGroup.h"
#include "WpaSupplicantListener.h"

using namespace std;

class WpaSupplicantInterface {
public:
WpaSupplicantInterface();
~WpaSupplicantInterface();
void cancelP2pConnect();
int32 connectToSupplicant(uint8* iface, WpaSupplicantListener* pSupplicantListener);
int32 disconnectSupplicant();
int32 setPersistentReconnect(tBool nEnabled);
int32 setDeviceName(uint8* pName);
int32 setP2pSsidPostfix(uint8* pP2pSsidPostfix);
int32 setPrimaryDeviceType(uint8* pDeviceType);
int32 setConfigMethods(uint8* pConfigMethods);
uint8* getP2pDeviceAddress();
uint8* initiateP2pConnect(uint8* pArgs);
uint8* listNetworks();
int32 sendP2pGroupAdd(int32 nNetId);
int32 sendP2pGroupRemove(uint8* pIface);
int32 sendP2pProvisionDiscRequest(uint8* pAddr);
int32 sendP2pReinvoke(int32 nNetId, uint8* pDevAddr);
int32 sendP2pReject(uint8* pDevAddr);
int32 sendP2pServDiscCancelRequest(uint8* pServReqId);
uint8* sendP2pServDiscRequest(uint8* addr, uint8* pQuery);
int32 sendTdlsDiscoveryRequest(uint8* pAddr);
int32 sendTdlsSetup(uint8* pAddr);
int32 sendTdlsTearDown(uint8* pAddr);
int32 setWfdEnable(tBool bIsEnable);
int32 setWfdSubElement(int32 nSubElementId, uint8* pHexDump);
int32 startP2pFind(int32 nTimeOut);
int32 startP2pListen(int32 nTimeOut);
int32 stopP2pFind();
int32 sendP2pFlush();
int32 sendP2pServiceFlush();



private:
void processEventMsg(uint8* pEvents);

WifiP2pDevice* parseDeviceFoundEvent(uint8* pEvent);
/* WifiP2pConfig* parseGoNegotiationRequestEvent(uint8* pEvent);*/
WifiP2pGroup* parseGroupStartedEvent(uint8* pEvent);
WifiP2pGroup* parseInvitationReceivedEvent(uint8* pEvent);
Parcel* parseProvDiscEvent(uint8* pEvent);
Parcel* parseServDiscResponseEvent(uint8* pEvent);

WpaSupplicantListener* m_pSupplicantListener;
};

#endif // _WFDSUPPLICANTINTERFACE_H_
Last edited on
even i when i debug with break point at anywhere in the program, it immediately crashes
Please use code tags when posting code, to make it more readable:

http://www.cplusplus.com/articles/z13hAqkS/
*******************************************************************************
Copyright Aricent Group, 2014
All rights Reserved, Licensed Software Confidential and Proprietary Information
of Aricent Group
Made available under Non-Disclosure Agreement OR
License as applicable.
*******************************************************************************

@ OP: Um... Should you be posting this in a public forum? I really hope you didn't just get hired for a job there.
Topic archived. No new replies allowed.