本帖最后由 sinanjj 于 2011-10-10 08:52 编辑
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#define PORT 843
int main (int argc, char **argv)
{
int listen_fd;
if ((listen_fd = socket (PF_INET, SOCK_STREAM, 0)) < 0) { printf ("socket() error\n"); exit (0); }
struct sockaddr_in acceptAddr; bzero(&acceptAddr, sizeof(acceptAddr));
acceptAddr.sin_family = PF_INET;
acceptAddr.sin_addr.s_addr = htonl (INADDR_ANY);
acceptAddr.sin_port = htons (PORT);
if (bind(listen_fd, (struct sockaddr *)&acceptAddr, sizeof(acceptAddr)) != 0) { printf("bind() error\n"); exit(0); }
if (listen (listen_fd, 1000) != 0) { printf("listen() error\n"); exit(0); }
signal(SIGPIPE, SIG_IGN);
for(;;) {
struct sockaddr_in clientAddr; bzero(&clientAddr, sizeof(clientAddr));
int clientSockfd, len;
len = sizeof (clientAddr);
clientSockfd = accept (listen_fd, (struct sockaddr *)&clientAddr, (socklen_t *)&len); /* accept() creates a new connected socket file descriptor. */
char *data = "<?xml version=\"1.0\"?><cross-domain-policy><site-control permitted-cross-domain-policies=\"all\"/><allow-access-from domain=\"*\" to-ports=\"*\"/></cross-domain-policy>\x00";
write (clientSockfd, data, (strlen(data)+1));
shutdown(clientSockfd, SHUT_RDWR); close (clientSockfd); /* close file descriptor */
}
return 0;
}
|