LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   regarding segv signal (https://www.linuxquestions.org/questions/linux-software-2/regarding-segv-signal-921575/)

santhosh-e 01-02-2012 02:49 AM

regarding segv signal
 
hi,

I have build the image for coldfire processor using build root 2011.08.Here we are using busybox version 1.18.5 and linux kernel 2.6.30.4.we try to download the image its works fine we got the prompt and file system.While pinging from the device i am facing segv error.

Here code is :
static void sendping_tail(void (*sp)(int), const void *pkt, int size_pkt)
{

int sz;

CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
ntransmitted++;

/* sizeof(pingaddr) can be larger than real sa size, but I think
* it doesn't matter */
sz = xsendto(pingsock, pkt, size_pkt, &pingaddr.sa, sizeof(pingaddr));
if (sz != size_pkt)
bb_error_msg_and_die(bb_msg_write_error);

if (pingcount == 0 || deadline || ntransmitted < pingcount) {
/* Didn't send all pings yet - schedule next in 1s */
signal(SIGALRM, sp);



if (deadline) {
total_secs += PINGINTERVAL;
if (total_secs >= deadline)
signal(SIGALRM, print_stats_and_exit);
}
alarm(PINGINTERVAL);


} else { /* -c NN, and all NN are sent (and no deadline) */
/* Wait for the last ping to come back.
* -W timeout: wait for a response in seconds.
* Affects only timeout in absense of any responses,
* otherwise ping waits for two RTTs. */
unsigned expire = timeout;

if (nreceived) {
/* approx. 2*tmax, in seconds (2 RTT) */
expire = tmax / (512*1024);
if (expire == 0)
expire = 1;
}
signal(SIGALRM, print_stats_and_exit);
alarm(expire);
}

}

static void sendping4(int junk UNUSED_PARAM)
{
struct icmp *pkt = G.snd_packet;

//memset(pkt, 0, datalen + ICMP_MINLEN + 4); - G.snd_packet was xzalloced
pkt->icmp_type = ICMP_ECHO;
/*pkt->icmp_code = 0;*/
pkt->icmp_cksum = 0; /* cksum is calculated with this field set to 0 */
pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp_id = myid;

/* If datalen < 4, we store timestamp _past_ the packet,
* but it's ok - we allocated 4 extra bytes in xzalloc() just in case.
*/
/*if (datalen >= 4)*/
/* No hton: we'll read it back on the same machine */
*(uint32_t*)&pkt->icmp_dun = monotonic_us();

pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN);

signal(SIGALRM,sendping4);
sendping_tail(sendping4, pkt, datalen + ICMP_MINLEN);
}

static void ping4(len_and_sockaddr *lsa)
{
int sockopt;

pingsock = create_icmp_socket();
pingaddr.sin = lsa->u.sin;
if (source_lsa) {
if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF,
&source_lsa->u.sa, source_lsa->len))
bb_error_msg_and_die("can't set multicast source interface");
xbind(pingsock, &source_lsa->u.sa, source_lsa->len);
}
if (str_I)
setsockopt_bindtodevice(pingsock, str_I);

/* enable broadcast pings */
setsockopt_broadcast(pingsock);

/* set recv buf (needed if we can get lots of responses: flood ping,
* broadcast ping etc) */
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));

signal(SIGINT, print_stats_and_exit);

/* start the ping's going ... */

sendping4(0);



/* listen for replies */
while (1) {
printf("listen for replies\n");
sendping4(0);

struct sockaddr_in from;
socklen_t fromlen = (socklen_t) sizeof(from);
int c;

c = recvfrom(pingsock, G.rcv_packet, G.sizeof_rcv_packet, 0,
(struct sockaddr *) &from, &fromlen);


if (c < 0) {
if (errno != EINTR)
bb_perror_msg("recvfrom");
continue;

}

}



We tried to debug the transmission and reception happens one time after that i am getting segv error.

please any ideas it will be helpful for debug the code.

regards
santhosh babu

santhosh-e 01-02-2012 03:27 AM

hi,

I have build the image for coldfire processor using build root 2011.08.Here we are using busybox version 1.18.5 and linux kernel 2.6.30.4.we try to download the image its works fine we got the prompt and file system.While pinging from the device i am facing segv error.

Here code is :
static void sendping_tail(void (*sp)(int), const void *pkt, int size_pkt)
{

int sz;

CLR((uint16_t)ntransmitted % MAX_DUP_CHK);
ntransmitted++;

/* sizeof(pingaddr) can be larger than real sa size, but I think
* it doesn't matter */
sz = xsendto(pingsock, pkt, size_pkt, &pingaddr.sa, sizeof(pingaddr));
if (sz != size_pkt)
bb_error_msg_and_die(bb_msg_write_error);

if (pingcount == 0 || deadline || ntransmitted < pingcount) {
/* Didn't send all pings yet - schedule next in 1s */
signal(SIGALRM, sp);



if (deadline) {
total_secs += PINGINTERVAL;
if (total_secs >= deadline)
signal(SIGALRM, print_stats_and_exit);
}
alarm(PINGINTERVAL);


} else { /* -c NN, and all NN are sent (and no deadline) */
/* Wait for the last ping to come back.
* -W timeout: wait for a response in seconds.
* Affects only timeout in absense of any responses,
* otherwise ping waits for two RTTs. */
unsigned expire = timeout;

if (nreceived) {
/* approx. 2*tmax, in seconds (2 RTT) */
expire = tmax / (512*1024);
if (expire == 0)
expire = 1;
}
signal(SIGALRM, print_stats_and_exit);
alarm(expire);
}

}

static void sendping4(int junk UNUSED_PARAM)
{
struct icmp *pkt = G.snd_packet;

//memset(pkt, 0, datalen + ICMP_MINLEN + 4); - G.snd_packet was xzalloced
pkt->icmp_type = ICMP_ECHO;
/*pkt->icmp_code = 0;*/
pkt->icmp_cksum = 0; /* cksum is calculated with this field set to 0 */
pkt->icmp_seq = htons(ntransmitted); /* don't ++ here, it can be a macro */
pkt->icmp_id = myid;

/* If datalen < 4, we store timestamp _past_ the packet,
* but it's ok - we allocated 4 extra bytes in xzalloc() just in case.
*/
/*if (datalen >= 4)*/
/* No hton: we'll read it back on the same machine */
*(uint32_t*)&pkt->icmp_dun = monotonic_us();

pkt->icmp_cksum = in_cksum((unsigned short *) pkt, datalen + ICMP_MINLEN);

signal(SIGALRM,sendping4);
sendping_tail(sendping4, pkt, datalen + ICMP_MINLEN);
}

static void ping4(len_and_sockaddr *lsa)
{
int sockopt;

pingsock = create_icmp_socket();
pingaddr.sin = lsa->u.sin;
if (source_lsa) {
if (setsockopt(pingsock, IPPROTO_IP, IP_MULTICAST_IF,
&source_lsa->u.sa, source_lsa->len))
bb_error_msg_and_die("can't set multicast source interface");
xbind(pingsock, &source_lsa->u.sa, source_lsa->len);
}
if (str_I)
setsockopt_bindtodevice(pingsock, str_I);

/* enable broadcast pings */
setsockopt_broadcast(pingsock);

/* set recv buf (needed if we can get lots of responses: flood ping,
* broadcast ping etc) */
sockopt = (datalen * 2) + 7 * 1024; /* giving it a bit of extra room */
setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, &sockopt, sizeof(sockopt));

signal(SIGINT, print_stats_and_exit);

/* start the ping's going ... */

sendping4(0);



/* listen for replies */
while (1) {
printf("listen for replies\n");
sendping4(0);

struct sockaddr_in from;
socklen_t fromlen = (socklen_t) sizeof(from);
int c;

c = recvfrom(pingsock, G.rcv_packet, G.sizeof_rcv_packet, 0,
(struct sockaddr *) &from, &fromlen);


if (c < 0) {
if (errno != EINTR)
bb_perror_msg("recvfrom");
continue;

}

}



We tried to debug the transmission and reception happens one time after that i am getting segv error.

please any ideas it will be helpful for debug the code.

regards
santhosh babu


All times are GMT -5. The time now is 02:00 PM.