Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Without seeing your code or the compiler warning it will be impossible for anybody to help. Chances are you dumped into an array that was too small or not allocated yet.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Rep:
Hi vicky chauhan,
Welcome to LQ!
Segmentation fault occurs when memory is accessed incorrectly. You can try using "strace" to see what's happening. But given the low detail of your post, I can't really offer much "help".
Without seeing your code or the compiler warning it will be impossible for anybody to help. Chances are you dumped into an array that was too small or not allocated yet.
cast to pointer from integer of different size [-Wint-to-pointer-cast]
memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
this is compiler warning
cast to pointer from integer of different size [-Wint-to-pointer-cast]
memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
this is compiler warning
Without seeing your code or the compiler warning it will be impossible for anybody to help. Chances are you dumped into an array that was too small or not allocated yet.
You need to read the "Question Guidelines" and "How to ask a smart question" links in my posting signature, along with the LQ Rules. We volunteer our time here, so telling us that "i m waiting" is plain rude. We answer when we can, if we can/want to. Secondly, you have posted one very small piece of your code, with no context at all...what do you think we'll be able to tell you??? And when posting code, you need to use CODE tags.
Post relevant details and we can try to help. Otherwise, since you're using RHEL 7...have you contacted RHEL support for help in analyzing a core dump?
int CreateRawSocket(int protocol_to_sniff)
{
int rawsock;
if((rawsock=socket(PF_PACKET,SOCK_RAW,htons(protocol_to_sniff)))==-1)
{
perror("Error creating raw socket:");
exit(-1);
}
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
^
Again: YOU NEED TO USE CODE TAGS....go back and edit your previous post. If you would like help from the community, you need to at least read and acknowledge things that you get told. Also, that is not the entire output from your compile attempt; again, you need to post details. Did you read the message you got, and at least try to look it up?? The compiler returns a warning because you are converting an int to void.
Again: use CODE tags, provide details, and don't tell volunteers to hurry up and help you.
Again: YOU NEED TO USE CODE TAGS....go back and edit your previous post. If you would like help from the community, you need to at least read and acknowledge things that you get told. Also, that is not the entire output from your compile attempt; again, you need to post details. Did you read the message you got, and at least try to look it up?? The compiler returns a warning because you are converting an int to void.
Again: use CODE tags, provide details, and don't tell volunteers to hurry up and help you.
As far as that warning goes, h_addr is an array of unsigned char of size 6.
manual page for ether_aton(3) quotes that this function returns a pointer to a structure type ether_addr. struct ether_addr contains the element named, ether_addr_octet which is an array of unsigned characters.
You should fix the warning.
You should check that the address returned by the ether_aton() function is not NULL, because it can be and copying to or from a NULL address will cause a crash.
If you're getting a core dump you can analyze it using gdb. I would recommend you compile your source with the -ggdb switch. It seems as if you already are obtaining a core dump, therefore you can use gdb to analyze this core and see the exact line where the problem is.
Note that the problem may not be where your warning is located at. That warning may have nothing to do with this crash. The warning should be resolved anyways, however it may not be your problem.
Do also heed the advice of others about how to ask questions properly, and also review the comments by others clearly before repeating your same questions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.