marignotti/mattach.c

49 lines
932 B
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.
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-05 05:08:27 +00:00
if (type != SOCK_STREAM) return ESOCKTNOSUPPORT;
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;
}
*(Word *)p1 = ipid;
return 0;
}