00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdio.h>
00022 #include "vfer_tests.h"
00023 #include "vfer_api.h"
00024
00025
00026 vfer_fd listen_skt;
00027 int port;
00028
00029
00030 int main(int argc, char** argv) {
00031 struct sockaddr_in sa;
00032 struct sockaddr_in sa_accepted;
00033 socklen_t accepted_len;
00034 vfer_fd skt_accepted;
00035 int port = 2005;
00036 char buf[INET_ADDRSTRLEN];
00037 int ret;
00038
00039 if (argc != 2) {
00040 printf("usage: %s [port]\n", argv[0]);
00041 return -1;
00042 }
00043
00044 TEST_INIT("TEST_SERVER", "test_server.c", stdout, stdout);
00045 vfer_debug(stdout, stdout, "scap");
00046
00047 port = atoi(argv[1]);
00048
00049 bzero((char*)(&sa), sizeof(sa));
00050 sa.sin_family = AF_INET;
00051 sa.sin_addr.s_addr = htonl(INADDR_ANY);
00052 sa.sin_port = htons(port);
00053
00054 listen_skt = vfer_socket (SOCK_DGRAM);
00055 if (listen_skt < 0) {
00056 TEST_PRINT("main", "vfer_socket failed");
00057 return 1;
00058 }
00059
00060 if ((ret = vfer_bind (listen_skt, (struct sockaddr*) &sa, sizeof(sa))) < 0) {
00061 TEST_PRINT("main", "vfer_bind failed");
00062 vfer_errortext(ret);
00063 return 1;
00064 }
00065 if ((ret = vfer_listen (listen_skt, 3)) < 0) {
00066 TEST_PRINT("main", "vfer_listen failed");
00067 TEST_PRINT("main", "%s", vfer_errortext(ret));
00068 return 1;
00069 }
00070
00071 while (1) {
00072 if ((skt_accepted = vfer_accept(listen_skt, (SA*)(&sa_accepted), &accepted_len)) < 0) {
00073 TEST_PRINT("main", "test_server2.c: vfer_accept failed");
00074 vfer_errortext(skt_accepted);
00075 } else {
00076 TEST_PRINT("main", "vfer_accept successfull");
00077 TEST_PRINT("main", "accepted new connection from: %s.%d",
00078 inet_ntop(AF_INET, &(sa_accepted.sin_addr),buf, INET_ADDRSTRLEN),
00079 ntohs(sa_accepted.sin_port));
00080 }
00081 }
00082
00083 vfer_close(listen_skt);
00084 return 0;
00085 }