This is a structure define by me....
typedef enum
{
TCP = 1,
UDP
}protocol;
typedef enum
{
DLL_Operation = 1,
MT_Operation,
Fork_Operation,
IPC_Operation
}msgc;
struct f
{
int seqNo;
protocol p;
msgc m;
protocol q;
int PayLoadSize;
void (*payload_ptr)();
};
Now am taking the address of a function in function pointer and sending it to client side from server...
This is my server side code..
struct f f2;
if(f2.m == 1)
{
f2.payload_ptr = &DLL;
f2.payload_ptr();
}
else if(f2.m == 2)
{
f2.payload_ptr = &MT;
f2.payload_ptr();
}
else if(f2.m == 3)
{
f2.payload_ptr = &Fork;
f2.payload_ptr();
}
else
{
f2.payload_ptr = &IPC;
f2.payload_ptr();
}
printf("Address is: %d\n",f2.payload_ptr);
if(f2.q == 1)
{
if(write(newsockfd, &f2, sizeof(f2)) < 0)
{
printf("\nERROR writing to socket");
exit(0);
}
close(sockfd);
close(newsockfd);
}
This is my client side code for receiving..
struct f f1;
if(f1.q = 1)
{
/* Reading data sent by server */
n = read(sockfd, &f1, sizeof(f1));
if(n < 0)
{
printf("\nERROR reading socket");
exit(0);
}
printf("Address is: %d\n",f1.payload_ptr);
f1.payload_ptr();
close(sockfd);
}
Now the problem is when i print the address of that pointer... it is printing same on both side.... but when i call that function pointer to execute.... it it giving Segmentation fault