Last change
on this file since 636 was
49,
checked in by Sam Hocevar, 15 years ago
|
- Imported original public domain release, for future reference.
|
-
Property svn:keywords set to
Id
|
File size:
1.8 KB
|
Line | |
---|
1 | #include "jnet.hpp" |
---|
2 | #include "macs.hpp" |
---|
3 | #include "dprint.hpp" |
---|
4 | #include "system.h" |
---|
5 | #include "ipx.hpp" |
---|
6 | #include "bwtcp.hpp" |
---|
7 | #include "jmalloc.hpp" |
---|
8 | |
---|
9 | |
---|
10 | char last_sock_err[200]; |
---|
11 | int current_sock_err=0; |
---|
12 | |
---|
13 | |
---|
14 | void set_sock_err(int x) { current_sock_err=x; } |
---|
15 | static int prot=NONET_PROTOCOL; |
---|
16 | |
---|
17 | |
---|
18 | int net_init(int protocol) |
---|
19 | { |
---|
20 | if (protocol==TCPIP_PROTOCOL) |
---|
21 | { |
---|
22 | if (bwt_init()) |
---|
23 | { |
---|
24 | prot=TCPIP_PROTOCOL; |
---|
25 | return 1; |
---|
26 | } |
---|
27 | return 0; |
---|
28 | } |
---|
29 | else if (protocol==IPX_PROTOCOL) |
---|
30 | { |
---|
31 | if (ipx_init()) |
---|
32 | { |
---|
33 | prot=IPX_PROTOCOL; |
---|
34 | return 1; |
---|
35 | } |
---|
36 | return 0; |
---|
37 | } |
---|
38 | else return 0; |
---|
39 | } |
---|
40 | |
---|
41 | void net_uninit() |
---|
42 | { |
---|
43 | if (prot==TCPIP_PROTOCOL) |
---|
44 | bwt_uninit(); |
---|
45 | else if (prot==IPX_PROTOCOL) |
---|
46 | ipx_uninit(); |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | in_socket *create_in_socket(int port) |
---|
52 | { |
---|
53 | switch (prot) |
---|
54 | { |
---|
55 | case TCPIP_PROTOCOL : |
---|
56 | { return new bwt_in_socket(port); } break; |
---|
57 | case IPX_PROTOCOL : |
---|
58 | { return new ipx_in_socket(port); } break; |
---|
59 | } |
---|
60 | return NULL; |
---|
61 | } |
---|
62 | |
---|
63 | out_socket *create_out_socket(char *name, int port) |
---|
64 | { |
---|
65 | switch (prot) |
---|
66 | { |
---|
67 | case TCPIP_PROTOCOL : |
---|
68 | { |
---|
69 | bwt_out_socket *o=new bwt_out_socket(); |
---|
70 | if (o->try_connect(name,port)) |
---|
71 | return o; |
---|
72 | else { delete o; return NULL; } |
---|
73 | } break; |
---|
74 | case IPX_PROTOCOL : |
---|
75 | { |
---|
76 | ipx_out_socket *o=new ipx_out_socket(port); |
---|
77 | if (o->try_connect(name,port)) |
---|
78 | return o; |
---|
79 | else { delete o; return NULL; } |
---|
80 | } break; |
---|
81 | } |
---|
82 | return NULL; |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | uchar *get_local_address() // same format as above (be sure to jfree this) |
---|
88 | { |
---|
89 | switch (prot) |
---|
90 | { |
---|
91 | case IPX_PROTOCOL : |
---|
92 | { |
---|
93 | return ipx_get_local_address(); |
---|
94 | } break; |
---|
95 | case TCPIP_PROTOCOL : |
---|
96 | { |
---|
97 | uchar *b=(uchar *)jmalloc(4,"TCPIP address"); |
---|
98 | *((int *)b)=bwt_get_my_ip(); |
---|
99 | return b; |
---|
100 | } break; |
---|
101 | } |
---|
102 | return NULL; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | out_socket::~out_socket() |
---|
107 | { ; } |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | |
---|
114 | |
---|
115 | |
---|
Note: See
TracBrowser
for help on using the repository browser.