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

Are you invoking ntohl() correctly?

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

How is HeadderFun declared? (Should it be HeaderFun?)

Hi,
Is lh correctly initialized (malloc, etc...) ?
Is the size of lh->linecnt really a long (4-bytes) ???

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.

You need to post the code which declares and initializes the structure you are manipulating.

and please use CODE tags :slight_smile: