Watt-32 tcp/ip  2.2 dev-rel.10
oldstuff.c
Go to the documentation of this file.
1 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <time.h>
9 
10 #include "copyrigh.h"
11 #include "wattcp.h"
12 #include "pctcp.h"
13 #include "netaddr.h"
14 #include "strings.h"
15 #include "chksum.h"
16 #include "misc.h"
17 #include "timer.h"
18 #include "pcdns.h"
19 
24 #undef tcp_cbrk
25 int tcp_cbrk (int mode)
26 {
27  return tcp_cbreak (mode);
28 }
29 
34 unsigned long set_ttimeout (unsigned ticks)
35 {
36 #ifdef WIN32
37  DWORD now = set_timeout (0);
38  return (ticks + now);
39 #else
40  int tmp = has_8254;
41  DWORD now;
42 
43  has_8254 = 0;
44  now = set_timeout (0);
45  has_8254 = tmp;
46  return (ticks + now);
47 #endif
48 }
49 
50 /*
51  * Not needed in Watt-32. Print remote tcp address and port.
52  */
53 void W32_CALL psocket (const sock_type *s)
54 {
55  char buf[20];
56 
57  (*_outch) ('[');
58  outs (_inet_ntoa(buf, s->tcp.hisaddr));
59  (*_outch) (':');
60  itoa (s->tcp.hisport, buf, 10);
61  outs (buf);
62  (*_outch) (']');
63 }
64 
69 void W32_CALL sock_sturdy (sock_type *s, int level)
70 {
71  s->tcp.rigid = level;
72  if (s->tcp.rigid < s->tcp.stress)
73  sock_abort (s);
74 }
75 
79 int W32_CALL resolve_ip (DWORD ip, char *name, int len)
80 {
81  return reverse_resolve_ip4 (ip, name, len);
82 }
83 
84 #undef time
85 
86 /*
87  * Some time/date conversion function only (?) found in Borland libs.
88  * Only(?) djgpp/DMC besides Borland have "struct time" etc.
89  */
90 #if defined(__DJGPP__) || defined(__DMC__)
91 time_t dostounix (struct date *d, struct time *t)
92 {
93  struct tm tm;
94 
95  if (!d || !t)
96  return (0);
97 
98  tm.tm_year = d->da_year - 1900;
99  tm.tm_mon = d->da_mon - 1;
100  tm.tm_mday = d->da_day;
101  tm.tm_isdst = 0;
102  tm.tm_hour = t->ti_hour;
103  tm.tm_min = t->ti_min;
104  tm.tm_sec = t->ti_sec;
105  return mktime (&tm);
106 }
107 
108 void unixtodos (time_t time, struct date *d, struct time *t)
109 {
110  struct tm *tm = localtime (&time);
111 
112  if (d && tm)
113  {
114  d->da_year = tm->tm_year;
115  d->da_mon = tm->tm_mon;
116  d->da_day = tm->tm_mday;
117  }
118  if (t && tm)
119  {
120  t->ti_hour = tm->tm_hour;
121  t->ti_min = tm->tm_min;
122  t->ti_sec = tm->tm_sec;
123  t->ti_hund = 0;
124  }
125 }
126 #endif
127 
128 #undef inchksum
129 WORD inchksum (const void *ptr, int len)
130 {
131 #ifdef HAVE_IN_CHECKSUM_FAST
132  return _w32_in_checksum_fast (ptr, len);
133 #else
134  return _w32_in_checksum (ptr, len);
135 #endif
136 }
137 
138 WORD _w32_inchksum (const void *ptr, int len)
139 {
140 #ifdef HAVE_IN_CHECKSUM_FAST
141  return _w32_in_checksum_fast (ptr, len);
142 #else
143  return _w32_in_checksum (ptr, len);
144 #endif
145 }
146 
147 
148 #if !defined(USE_BIGENDIAN) && !defined(WATT32_NO_INLINE_INTEL)
149 /*
150  * If linking old .o-files with new watt*.lib.
151  * Or user didn't include <sys/swap.h> (via tcp.h).
152  */
153 #undef intel
154 #undef intel16
155 #undef htons
156 #undef htonl
157 #undef ntohs
158 #undef ntohl
159 
160 DWORD intel (DWORD val)
161 {
162  return __ntohl (val);
163 }
164 
165 WORD intel16 (WORD val)
166 {
167  return __ntohs (val);
168 }
169 #endif
170 
171 #if defined(TEST_PROG)
172 
173 #if !defined(__MSDOS__)
174 #error For MSDOS only
175 #endif
176 
177 int main (void)
178 {
179  struct date d;
180  struct time t;
181  time_t now = time (NULL);
182 
183  getdate (&d);
184  gettime (&t);
185  printf ("time now is: %s", ctime(&now));
186  now = dostounix (&d, &t);
187  printf ("dostounix(): %s", ctime(&now));
188  printf ("unixtodos(): %02d/%02d/%04d %02d:%02d:%02d\n",
189  d.da_day, d.da_mon, d.da_year,
190  t.ti_hour, t.ti_min, t.ti_sec);
191  return (0);
192 }
193 #endif
194 
int W32_CALL sock_abort(sock_type *s)
Abort a UDP/TCP/Raw socket.
Definition: pctcp.c:2823
int tcp_cbrk(int mode)
Definition: oldstuff.c:25
Core definitions.
int W32_CALL resolve_ip(DWORD ip, char *name, int len)
Resolve an IP-address to a name.
Definition: oldstuff.c:79
DWORD W32_CALL set_timeout(DWORD msec)
Return time for when given timeout (msec) expires.
Definition: timer.c:503
Definition: ip.h:67
unsigned long set_ttimeout(unsigned ticks)
Definition: oldstuff.c:34
BOOL has_8254
Do we have a working 8254 timer chip?
Definition: timer.c:56
int W32_CALL tcp_cbreak(int mode)
Sets our break mode.
Definition: pc_cbrk.c:207
char *W32_CALL _inet_ntoa(char *s, DWORD ip)
Convert an IP-address 'ip' into a string.
Definition: netaddr.c:43
void W32_CALL sock_sturdy(sock_type *s, int level)
Keep the socket open inspite of receiving "ICMP Unreachable" For UDP or TCP socket.
Definition: oldstuff.c:69
int main(int argc, char **argv)
Definition: echo.c:223