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
sv_funcs.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
- /* sv_funcs.c - TCPechod, TCPchargend, TCPdaytimed, TCPtimed */
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <time.h>
- #include <string.h>
- #define BUFFERSIZE 4096 /* max read buffer size */
- extern int errno;
- void TCPechod(int), TCPchargend(int), TCPdaytimed(int), TCPtimed(int);
- int errexit(const char *format, ...);
- /*------------------------------------------------------------------------
- * TCPecho - do TCP ECHO on the given socket
- *------------------------------------------------------------------------
- */
- void
- TCPechod(int fd)
- {
- char buf[BUFFERSIZE];
- int cc;
- while (cc = read(fd, buf, sizeof buf)) {
- if (cc < 0)
- errexit("echo read: %sn", strerror(errno));
- if (write(fd, buf, cc) < 0)
- errexit("echo write: %sn", strerror(errno));
- }
- }
- #define LINELEN 72
- /*------------------------------------------------------------------------
- * TCPchargend - do TCP CHARGEN on the given socket
- *------------------------------------------------------------------------
- */
- void
- TCPchargend(int fd)
- {
- char c, buf[LINELEN+2]; /* print LINELEN chars + rn */
- c = ' ';
- buf[LINELEN] = 'r';
- buf[LINELEN+1] = 'n';
- while (1) {
- int i;
- for (i=0; i<LINELEN; ++i) {
- buf[i] = c++;
- if (c > '~')
- c = ' ';
- }
- if (write(fd, buf, LINELEN+2) < 0)
- break;
- }
- }
- /*------------------------------------------------------------------------
- * TCPdaytimed - do TCP DAYTIME protocol
- *------------------------------------------------------------------------
- */
- void
- TCPdaytimed(int fd)
- {
- char buf[LINELEN], *ctime();
- time_t now;
- (void) time(&now);
- sprintf(buf, "%s", ctime(&now));
- (void) write(fd, buf, strlen(buf));
- }
- #define UNIXEPOCH 2208988800UL /* UNIX epoch, in UCT secs */
- /*------------------------------------------------------------------------
- * TCPtimed - do TCP TIME protocol
- *------------------------------------------------------------------------
- */
- void
- TCPtimed(int fd)
- {
- time_t now;
- (void) time(&now);
- now = htonl((unsigned long)(now + UNIXEPOCH));
- (void) write(fd, (char *)&now, sizeof(now));
- }