Extern variable has different values in different C files
I'm trying to use a shared variable in multi C files. So, I write a
program to use its value:
In the path: sonnh\epan\dissectors\socket_sonnh.h , I defined a extern
variable: extern int ServerSocket;
In the path: sonnh\tshark.c , after #include
<epan/dissectors/socket_sonnh.h> I create the init value ServerSocket =
socket(AF_INET,SOCK_STREAM,IPPROTO_IP);
In the path: sonnh\epan\dissectors\packet-camel.c, after #include
"socket_sonnh.h" I want to use the value of ServerSocket by command i =
send(ServerSocket, cSendBuff, 20, 0);
The flow of code is: after creation of ServerSocket in tshark.c --> (call
func in other file) --> (somewhere I don't know) --> call func in
packet-camel.c to send socket. I know this because i check the log.
But actually, I check the value of ServerSocket at the top and bottom of
tshark.c, it is always 336, but the value of this in packet-camel.c is
always 0. i think it is extern variable , so it keeps its value while
running in different files but in this case, i cannot see the value of
ServerSocket being the same with the value of 336 as seen in tshark.c.
Could you please help me to find out why and how can I solve this problem
to have the value of ServerSocket in packket-camel.c (using shared
variable). Thank you so much.
No comments:
Post a Comment