]> err.no Git - sope/blob - sope-core/NGStreams/NGDatagramPacket.m
do not run autoconf in NGStreams
[sope] / sope-core / NGStreams / NGDatagramPacket.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "NGDatagramPacket.h"
24 #include "common.h"
25
26 @implementation NGDatagramPacket
27
28 + (id)packetWithData:(NSData *)_data {
29   return [[[self alloc] initWithData:_data] autorelease];
30 }
31 + (id)packetWithBytes:(const void *)_bytes size:(int)_packetSize {
32   return [[[self alloc] initWithBytes:_bytes size:_packetSize] autorelease];
33 }
34
35 - (id)initWithBytes:(const void *)_bytes size:(int)_packetSize {
36   return [self initWithData:[NSData dataWithBytes:_bytes length:_packetSize]];
37 }
38 - (id)initWithData:(NSData *)_data {
39   if ((self = [self init])) {
40     self->packet = [_data copyWithZone:[self zone]];
41   }
42   return self;
43 }
44
45 - (void)dealloc {
46   [self->packet   release];
47   [self->sender   release];
48   [self->receiver release];
49   [super dealloc];
50 }
51
52 /* accessors */
53
54 - (void)setSender:(id<NGSocketAddress>)_address {
55   ASSIGN(self->sender, _address);
56 }
57 - (id<NGSocketAddress>)sender {
58   return self->sender;
59 }
60
61 - (void)setReceiver:(id<NGSocketAddress>)_address {
62   ASSIGN(self->receiver, _address);
63 }
64 - (id<NGSocketAddress>)receiver {
65   return self->receiver;
66 }
67
68 - (void)setData:(NSData *)_data {
69   ASSIGN(self->packet, _data);
70 }
71 - (NSData *)data {
72   return self->packet;
73 }
74
75 - (int)packetSize {
76   return [self->packet length];
77 }
78
79 /* operations */
80
81 - (void)reverseAddresses {
82   id oldSender = [[self sender] retain];
83   [self setSender:[self receiver]];
84   [self setReceiver:oldSender];
85   [oldSender release]; oldSender = nil;
86 }
87
88 /* description */
89
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]];
94 }
95
96 @end /* NGDatagramPacket */