2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGDatagramPacket.h"
25 @implementation NGDatagramPacket
27 + (id)packetWithData:(NSData *)_data {
28 return [[[self alloc] initWithData:_data] autorelease];
30 + (id)packetWithBytes:(const void *)_bytes size:(int)_packetSize {
31 return [[[self alloc] initWithBytes:_bytes size:_packetSize] autorelease];
34 - (id)initWithBytes:(const void *)_bytes size:(int)_packetSize {
35 return [self initWithData:[NSData dataWithBytes:_bytes length:_packetSize]];
37 - (id)initWithData:(NSData *)_data {
38 if ((self = [self init])) {
39 self->packet = [_data copyWithZone:[self zone]];
45 [self->packet release];
46 [self->sender release];
47 [self->receiver release];
53 - (void)setSender:(id<NGSocketAddress>)_address {
54 ASSIGN(self->sender, _address);
56 - (id<NGSocketAddress>)sender {
60 - (void)setReceiver:(id<NGSocketAddress>)_address {
61 ASSIGN(self->receiver, _address);
63 - (id<NGSocketAddress>)receiver {
64 return self->receiver;
67 - (void)setData:(NSData *)_data {
68 ASSIGN(self->packet, _data);
75 return [self->packet length];
80 - (void)reverseAddresses {
81 id oldSender = [[self sender] retain];
82 [self setSender:[self receiver]];
83 [self setReceiver:oldSender];
84 [oldSender release]; oldSender = nil;
89 - (NSString *)description {
90 return [NSString stringWithFormat:@"<%@[0x%p]: from=%@ to=%@ size=%i>",
91 NSStringFromClass([self class]), self,
92 [self sender], [self receiver], [self packetSize]];
95 @end /* NGDatagramPacket */