gethostbyaddr -> segmentation fault

Laurent Beausser <[email protected]>
Newsgroups gmane.linux.redhat.devel
Message-ID <[email protected]>
Hello.
I am working on a app which is in fact a sensor who
get packets and treats them according to a security
policy .
Here is one of my functions:
/*------------------------------------------------------------------------------
Name : netLogUdpDatagramme : logs the UDP datagrams
Syntaxe : long netLogUdpDatagramme( struct udphdr
*udp_hdr, struct ctx_t *ctx, char *errmsg)
Description :
Input : udp_hdr = pointer on udp packet
ctx = pointer on communication context
Output : errmsg = pointer on error message
Return : 0 = OK
-1 = PB unknwown status
---------------------------------------------------------------------------------*/
#undef FUNCT
#define FUNCT "netLogUdpDatagramme()"
long
netLogUdpDatagramme (struct msg_syslog msglog, struct
udphdr *udp_hdr,
struct ctx_t *ctx, char *errmsg)
{
struct in_addr ip_src, ip_dst;
struct hostent *sd_id = NULL;
char srcipname[255] = "", dstipname[255] = "";
char srcname[255] = "", dstname[255] = "";
char buff[255] = "";

ip_src.s_addr = ctx->ip_src;
printf("it's gonna break down\n");

/*I GET A SEG FAULT HERE*/sd_id = gethostbyaddr ((char
*) &ip_src.s_addr, sizeof (ip_src.s_addr),AF_INET);
strncpy (srcipname, inet_ntoa (ip_src), 250);
if (sd_id)
strncpy (srcname, sd_id->h_name, 250);
else
strncpy (srcname, srcipname, 250);

ip_dst.s_addr = ctx->ip_dst;
/*HERE TOO*/ sd_id = gethostbyaddr ((char *)
&ip_dst.s_addr, sizeof (ip_dst.s_addr),AF_INET);

strncpy (dstipname, inet_ntoa (ip_dst), 250);
if (sd_id)
strncpy (dstname, sd_id->h_name, 250);
else
strncpy (dstname, dstipname, 250);

if (netUdpMessageDecode (ntohs (udp_hdr->source),
buff) < 0) {
if (netUdpMessageDecode (ntohs (udp_hdr->dest), buff)
< 0)
sprintf (buff, "Unknown UDP service %d %d",
ntohs (udp_hdr->source), ntohs (udp_hdr->dest));
}

if (SyslogMode == 1)
Notify (msglog, ctx);

return (0);
}

I get a segmentation fault at the gethostbyaddr calls.
The signature of this fonction is ok, respected, types
too. i'm under redhat 8.0, kernel 2.4.18-14
i don't understand.
can someone help me :) ?

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.