marignotti/mattach.c

60 lines
1.1 KiB
C
Raw Normal View History

2012-05-05 05:08:27 +00:00
#include "marignotti.h"
#include <gno/kerntool.h>
#include <errno.h>
#include <sys/socket.h>
2012-05-12 01:21:29 +00:00
#include "s16debug.h"
2012-05-05 05:08:27 +00:00
#pragma noroot
#pragma optimize 79
// better known as socket(2)
int mattach(int type, void *p1, void *p2, void *p3, void *p4, void *p5)
{
Word t;
Word ipid;
Entry *e;
// p2 = selwakeup.
2012-05-12 02:47:09 +00:00
selwakeupfx fx = (selwakeupfx)p2;
2012-05-05 05:08:27 +00:00
int protocol = *(int *)p3;
2012-05-12 01:21:29 +00:00
if (Debug > 0)
{
s16_debug_printf("socket type = %d protocol = %d",
type, protocol);
}
2012-05-12 23:44:10 +00:00
switch (type)
{
case SOCK_STREAM:
case SOCK_DGRAM:
break;
default:
return ESOCKTNOSUPPORT;
break;
}
2012-05-05 06:20:05 +00:00
//if (protocol != 6) return EPROTONOSUPPORT;
2012-05-05 05:08:27 +00:00
// TODO -- check protocol? 6 = tcp, 1 = icmp, 17 = udp.
IncBusy();
ipid = TCPIPLogin(MyID, 0, 0, 0, 0x0040);
t = _toolErr;
DecBusy();
if (t) return ENETDOWN;
e = create_entry(ipid);
if (!e)
{
TCPIPLogout(ipid);
return ENOMEM;
}
2012-05-12 02:47:09 +00:00
e->select_fx = fx;
2012-05-12 05:25:36 +00:00
e->_TYPE = type;
2012-05-12 02:47:09 +00:00
2012-05-05 05:08:27 +00:00
*(Word *)p1 = ipid;
return 0;
}