LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-18-2017, 02:08 PM   #1
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Rep: Reputation: Disabled
i use rhel 7 i got segment fault core dump


i got problem on rhel 7 segment faul core dumped when we using memcpy we got warnig cast int
 
Old 07-18-2017, 02:12 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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.
 
Old 07-18-2017, 02:13 PM   #3
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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".
 
Old 07-18-2017, 02:21 PM   #4
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
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.


i send my code help me
 
Old 07-18-2017, 02:23 PM   #5
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by vicky chauhan View Post
i send my code help me
unsigned char* CreateEthernetHeader(char *src_mac,char *dst_mac,int protocol)
{
struct ethhdr *ethernet_header;

ethernet_header=(struct ethhdr*)malloc(sizeof(struct ethhdr));

memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
memcpy(ethernet_header->h_dest,(void *)ether_aton(dst_mac),6);
ethernet_header->h_proto=htons(protocol);

return (unsigned char*)ethernet_header;

}
 
Old 07-18-2017, 02:27 PM   #6
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
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
 
Old 07-18-2017, 02:30 PM   #7
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by vicky chauhan View Post
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



reply me sir i m waiting
 
Old 07-18-2017, 02:41 PM   #8
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suicidaleggroll View Post
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.



unsigned char* CreateEthernetHeader(char *src_mac,char *dst_mac,int protocol)
{
struct ethhdr *ethernet_header;

ethernet_header=(struct ethhdr*)malloc(sizeof(struct ethhdr));

memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
memcpy(ethernet_header->h_dest,(void *)ether_aton(dst_mac),6);
ethernet_header->h_proto=htons(protocol);

return (unsigned char*)ethernet_header;

}
 
Old 07-18-2017, 02:54 PM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
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?
 
Old 07-18-2017, 03:00 PM   #10
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
#include<string.h>
#include<sys/types.h>
#include<stdio.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<features.h>
#include<linux/if_packet.h>
#include<linux/if_ether.h>
#include<errno.h>
#include<sys/ioctl.h>
#include<net/if.h>
#include<net/ethernet.h>

#define SRC_ETHER_ADDR "aa:aa:aa:aa:aa:aa"
#define DST_ETHER_ADDR "bb:bb:bb:bb:bb:bb"


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);
}

return rawsock;

}

int BindRawSocketToInterface(char *device,int rawsock,int protocol)
{
struct sockaddr_ll sll;
struct ifreq ifr;

bzero(&sll,sizeof(sll));
bzero(&ifr,sizeof(ifr));
strncpy((char*)ifr.ifr_name,device,IFNAMSIZ);
if((ioctl(rawsock,SIOCGIFINDEX,&ifr))==-1)
{
perror("Error getting index:");
exit(-1);
}

sll.sll_family=AF_PACKET;
sll.sll_ifindex=ifr.ifr_ifindex;
sll.sll_protocol=htons(protocol);

if((bind(rawsock,(struct sockaddr*)&sll,sizeof(sll)))==-1)
{
perror("Error binding interface:");
exit(-1);
}

return 1;
}
int SendRawPacket(int rawsock,unsigned char *pkt,int pkt_len)
{

int sent=0;
if((sent=write(rawsock,pkt,pkt_len))!=pkt_len)
{
return 0;
}
return 1;
}

unsigned char* CreateEthernetHeader(char *src_mac,char *dst_mac,int protocol)
{
struct ethhdr *ethernet_header;

ethernet_header=(struct ethhdr*)malloc(sizeof(struct ethhdr));

memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
memcpy(ethernet_header->h_dest,(void *)ether_aton(dst_mac),6);
ethernet_header->h_proto=htons(protocol);

return (unsigned char*)ethernet_header;

}

main(int argc,char **argv)
{
int raw ;
unsigned char *packet;
int ethhdr_len;

raw=CreateRawSocket(ETH_P_ALL);
BindRawSocketToInterface(argv[1],raw,ETH_P_ALL);

packet=CreateEthernetHeader(SRC_ETHER_ADDR,DST_ETHER_ADDR,ETHERTYPE_IP);
ethhdr_len=sizeof(struct ethhdr);

if(!SendRawPacket(raw,packet,ethhdr_len))
{
perror("Error sending packet");
}

else
printf("packet sent successfully\n");
free(packet);
close(raw);
return 0;

}
 
Old 07-18-2017, 03:03 PM   #11
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
compile error



warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
memcpy(ethernet_header->h_source,(void *)ether_aton(src_mac),6);
^
 
Old 07-18-2017, 03:17 PM   #12
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by vicky chauhan View Post
compile error

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.
 
Old 07-18-2017, 03:24 PM   #13
vicky chauhan
LQ Newbie
 
Registered: Jul 2017
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
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.

we remove void
 
Old 07-19-2017, 06:35 AM   #14
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.

See my blog entry about how to analyze core files if you do not understand how to use gdb to analyze this 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.
 
1 members found this post helpful.
Old 07-21-2017, 01:46 PM   #15
vivek singh chauhan1
LQ Newbie
 
Registered: Jul 2017
Posts: 2

Rep: Reputation: Disabled
my program compile safe of packet sniff

half program run safe and then...


segment fault(core dumped) stop the program
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Segmentation fault (core dump) vikrant2k14 Linux - Newbie 17 02-04-2015 05:25 AM
[SOLVED] Getting segmentation fault(core dump) error gauravdev Linux - Newbie 2 10-12-2012 02:48 AM
segmentation fault (core dump) bhatia.ankur8 Linux - General 1 07-06-2010 04:58 AM
segmentation fault core dump shaiva Linux - Newbie 1 09-23-2009 11:04 AM
php core dump with segmentation fault ohcarol *BSD 9 10-14-2008 09:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration