001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.lib.aSocket;
026:
027: import seda.sandStorm.api.*;
028: import seda.sandStorm.core.*;
029: import java.net.*;
030:
031: /**
032: * An AUdpPacket is an extension to BufferElement that supports
033: * specifying the destination address and port for a given packet.
034: *
035: * @author Matt Welsh
036: */
037: public class AUdpPacket extends BufferElement {
038:
039: public InetAddress address = null;
040: public int port = -1;
041:
042: /**
043: * Create an AUdpPacket with the given data, an offset of 0, and a
044: * size of data.length.
045: */
046: public AUdpPacket(byte data[]) {
047: this (data, 0, data.length, null);
048: }
049:
050: /**
051: * Create an AUdpPacket with the given data, an offset of 0, and a
052: * size of data.length, with the given completion queue.
053: */
054: public AUdpPacket(byte data[], SinkIF compQ) {
055: this (data, 0, data.length, compQ);
056: }
057:
058: /**
059: * Create an AUdpPacket with the given data, offset, and size.
060: */
061: public AUdpPacket(byte data[], int offset, int size) {
062: this (data, offset, size, null);
063: }
064:
065: /**
066: * Create an AUdpPacket with the given data, offset, size, and
067: * completion queue.
068: */
069: public AUdpPacket(byte data[], int offset, int size, SinkIF compQ) {
070: super (data, offset, size, compQ);
071: }
072:
073: /**
074: * Create an AUdpPacket with the given data, offset, size,
075: * completion queue, destination address, and port.
076: */
077: public AUdpPacket(byte data[], int offset, int size, SinkIF compQ,
078: InetAddress address, int port) {
079: super (data, offset, size, compQ);
080: this .address = address;
081: this .port = port;
082: }
083:
084: /**
085: * Create an AUdpPacket with a new data array of the given size.
086: */
087: public AUdpPacket(int size) {
088: this (new byte[size], 0, size, null);
089: }
090:
091: /**
092: * Return the destination address. Returns null if not set.
093: */
094: public InetAddress getAddress() {
095: return address;
096: }
097:
098: /**
099: * Return the destination port. Returns -1 if not set.
100: */
101: public int getPort() {
102: return port;
103: }
104:
105: }
|