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
udphdr.c
Package: export.zip [view]
Upload User: hepax88
Upload Date: 2007-01-03
Package Size: 1101k
Code Size: 2k
Category:
TCP/IP Stack
Development Platform:
Visual C++
- /* UDP header conversion routines
- * Copyright 1991 Phil Karn, KA9Q
- */
- #include "global.h"
- #include "mbuf.h"
- #include "ip.h"
- #include "internet.h"
- #include "udp.h"
- /* Convert UDP header in internal format to an mbuf in external format */
- void
- htonudp(
- struct udp *udp,
- struct mbuf **bpp,
- struct pseudo_header *ph
- ){
- register uint8 *cp;
- uint16 checksum;
- /* Allocate UDP protocol header and fill it in */
- pushdown(bpp,NULL,UDPHDR);
- cp = (*bpp)->data;
- cp = put16(cp,udp->source); /* Source port */
- cp = put16(cp,udp->dest); /* Destination port */
- cp = put16(cp,udp->length); /* Length */
- *cp++ = 0; /* Clear checksum */
- *cp-- = 0;
- /* All zeros and all ones is equivalent in one's complement arithmetic;
- * the spec requires us to change zeros into ones to distinguish an
- * all-zero checksum from no checksum at all
- */
- if((checksum = cksum(ph,*bpp,ph->length)) == 0)
- checksum = 0xffff;
- put16(cp,checksum);
- }
- /* Convert UDP header in mbuf to internal structure */
- int
- ntohudp(
- struct udp *udp,
- struct mbuf **bpp
- ){
- uint8 udpbuf[UDPHDR];
- if(pullup(bpp,udpbuf,UDPHDR) != UDPHDR)
- return -1;
- udp->source = get16(&udpbuf[0]);
- udp->dest = get16(&udpbuf[2]);
- udp->length = get16(&udpbuf[4]);
- udp->checksum = get16(&udpbuf[6]);
- return 0;
- }
- /* Extract UDP checksum value from a network-format header without
- * disturbing the header
- */
- uint16
- udpcksum(
- struct mbuf *bp
- ){
- struct mbuf *dup;
- if(dup_p(&dup,bp,6,2) != 2)
- return 0;
- return pull16(&dup);
- }