segmentation fault in socket application


 
Thread Tools Search this Thread
Operating Systems Linux segmentation fault in socket application
# 1  
Old 04-17-2008
segmentation fault in socket application

helo,
i m using linux operationg system at both client and server side.

Now in my application when i use ntohl() then it will give segmentation fault.
now when i remove nothl(), then it works fine.
can u tell me why this happen.


amit
# 2  
Old 04-17-2008
Are you invoking ntohl() correctly?
# 3  
Old 04-17-2008
Code please.
# 4  
Old 04-18-2008
Quote:
Originally Posted by ramen_noodle
Code please.
helo my code is given below

static HeadderFun* listheader_ntoh(HeadderFun* lh)
{
lh->head_len = ntohl(lh->cl_head_len);
lh->record_len = ntohl(lh->cl_record_len);
lh->linecnt = ntohl(lh->cl_linecnt);
return lh;
}

now when i use ntohl() in the above code, i got segmentation fault.
when i remove it, application work fine.
can u tell me whats root cause of segmentation fault .

amit
# 5  
Old 04-18-2008
How is HeadderFun declared? (Should it be HeaderFun?)
# 6  
Old 04-18-2008
Quote:
Originally Posted by amitpansuria
helo my code is given below

static HeadderFun* listheader_ntoh(HeadderFun* lh)
{
lh->head_len = ntohl(lh->cl_head_len);
lh->record_len = ntohl(lh->cl_record_len);
lh->linecnt = ntohl(lh->cl_linecnt);
return lh;
}

now when i use ntohl() in the above code, i got segmentation fault.
when i remove it, application work fine.
can u tell me whats root cause of segmentation fault .

amit
Hi,
Is lh correctly initialized (malloc, etc...) ?
Is the size of lh->linecnt really a long (4-bytes) ???
# 7  
Old 04-18-2008
Quote:
Originally Posted by era
How is HeadderFun declared? (Should it be HeaderFun?)
I m sorry i give wrong code format.
the right code is given below

static ListHeader* listheader_ntoh(ListHeader* lh)
{
lh->head_len = ntohl(lh->cl_head_len);
lh->record_len = ntohl(lh->cl_record_len);
lh->linecnt = ntohl(lh->cl_linecnt);
return lh;
}

// here ListHeader is a structure for the List format.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. Programming

segmentation fault

ive written my code in C for implementation of a simple lexical analyser using singly linked list hence am making use of dynamic allocation,but when run in linux it gives a segmentation fault is it cause of the malloc function that ive made use of????any suggestions as to what i could do??? thank... (8 Replies)
Discussion started by: rockgal
8 Replies

7. 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

8. Programming

segmentation fault

sometimes for this code i get a segmentation fault for codes llike this : int main{ int * a= 0; int b; a = (int*)malloc(sizeof(int)); ///some code using these variable but no freeing of a if(a){ free(a); a = 0; } return... (3 Replies)
Discussion started by: wojtyla
3 Replies

9. AIX

Segmentation fault

I am tring to install Lotus Domino/Notes 5.0.5 on a AIX 4.3.3 server. I go to run the cdrom/ibmpow/install and I get the following error. Lotus Notes for Unix Install Program --------------------------------------------- ./install: 10088 Segmentation fault This had Lotus Notes installed... (1 Reply)
Discussion started by: jshaulis
1 Replies

10. Programming

segmentation fault

hi all i'm trying to execute a c program under linux RH and it gives me segmentation fault, this program was running under unix at&t anybody kow what the problem could be? thanx in advance regards (2 Replies)
Discussion started by: omran
2 Replies
Login or Register to Ask a Question