/[LeafOK_CVS]/lbbs/src/netio.c
ViewVC logotype

Contents of /lbbs/src/netio.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Tue Mar 22 08:59:32 2005 UTC (21 years ago) by sysadm
Branch: MAIN
CVS Tags: lbbs_1-0-0-0_MIL
Changes since 1.4: +73 -0 lines
Content type: text/x-csrc
*** empty log message ***

1 /***************************************************************************
2 netio.c - description
3 -------------------
4 begin : Mon Oct 18 2004
5 copyright : (C) 2004 by Leaflet
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "common.h"
19 #include <string.h>
20 #include <sys/socket.h>
21
22 char
23 s_getc (int socket)
24 {
25 char c;
26 if (recv (socket, &c, 1, 0) > 0)
27 return c;
28 else
29 return '\0';
30 }
31
32 int
33 s_putc (int socket, char c)
34 {
35 int ret;
36
37 ret = send (socket, &c, 1, 0);
38
39 return ret;
40 }
41
42 int
43 s_receive (int socket, char *buffer, int buffer_length, char end_str[])
44 {
45 char buf_str[2048];
46 int buf_read, total_read;
47 int buf_len = 2047;
48
49 if (buf_len + 1 > buffer_length)
50 buf_len = buffer_length - 1;
51
52 total_read = 0;
53 strcpy (buffer, "");
54 while ((buf_read = recv (socket, buf_str, buf_len, 0)) > 0)
55 {
56 buf_str[buf_read] = '\0';
57 total_read += buf_read;
58 strcat (buffer, buf_str);
59
60 buf_len = buffer_length - total_read - 1;
61 if (buf_len + 1 > buffer_length)
62 buf_len = buffer_length - 1;
63
64 if (strcmp ((buffer + total_read - strlen (end_str)), end_str) == 0)
65 break;
66 //different line-end symbol in different OS
67 if (strcmp (end_str, "\r") == 0)
68 {
69 if (strcmp ((buffer + total_read - 2), "\r\n") == 0)
70 break;
71 }
72 }
73
74 return total_read;
75 }
76
77 int
78 s_send (int socket, const char *in_str)
79 {
80 int ret;
81
82 if (in_str != NULL && strlen (in_str) > 0)
83 {
84 ret = send (socket, in_str, strlen (in_str), 0);
85 }
86
87 return ret;
88 }
89
90 // from Maple-hightman
91 // added by flyriver, 2001.3.3
92 int
93 telnetopt (int fd, char *buf, int max)
94 {
95 unsigned char c, d, e;
96 int pp = 0;
97 unsigned char tmp[30];
98
99 while (pp < max)
100 {
101 c = buf[pp++];
102 if (c == 255)
103 {
104 d = buf[pp++];
105 e = buf[pp++];
106 iflush ();
107 if ((d == 253) && (e == 3 || e == 24))
108 {
109 tmp[0] = 255;
110 tmp[1] = 251;
111 tmp[2] = e;
112 write (fd, tmp, 3);
113 continue;
114 }
115 if ((d == 251 || d == 252) && (e == 1 || e == 3 || e == 24))
116 {
117 tmp[0] = 255;
118 tmp[1] = 253;
119 tmp[2] = e;
120 write (fd, tmp, 3);
121 continue;
122 }
123 if (d == 251 || d == 252)
124 {
125 tmp[0] = 255;
126 tmp[1] = 254;
127 tmp[2] = e;
128 write (fd, tmp, 3);
129 continue;
130 }
131 if (d == 253 || d == 254)
132 {
133 tmp[0] = 255;
134 tmp[1] = 252;
135 tmp[2] = e;
136 write (fd, tmp, 3);
137 continue;
138 }
139 if (d == 250)
140 {
141 while (e != 240 && pp < max)
142 e = buf[pp++];
143 tmp[0] = 255;
144 tmp[1] = 250;
145 tmp[2] = 24;
146 tmp[3] = 0;
147 tmp[4] = 65;
148 tmp[5] = 78;
149 tmp[6] = 83;
150 tmp[7] = 73;
151 tmp[8] = 255;
152 tmp[9] = 240;
153 write (fd, tmp, 10);
154 }
155 }
156 else
157 outc (c);
158 }
159 iflush ();
160 return 0;
161 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1