/* CLISERVER - SERVER CONNESSION LESS SU INTERNET */ #include #include #include #include #include #include #define BUFSZ 256 #define DATA "012345678901234567890123456789..." int ceposta(); int sock, sock, length, flength,i; struct sockaddr_in name, fromname; int buf[BUFSZ]; main() { if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { perror("server:socket"); exit(1); } name.sin_family = AF_INET; name.sin_addr.s_addr = INADDR_ANY; /* name.sin_port =0; */ name.sin_port =htons(2000); length = sizeof(name); fromname.sin_family = AF_INET; fromname.sin_addr.s_addr = INADDR_ANY; fromname.sin_port =0; flength = sizeof(fromname); if (bind(sock, &name, sizeof name) < 0) { perror("server: bind"); exit(1); } signal(SIGIO, ceposta); if (fcntl(sock,F_SETOWN, getpid()) <0){ perror("fcntl F_SETOWN"); exit(1); } if (fcntl(sock,F_SETFL, FASYNC) <0){ perror("fcntl FASYNC"); exit(1); } printf("socket port #%d\n", ntohs(name.sin_port)); i = 0; while (1) { printf("\r%d",i); } close(sock); exit(0); } int ceposta() { if (recvfrom(sock,buf, sizeof(buf),0, &fromname, &flength) <0) perror("receiving datagram pocket"); buf[2]=++i; if (sendto(sock,buf, sizeof(buf),0, (struct sockaddr*) &fromname, sizeof fromname) < 0) perror("sending datagram pocket"); }