125{
126 int status, sock,
i,
n, header_length, content_length;
127 struct hostent *phe;
128 struct sockaddr_in bind_addr;
130
131#if defined( _MSC_VER )
132 {
133 WSADATA WSAData;
134
135
136 if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
137 return -1;
138 }
139#endif
140
141
143
145 if (phe == NULL) {
146 perror("Cannot retrieve host name");
147 return -1;
148 }
149 phe = gethostbyaddr(phe->h_addr, sizeof(int), AF_INET);
150 if (phe == NULL) {
151 perror("Cannot retrieve host name");
152 return -1;
153 }
154
155
158
159
160 if ((sock =
socket(AF_INET, SOCK_STREAM, 0)) == -1) {
161 perror("cannot create socket");
162 return -1;
163 }
164
165
166 memset(&bind_addr, 0, sizeof(bind_addr));
167 bind_addr.sin_family = AF_INET;
168 bind_addr.sin_addr.s_addr = 0;
169 bind_addr.sin_port = htons((unsigned short) port);
170
171 phe = gethostbyname(host);
172 if (phe == NULL) {
173 perror("cannot get host name");
174 return -1;
175 }
176 memcpy((char *) &(bind_addr.sin_addr), phe->h_addr, phe->h_length);
177
178
179 status = connect(sock, (
struct sockaddr *) &bind_addr,
sizeof(bind_addr));
181 printf("Cannot connect to host %s, port %d\n", host, port);
182 return -1;
183 }
184
186 printf("Successfully connected to host %s, port %d\n", host, port);
187
188
189 strcpy(boundary, "---------------------------7d0bf1a60904bc");
191 strcat(
content,
"\r\nContent-Disposition: form-data; name=\"cmd\"\r\n\r\nSubmit\r\n");
192
193 if (uname[0])
195 "%s\r\nContent-Disposition: form-data; name=\"unm\"\r\n\r\n%s\r\n",
196 boundary, uname);
197
198 if (upwd[0]) {
201 "%s\r\nContent-Disposition: form-data; name=\"upwd\"\r\n\r\n%s\r\n",
203 }
204
205 if (experiment[0])
207 "%s\r\nContent-Disposition: form-data; name=\"exp\"\r\n\r\n%s\r\n",
208 boundary, experiment);
209
210 for (
i = 0;
i < n_attr;
i++)
212 "%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n", boundary,
213 attrib_name[
i], attrib[
i]);
214
216 "%s\r\nContent-Disposition: form-data; name=\"Text\"\r\n\r\n%s\r\n%s\r\n",
217 boundary, text, boundary);
218
219 content_length = strlen(
content);
221
223 if (afilename[
i][0]) {
225 "Content-Disposition: form-data; name=\"attfile%d\"; filename=\"%s\"\r\n\r\n",
226 i + 1, afilename[
i]);
227
228 content_length += strlen(p);
229 p += strlen(p);
230 memcpy(p, buffer[
i], buffer_size[
i]);
232 strcpy(p, boundary);
233 strcat(p, "\r\n");
234
235 content_length += buffer_size[
i] + strlen(p);
236 p += strlen(p);
237 }
238
239
242 "Content-Type: multipart/form-data; boundary=%s\r\n", boundary);
246
247 if (passwd[0]) {
250 }
251
253
254 header_length = strlen(
request);
256
257
258
259
260
261
262
263
264
265
266
268 printf("Request sent to host:\n");
270 }
271
272 send(sock,
request, header_length + content_length, 0);
273
274
277 perror("Cannot receive response");
278 return -1;
279 }
280
281
287 }
289
291
293 printf("Response received:\n");
295 }
296
297
299 printf("Message successfully transmitted\n");
300 else if (strstr(
response,
"Logbook Selection"))
301 printf("No logbook specified\n\n");
302 else if (strstr(
response,
"Enter password"))
303 printf("Missing or invalid password\n");
305 printf("Missing or invalid user name/password\n");
306 else
307 printf("Error transmitting message\n");
308
309 return 1;
310}
void base64_encode(char *s, char *d)