www.pudn.com > ejip.zip > Udp.java


/* 
 * Copyright (c) Martin Schoeberl, martin@jopdesign.com 
 * All rights reserved. 
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met: 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in the 
 *    documentation and/or other materials provided with the distribution. 
 * 3. All advertising materials mentioning features or use of this software 
 *    must display the following acknowledgement: 
 *	This product includes software developed by Martin Schoeberl 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
 * SUCH DAMAGE. 
 * 
 */ 
 
package ejip; 
 
/* 
*   Changelog: 
*		2002-10-24	creation. 
* 
* 
*/ 
 
import util.*; 
 
/** 
*	UDP functions. 
*/ 
 
public class Udp { 
 
	public static final int PROTOCOL = 17; 
 
	public static final int HEAD = 5;	// offset of data in words 
	public static final int DATA = 7;	// offset of data in words 
	static int count; 
 
	static void process(Packet p) { 
 
		int i, j; 
		int[] buf = p.buf; 
 
		int port = buf[HEAD]; 
		int remport = port >>> 16; 
		port &= 0xffff; 
 
/* 
if (port!=1625) { 
Dbg.wr('\n'); 
Dbg.wr('U'); 
Dbg.intVal(port); 
} 
*/ 
		if (port == Tftp.PORT) { 
			 
			Tftp.process(p); 
 
		} else if (port == 1625) { 
 
			// do the Dgb thing! 
			i = Dbg.readBuffer(buf, 7); 
			p.len = 28+i; 
 
		} else { 
			p.len = 0; 
			return; 
		} 
 
		if (p.len==0) return; 
 
		// 'exchange' port numbers 
		buf[HEAD] = (port<<16) + remport; 
 
		// Fill in UDP header 
		buf[HEAD+1] = (p.len-20)<<16; 
		buf[2] = (PROTOCOL<<16) + p.len - 20; 		// set protocol and udp length in iph checksum for tcp checksum 
		i = TcpIp.chkSum(buf, 2, p.len-8); 
		if (i==0) i = 0xffff; 
		buf[HEAD+1] |= i; 
	 
	} 
 
}