made a minor change in making a new socket device

This commit is contained in:
hyung-hwan 2016-04-26 05:54:48 +00:00
parent e8d5784756
commit 60cff400ac
2 changed files with 25 additions and 10 deletions

View File

@ -67,7 +67,7 @@ static void* mmgr_alloc (stio_mmgr_t* mmgr, stio_size_t size)
{
void* x;
if (((mmgr_stat_t*)mmgr->ctx)->total_count > 100)
if (((mmgr_stat_t*)mmgr->ctx)->total_count > 300)
{
printf ("CRITICAL ERROR ---> too many heap chunks...\n");
return STIO_NULL;
@ -451,19 +451,27 @@ static int icmp_sck_on_read (stio_dev_sck_t* dev, const void* data, stio_iolen_t
{
/* TODO: consider IP options... */
iphdr = (stio_iphdr_t*)data;
icmphdr = (stio_icmphdr_t*)((stio_uint8_t*)data + (iphdr->ihl * 4));
/* TODO: check srcaddr against target */
if (icmphdr->type == STIO_ICMP_ECHO_REPLY &&
stio_ntoh16(icmphdr->u.echo.seq) == icmpxtn->icmp_seq) /* TODO: more check.. echo.id.. */
if (iphdr->ihl * 4 + STIO_SIZEOF(*icmphdr) > dlen)
{
icmpxtn->reply_received = 1;
printf ("ICMP REPLY RECEIVED...ID %d SEQ %d\n", (int)stio_ntoh16(icmphdr->u.echo.id), (int)stio_ntoh16(icmphdr->u.echo.seq));
printf ("INVALID ICMP PACKET.. WRONG IHL...%d\n", (int)iphdr->ihl * 4);
}
else
{
printf ("GARBAGE ICMP PACKET...LEN %d SEQ %d,%d\n", (int)dlen, (int)icmpxtn->icmp_seq, (int)stio_ntoh16(icmphdr->u.echo.seq));
icmphdr = (stio_icmphdr_t*)((stio_uint8_t*)data + (iphdr->ihl * 4));
/* TODO: check srcaddr against target */
if (icmphdr->type == STIO_ICMP_ECHO_REPLY &&
stio_ntoh16(icmphdr->u.echo.seq) == icmpxtn->icmp_seq) /* TODO: more check.. echo.id.. */
{
icmpxtn->reply_received = 1;
printf ("ICMP REPLY RECEIVED...ID %d SEQ %d\n", (int)stio_ntoh16(icmphdr->u.echo.id), (int)stio_ntoh16(icmphdr->u.echo.seq));
}
else
{
printf ("GARBAGE ICMP PACKET...LEN %d SEQ %d,%d\n", (int)dlen, (int)icmpxtn->icmp_seq, (int)stio_ntoh16(icmphdr->u.echo.seq));
}
}
}
return 0;

View File

@ -324,7 +324,8 @@ static struct sck_type_map_t sck_type_map[] =
/* STIO_DEV_SCK_DGRAM */
{ AF_LINK, SOCK_DGRAM, STIO_CONST_HTON16(STIO_ETHHDR_PROTO_ARP), 0 },
#else
# error UNSUPPORTED DATA LINK ADDRESS
{ -1, 0, 0, 0 },
{ -1, 0, 0, 0 },
#endif
/* STIO_DEV_SCK_ICMP4 - IP protocol field is 1 byte only. no byte order conversion is needed */
@ -414,6 +415,12 @@ static int dev_sck_make (stio_dev_t* dev, void* ctx)
STIO_ASSERT (arg->type >= 0 && arg->type < STIO_COUNTOF(sck_type_map));
if (sck_type_map[arg->type].domain <= -1)
{
dev->stio->errnum = STIO_ENOIMPL;
return -1;
}
rdev->sck = stio_openasyncsck (dev->stio, sck_type_map[arg->type].domain, sck_type_map[arg->type].type, sck_type_map[arg->type].proto);
if (rdev->sck == STIO_SCKHND_INVALID) goto oops;