Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
TCPdaytimed.c
Package: linux-socket-program.rar [view]
Upload User: wei_4586
Upload Date: 2008-05-28
Package Size: 18k
Code Size: 2k
Category:
Linux Network
Development Platform:
Unix_Linux
- /* TCPdaytimed.c - main */
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <string.h>
- extern int errno;
- int errexit(const char *format, ...);
- void TCPdaytimed(int fd);
- int passiveTCP(const char *service, int qlen);
- #define QLEN 32
- /*------------------------------------------------------------------------
- * main - Iterative TCP server for DAYTIME service
- *------------------------------------------------------------------------
- */
- int
- main(int argc, char *argv[])
- {
- struct sockaddr_in fsin; /* the from address of a client */
- char *service = "daytime"; /* service name or port number */
- int msock, ssock; /* master & slave sockets */
- unsigned int alen; /* from-address length */
- switch (argc) {
- case 1:
- break;
- case 2:
- service = argv[1];
- break;
- default:
- errexit("usage: TCPdaytimed [port]n");
- }
- msock = passiveTCP(service, QLEN);
- while (1) {
- alen = sizeof(fsin);
- ssock = accept(msock, (struct sockaddr *)&fsin, &alen);
- if (ssock < 0)
- errexit("accept failed: %sn", strerror(errno));
- TCPdaytimed(ssock);
- (void) close(ssock);
- }
- }
- /*------------------------------------------------------------------------
- * TCPdaytimed - do TCP DAYTIME protocol
- *------------------------------------------------------------------------
- */
- void
- TCPdaytimed(int fd)
- {
- char *pts; /* pointer to time string */
- time_t now; /* current time */
- char *ctime();
- (void) time(&now);
- pts = ctime(&now);
- (void) write(fd, pts, strlen(pts));
- }