Sponsored Content
Full Discussion: Segmentation Fault by memcpy
Top Forums Programming Segmentation Fault by memcpy Post 302427704 by shamrock on Monday 7th of June 2010 02:56:26 PM
Old 06-07-2010
Quote:
Originally Posted by Zykl0n-B
Code:
struct arpmsg{
struct ethernet ethernet;
struct arp arp;
};

And i get the segmentation fault in the main program when i use memcpy to store the addresses in their respective field, here's an example:

Code:
char mac[]={0x01,0x00,0x5E,0x03,0x03,0x08};
memcpy(arpmsg->arp.ar$sha, mac, 6);

Please, could anyone tell me what am i doing wrong? This is a weird error, gcc gives me no warnings.

Oh!, i changed the memcpy function to strncpy, strcpy, and i keep getting the same SIGSEGV.

I'll appreciate any answers, thank you.
From your post it looks like arpmsg is a struct tag not an instance of that type...and if you have a variable of that type calld aprmsg then you are using the wrong operator to access its members...
Code:
struct arpmsg
{
    struct ethernet ethernet;
    struct arp arp;
} arpmsg;

memcpy(arpmsg.arp.ar$sha, mac, 6);

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation Fault

hello all, I tried a program on an array to intialise array elements from the standard input device.it is an integer array of 5 elements.but after entering the 4th element it throws a message called "Segmentation Fault" and returns to the command prompt without asking for the 5th element. ... (3 Replies)
Discussion started by: compbug
3 Replies

2. AIX

Segmentation fault

Hi , During execution a backup binary i get following error "Program error 11 (Segmentation fault), saving core file in '/usr/datatools" Riyaz (2 Replies)
Discussion started by: rshaikh
2 Replies

3. UNIX for Dummies Questions & Answers

Segmentation Fault

Hi, While comparing primary key data of two tables thr bteq script I am getting this Error. This script is a shell script. *** Error: The following error was encountered on the output file. Script.sh: 3043492 Segmentation fault(coredump) Please let me know how to get through it. ... (5 Replies)
Discussion started by: monika
5 Replies

4. Programming

Segmentation fault in C

i have this code int already_there(char *client_names, char *username) { int i; for(i = 0; i<NUM; i++) { printf("HERE\n"); if (strcmp(client_names, username)==0) return(1); } return(0); } and i get a segmentation fault, whats wrong here? (7 Replies)
Discussion started by: omega666
7 Replies

5. UNIX for Advanced & Expert Users

segmentation fault with ps

What does this mean and why is this happening? $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps -ef | grep ocular Segmentation fault (core dumped) $ ps aux | grep ocular Segmentation fault (core dumped) $ ps Segmentation fault (core dumped) $ pkill okular $ ps... (1 Reply)
Discussion started by: cokedude
1 Replies

6. Programming

Using gdb, ignore beginning segmentation fault until reproduce environment segmentation fault

I use a binary name (ie polo) it gets some parameter , so for debugging normally i do this : i wrote script for watchdog my app (polo) and check every second if it's not running then start it , the problem is , if my app , remain in state of segmentation fault for a while (ie 15 ... (6 Replies)
Discussion started by: pooyair
6 Replies

7. Homework & Coursework Questions

Segmentation Fault

this is a network programming code to run a rock paper scissors in a client and server. I completed it and it was working without any error. After I added the findWinner function to the server code it starts giving me segmentation fault. -the segmentation fault is fixed Current problem -Also... (3 Replies)
Discussion started by: femchi
3 Replies

8. Solaris

Segmentation fault

Hi Guys, I just installed and booted a zone called testzone. When I logged in remotely and tried changing to root user I get this error: "Segmentation fault" Can someone please help me resolve this? Thanks alot (2 Replies)
Discussion started by: cjashu
2 Replies

9. Programming

Segmentation fault

I keep getting this fault on a lot of the codes I write, I'm not exactly sure why so I'd really appreciate it if someone could explain the idea to me. For example this code #include <stdio.h> main() { unsigned long a=0; unsigned long b=0; int z; { printf("Enter two... (2 Replies)
Discussion started by: sizzler786
2 Replies

10. Programming

C. To segmentation fault or not to segmentation fault, that is the question.

Oddities with gcc, 2.95.3 for the AMIGA and 4.2.1 for MY current OSX 10.14.1... I am creating a basic calculator for the AMIGA ADE *NIX emulator in C as it does not have one. Below are two very condensed snippets of which I have added the results inside the each code section. IMPORTANT!... (11 Replies)
Discussion started by: wisecracker
11 Replies
ARPWATCH(8)						      System Manager's Manual						       ARPWATCH(8)

NAME
arpwatch - keep track of ethernet/ip address pairings SYNOPSIS
arpwatch [ -dN ] [ -f datafile ] [ -i interface ] [ -n net[/width ]] [ -r file ] [ -s sendmail_path ] [ -p ] [ -a ] [ -m addr ] [ -u username ] [ -R seconds ] [ -Q ] [ -z ignorenet/ignoremask ] DESCRIPTION
Arpwatch keeps track for ethernet/ip address pairings. It syslogs activity and reports certain changes via email. Arpwatch uses pcap(3) to listen for arp packets on a local ethernet interface. The -d flag is used enable debugging. This also inhibits forking into the background and emailing the reports. Instead, they are sent to stderr. The -f flag is used to set the ethernet/ip address database filename. The default is arp.dat. The -i flag is used to override the default interface. The -n flag specifies additional local networks. This can be useful to avoid "bogon" warnings when there is more than one network running on the same wire. If the optional width is not specified, the default netmask for the network's class is used. The -N flag disables reporting any bogons. The -r flag is used to specify a savefile (perhaps created by tcpdump(1) or pcapture(1)) to read from instead of reading from the network. In this case, arpwatch does not fork. (Debian) The -s flag is used to specify the path to the sendmail program. Any program that takes the option -odi and then text from stdin can be substituted. This is useful for redirecting reports to log files instead of mail. (Debian) The -p flag disables promiscuous operation. ARP broadcasts get through hubs without having the interface in promiscuous mode, while saving considerable resources that would be wasted on processing gigabytes of non-broadcast traffic. OTOH, setting promiscuous mode does not mean getting 100% traffic that would concern arpwatch . YMMV. (Debian) -a By default, arpwatch reports bogons (unless -N is given) for IP addresses that are in the same subnet than the first IP address of the default interface. If this option is specified, arpwatch will report bogons about every IP addresses. (Debian) The -m option is used to specify the e-mail address to which reports will be sent. By default, reports are sent to root on the local machine. (Debian) The -u flag instructs arpwatch to drop root privileges and change the UID to username and GID to the primary group of username . This is recommended for security reasons, but username has to have write access to the default directory. (Debian) The -R flag instructs arpwatch to restart in seconds seconds after the interface went down. By default, in such cases arpwatch would print an error message and exit. This option is ignored if either the -r or -u flags are used. (Debian) The -Q flags prevents arpwatch from sending reports by mail. (Debian) The -z flag is used to set a range of ip addresses to ignore (such as a DHCP range). Netmask is specified as 255.255.128.0. Note that an empty arp.dat file must be created before the first time you run arpwatch. REPORT MESSAGES
Here's a quick list of the report messages generated by arpwatch(1) (and arpsnmp(1)): new activity This ethernet/ip address pair has been used for the first time six months or more. new station The ethernet address has not been seen before. flip flop The ethernet address has changed from the most recently seen address to the second most recently seen address. (If either the old or new ethernet address is a DECnet address and it is less than 24 hours, the email version of the report is suppressed.) changed ethernet address The host switched to a new ethernet address. SYSLOG MESSAGES
Here are some of the syslog messages; note that messages that are reported are also sysloged. ethernet broadcast The mac ethernet address of the host is a broadcast address. ip broadcast The ip address of the host is a broadcast address. bogon The source ip address is not local to the local subnet. ethernet broadcast The source mac or arp ethernet address was all ones or all zeros. ethernet mismatch The source mac ethernet address didn't match the address inside the arp packet. reused old ethernet address The ethernet address has changed from the most recently seen address to the third (or greater) least recently seen address. (This is similar to a flip flop.) suppressed DECnet flip flop A "flip flop" report was suppressed because one of the two addresses was a DECnet address. FILES
/var/lib/arpwatch - default directory arp.dat - ethernet/ip address database /usr/share/arpwatch/ethercodes.dat - vendor ethernet block list SEE ALSO
arpsnmp(8), arp(8), bpf(4), tcpdump(1), pcapture(1), pcap(3) AUTHORS
Craig Leres of the Lawrence Berkeley National Laboratory Network Research Group, University of California, Berkeley, CA. The current version is available via anonymous ftp: ftp://ftp.ee.lbl.gov/arpwatch.tar.gz BUGS
Please send bug reports to arpwatch@ee.lbl.gov. Attempts are made to suppress DECnet flip flops but they aren't always successful. Most error messages are posted using syslog. 4th Berkeley Distribution 8 October 2000 ARPWATCH(8)
All times are GMT -4. The time now is 01:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy