-
Notifications
You must be signed in to change notification settings - Fork 1
/
mbind.c
74 lines (55 loc) · 1.58 KB
/
mbind.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "marignotti.h"
#include <gno/kerntool.h>
#include <errno.h>
#include <string.h>
#include <sys/socket.h>
#include "s16debug.h"
#pragma noroot
#pragma optimize 79
int mbind(Entry *e, void *p1, void *p2, void *p3, void *p4, void *p5)
{
Word port;
Word t;
Word terr;
xsockaddr_in *addr = (xsockaddr_in *)p3;
int addrlen = p4 ? *(int *)p4 : 0;
port = addr->sin_port;
asm {
lda <port
xba
sta <port
}
if (Debug > 0)
{
union xsplit s;
s.i32 = addr->sin_addr;
s16_debug_printf("bind family = %d address = %d.%d.%d.%d port = %d",
addr->sin_family,
s.i8[0], s.i8[1], s.i8[2], s.i8[3],
port);
}
if (e->_TYPE != SOCK_STREAM)
return EOPNOTSUPP;
if (addrlen < 8 || !addr) return EINVAL;
if (addr->sin_family != AF_INET) return EINVAL;
// don't re-bind if listen() or connect() called.
IncBusy();
terr = TCPIPStatusTCP(e->ipid, &e->sr);
if (t) terr = t;
e->terr = t;
DecBusy();
if (e->sr.srState != TCPSCLOSED) return EINVAL;
// address component is ignored -- only port is used.
// bind w/ port 0 means the system should pick a port.
// marinetti picks a port at TCPIPLogin time, so no need
// to do anything here.
// Note: TCPIPSetSourcePort does not check if the port is free.
// todo -- return EACCES if reserved port && !root.
if (port)
{
IncBusy();
TCPIPSetSourcePort(e->ipid, port);
DecBusy();
}
return 0;
}