pass one structure to function

Hi
I want to pass my structure to one function.That function only accepts "u_char *" pointer but my structure has another type,my structure has some "int" type.Unfortunately I can not modify that function!
Is there any solution for this problem?

Thanks in advance
What function is it?
What is the result you want to get?
Something about the structure?
Thanks for quick reply
The proto type function is:
 
Count_Packet(u_char *args,const struct pcap_pkthdr *Packet_Header,const u_char* Original_Packet)


My structure is:
1
2
3
4
5
6
7
typedef struct
{
	unsigned long int Total_Packet_Count;
	unsigned long int TCP_Packet_Count;
	unsigned long int UDP_Packet_Count;
	unsigned long int ICMP_Packet_Count;
}Packet_Type_Counter;


Can I use void pointer for pass my structure as "args" in this function ?

Thanks in advance
Last edited on
Why don't you use
Count_Packet(Packet_Type_counter * args, ...
Or well, you can cast it to void * too.
If you can't get it to compile, make sure your struct is defined before the function, and eventually try something like this:
 
Count_Packet(& (StructVariableName) ...
Thanks again
I can not modify the function,because that is "callback" function and should has specific prototype.for more information, this callback is for "pcap_loop" function from "libpcap" library.
[b]Can I pass "void" pointer to "Count_Packet" as "u_char *args" argument ?
[/b]
Thanks in advance
You can pass it pointer, yes.
But you should pass it NOT as a void *, but as a u_char *.
Nothing changes in fact, but you may get a warning/error giving a void *.
Then re-cast it back to a Packet_Type *.
Like this:
1
2
3
Packet_Type Packet;
...
Count_Packet( &Packet, ...

and in Count_Packet...
 
Packet_Type Packet = *( (Packet_Type *)args );
 
Packet_Type *Packet =  (Packet_Type *)args;
will better.
I am confused about only one thing that is if it is a call back then how come you are invoking it from your code.

You are allowed to give the definition of call back but invocation is done implicitly.
Correct me if i'm worng.
@beyonder2015 you will then need to use the -> operator instead of the . op., and i think he isn't so expert about that, just a guess.
@sandeepdas: You are right, but you also can explicitly call the callback in your code.
@EssGeEich you very responsible!
Topic archived. No new replies allowed.