version 1.1, 2011/11/02 16:11:09
|
version 1.1.2.1, 2011/11/02 16:11:09
|
Line 0
|
Line 1
|
|
#include <stdio.h> |
|
#include <sys/types.h> |
|
#include <sys/socket.h> |
|
#include <netinet/in.h> |
|
#include <aitio.h> |
|
|
|
|
|
int |
|
main(int argc, char **argv) |
|
{ |
|
int s, c, sl; |
|
struct sockaddr sa; |
|
struct sockaddr_in sin; |
|
|
|
if (argc < 3) |
|
return 1; |
|
|
|
sa.sa_len = sl = sizeof sa; |
|
sin.sin_len = sizeof sin; |
|
sin.sin_family = AF_INET; |
|
sin.sin_port = htons(5000); |
|
sin.sin_addr.s_addr = inet_addr("127.0.0.1"); |
|
|
|
s = socket(AF_INET, SOCK_STREAM, 0); |
|
if (s == -1) { |
|
perror("socket"); |
|
return 2; |
|
} |
|
if (bind(s, (struct sockaddr*) &sin, sizeof sin) == -1) { |
|
perror("bind"); |
|
close(s); |
|
return 3; |
|
} |
|
if (listen(s, 5) == -1) { |
|
perror("listen"); |
|
close(s); |
|
return 4; |
|
} |
|
|
|
if ((c = accept(s, &sa, &sl)) != -1) { |
|
sl = ioRecvFile(c, argv[1], strtol(argv[2], NULL, 0), 0644, argv[3] ? strtol(argv[3], NULL, 0) : 0); |
|
printf("received %d bytes\n", sl); |
|
if (!sl) |
|
printf("#%d - %s\n", io_GetErrno(), io_GetError()); |
|
close(c); |
|
} |
|
|
|
close(s); |
|
return 0; |
|
} |