gethostbyaddr -> segmentation fault

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://listman.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux