<sys/time.h> gettimeofday conflict with Eth socket sendto
Whenever I enable gettimeofday in my code, previous working sendto(raw_eth, buffer, ...)
stopped working and Error: Bad file descriptor. Why is that? the only thing I'm sure is it's not name pollution. Since all the variable defined in main() works if I make the wrap of gettimeofday an empty function. Thanks, |
In the absence of code the only explanation I can come up with is: wizards did it! If you don't wish to share the code of your program, write a different, smaller program which does little more but exemplify the problem you are facing; and post that program instead.
|
Hi -
It sounds like you might be calling "gettimeofday()" incorrectly? Does your code resemble this: Code:
#include <sys/time.h> |
Thank you guys for reply,
I have gettimeofday(tv, NULL) wrapped with a function: int SetTimer(struct timeval *tv, time_t sec) { gettimeofday(tv, NULL); tv->tv_sec+=sec; return 0; } in main() { struct timeval *tv; SetTimer(tv, TIME_OUT); /* Socket stuff */ ... sendto(...) } if I comment out contents in SetTimer, sendto works. |
Thank you for posting some code. Unfortunately, it doesn't show enough to exhibit any problem.
So would you be so kind as to do these two things?
|
legendbb -
Please do what I asked you to above!!!!! You're declaring a pointer to "struct timeval *" ... but your never ALLOCATING the timeval record that's being pointed to!!!! Guaranteed segmentation violation ;) Just declare the variable, and pass "&addressof" into the function. It will make you much happier ;) PS: Regrettably, a buffer overrun in one part of the program (e.g. your call time "gettimeofday()" with a bogus pointer) can (and usually will) cause a crash in a completely *different* part of the program (here, "sendto()". But just as easily "printf()", "malloc()" or just about any other standard library function). |
My problematic code is 600 lines.
I'll tailor it down until the problem just repeats, and post here is I don't find the answer. Thank you everyone for your help and time. |
Quote:
BTW, what is the proper way of initializing the pointer of such struct if in some scenario I prefer to use pointer. Code:
struct timeval *tv; |
Quote:
If you don't declare anything but a pointer ... well, then, it doesn't have anything to "point to", does it? 'Hope that helps .. PSM PS: An equivalent example: Code:
struct timeval *t_p = malloc (sizeof (struct timeval)); Code:
struct timeval t; |
Great thanks,
|
Code:
struct timeval start0={0,0}; |
All times are GMT -5. The time now is 12:33 AM. |