-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
805 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#include "marignotti.h" | ||
#include <gno/kerntool.h> | ||
#include <errno.h> | ||
#include "net.h" | ||
|
||
#pragma noroot | ||
#pragma optimize 79 | ||
|
||
int block(int sem) | ||
{ | ||
int xerrno = 0; | ||
Kswait(sem, &xerrno); | ||
return xerrno; | ||
} | ||
|
||
int queue_command(Entry *e, word command, LongWord cookie, LongWord timeout) | ||
{ | ||
int xerrno; | ||
|
||
SEI(); | ||
e->command = kCommandRead; | ||
e->cookie = cookie; | ||
e->timeout = timeout; | ||
CLI(); | ||
|
||
xerrno = 0; | ||
Kswait(e->semaphore, &xerrno); | ||
return xerrno; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#pragma databank 1 | ||
|
||
int driver( | ||
int socknum, int req, | ||
void *p1, void *p2, | ||
void *p3, void *p4, void *p5) | ||
{ | ||
int rv; | ||
Entry *e; | ||
|
||
if (req == PRU_ATTACH) | ||
{ | ||
return mattach(socknum, p1, p2, p3, p4, p5); | ||
} | ||
|
||
e = find_entry(socknum); | ||
if (!e) | ||
{ | ||
if (req == PRU_RCVD || req == PRU_SEND) | ||
*(LongWord *)p2 = 0; | ||
|
||
return EBADF; | ||
} | ||
|
||
switch (req) | ||
{ | ||
case PRU_ABORT: | ||
break; | ||
|
||
case PRU_ACCEPT: | ||
break; | ||
|
||
case PRU_ATTACH: | ||
// KERNsocket(int domain, int type, int protocol, int *ERRNO); | ||
// handled above. | ||
break; | ||
|
||
case PRU_BIND: | ||
// KERNbind(int fd, struct sockaddr *my_addr, int addrlen, int *ERRNO) | ||
//return do_bind(socknum, m, m_len, addr, addrlen, rights); | ||
return 0; | ||
break; | ||
|
||
case PRU_CONNECT: | ||
// KERNconnect(int fd, struct sockaddr *serv_addr, | ||
// int addrlen, int *ERRNO) | ||
return mconnect(e, p1, p2, p3, p4, p5); | ||
break; | ||
|
||
case PRU_CONNECT2: | ||
break; | ||
|
||
case PRU_CONTROL: | ||
break; | ||
|
||
case PRU_DETACH: | ||
// called from GS/OS | ||
// int SOCKclose(int sock) part 2 | ||
DecBusy(); | ||
rv = mdetach(e, p1, p2, p3, p4, p5); | ||
IncBusy(); | ||
return rv; | ||
break; | ||
|
||
case PRU_DISCONNECT: | ||
// called from GS/OS | ||
// int SOCKclose(int sock) part 1 | ||
//return do_disconnect(socknum, m, m_len, addr, addrlen, rights); | ||
return 0; | ||
break; | ||
|
||
case PRU_LISTEN: | ||
break; | ||
|
||
case PRU_PEERADDR: | ||
break; | ||
|
||
case PRU_RCVD: | ||
// this may be called from GSOS (in which case IncBusy() | ||
// is in effect | ||
// or from KERNrecvfrom (in which case it isn't). | ||
// | ||
// may block, so be nice. | ||
// SOCKrdwr(struct rwPBlock *pb, word cmd, int sock) | ||
DecBusy(); | ||
rv = mread(e, p1, p2, p3, p4, p5); | ||
IncBusy(); | ||
return rv; | ||
break; | ||
|
||
case PRU_RCVOOB: | ||
break; | ||
|
||
case PRU_SEND: | ||
// SOCKrdwr(struct rwPBlock *pb, word cmd, int sock) | ||
// same as above. | ||
DecBusy(); | ||
rv = mwrite(e, p1, p2, p3, p4, p5); | ||
IncBusy(); | ||
return rv; | ||
break; | ||
|
||
case PRU_SENDOOB: | ||
break; | ||
|
||
case PRU_SENSE: | ||
break; | ||
|
||
case PRU_SHUTDOWN: | ||
break; | ||
|
||
case PRU_SOCKADDR: | ||
break; | ||
|
||
case PRU_CO_GETOPT: | ||
break; | ||
|
||
case PRU_CO_SETOPT: | ||
break; | ||
|
||
case PRU_SELECT: | ||
// int SOCKselect(int pid, int fl, int sock) | ||
break; | ||
} | ||
|
||
return EINVAL; | ||
} | ||
|
||
#pragma databank 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#include "marignotti.h" | ||
|
||
#include <memory.h> | ||
#include <texttool.h> | ||
#include <misctool.h> | ||
#include <locator.h> | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <signal.h> | ||
|
||
#include <gno/gno.h> | ||
|
||
#pragma optimize 79 | ||
|
||
int semID = 0; | ||
Word MyID; | ||
Word QuitFlag; | ||
|
||
#pragma databank 0 | ||
void signal_handler(int sig, int code) | ||
{ | ||
WriteLine("\pWe got signal!"); | ||
QuitFlag = 1; | ||
} | ||
|
||
void DisplayMessage(const char *string) | ||
{ | ||
if (string) WriteLine(string); | ||
} | ||
|
||
#pragma databank 0 | ||
|
||
// startup/shutdown flags. | ||
enum { | ||
kLoaded = 1, | ||
kStarted = 2, | ||
kConnected = 4 | ||
}; | ||
|
||
Word StartUp(displayPtr fx) | ||
{ | ||
word status; | ||
word flags = 0; | ||
|
||
// TCPIP is an init, not a tool, so it should always | ||
// be loaded. | ||
|
||
status = TCPIPStatus(); | ||
if (_toolErr) | ||
{ | ||
LoadOneTool(54, 0x0300); | ||
if (_toolErr) return -1; | ||
|
||
status = 0; | ||
flags |= kLoaded; | ||
} | ||
|
||
#if 1 | ||
// require 3.0b3 | ||
if (TCPIPLongVersion() < 0x03006003) | ||
{ | ||
if (fx) fx("Marinetti 3.0b3 is required."); | ||
if (flags & kLoaded) | ||
UnloadOneTool(54); | ||
return -1; | ||
} | ||
#endif | ||
|
||
if (!status) | ||
{ | ||
TCPIPStartUp(); | ||
if (_toolErr) return -1; | ||
flags |= kStarted; | ||
} | ||
|
||
status = TCPIPGetConnectStatus(); | ||
if (!status) | ||
{ | ||
TCPIPConnect(fx); | ||
flags |= kConnected; | ||
} | ||
|
||
return flags; | ||
} | ||
|
||
void ShutDown(word flags, Boolean force, displayPtr fx) | ||
{ | ||
if (flags & kConnected) | ||
{ | ||
TCPIPDisconnect(force, fx); | ||
if (_toolErr) return; | ||
} | ||
if (flags & kStarted) | ||
{ | ||
TCPIPShutDown(); | ||
if (_toolErr) return; | ||
} | ||
if (flags & kLoaded) | ||
{ | ||
UnloadOneTool(54); | ||
} | ||
} | ||
|
||
|
||
int main(int argc, char **argv) | ||
{ | ||
|
||
int flags; | ||
|
||
MyID = MMStartUp(); | ||
|
||
flags = StartUp(DisplayMessage); | ||
|
||
if (flags == -1) exit(1); | ||
|
||
semID = screate(1); | ||
|
||
InstallNetDriver(driver, 0); | ||
|
||
QuitFlag = 0; | ||
|
||
signal(SIGQUIT, signal_handler); | ||
signal(SIGINT, signal_handler); | ||
signal(SIGHUP, signal_handler); | ||
|
||
// SIGUSR to dump table ala netstat? | ||
while (!QuitFlag) | ||
{ | ||
|
||
IncBusy(); | ||
|
||
TCPIPPoll(); | ||
|
||
DecBusy(); | ||
|
||
process_table(); | ||
|
||
asm { cop 0x7f } | ||
} | ||
|
||
InstallNetDriver(NULL, 0); | ||
sdelete(semID); | ||
|
||
destroy_table(); | ||
|
||
ShutDown(flags, 0, DisplayMessage); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.