2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NGDatagramPacket.h"
26 @implementation NGDatagramPacket
28 + (id)packetWithData:(NSData *)_data {
29 return [[[self alloc] initWithData:_data] autorelease];
31 + (id)packetWithBytes:(const void *)_bytes size:(int)_packetSize {
32 return [[[self alloc] initWithBytes:_bytes size:_packetSize] autorelease];
35 - (id)initWithBytes:(const void *)_bytes size:(int)_packetSize {
36 return [self initWithData:[NSData dataWithBytes:_bytes length:_packetSize]];
38 - (id)initWithData:(NSData *)_data {
39 if ((self = [self init])) {
40 self->packet = [_data copyWithZone:[self zone]];
46 [self->packet release];
47 [self->sender release];
48 [self->receiver release];
54 - (void)setSender:(id<NGSocketAddress>)_address {
55 ASSIGN(self->sender, _address);
57 - (id<NGSocketAddress>)sender {
61 - (void)setReceiver:(id<NGSocketAddress>)_address {
62 ASSIGN(self->receiver, _address);
64 - (id<NGSocketAddress>)receiver {
65 return self->receiver;
68 - (void)setData:(NSData *)_data {
69 ASSIGN(self->packet, _data);
76 return [self->packet length];
81 - (void)reverseAddresses {
82 id oldSender = [[self sender] retain];
83 [self setSender:[self receiver]];
84 [self setReceiver:oldSender];
85 [oldSender release]; oldSender = nil;
90 - (NSString *)description {
91 return [NSString stringWithFormat:@"<%@[0x%08X]: from=%@ to=%@ size=%i>",
92 NSStringFromClass([self class]), (unsigned)self,
93 [self sender], [self receiver], [self packetSize]];
96 @end /* NGDatagramPacket */