1/*
2  Copyright (C) 2000-2005 SKYRIX Software AG
3
4  This file is part of SOPE.
5
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
9  later version.
10
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.
15
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
19  02111-1307, USA.
20*/
21
22#include "NGInternetSocketDomain.h"
23#include "NGInternetSocketAddress.h"
24#include "common.h"
25
26#ifndef __MINGW32__
27#  include <netinet/in.h>
28#endif
29
30@implementation NGInternetSocketDomain
31
32static NGInternetSocketDomain *domain = nil;
33
34+ (void)initialize {
35  if (domain == nil) domain = [[NGInternetSocketDomain alloc] init];
36}
37+ (id)domain {
38  return domain;
39}
40
41/* NGSocketDomain */
42
43- (id<NGSocketAddress>)addressWithRepresentation:(void *)_data
44  size:(unsigned int)_size
45{
46  NGInternetSocketAddress *address = nil;
47
48  if ((unsigned int)[self addressRepresentationSize] != _size) {
49    NSLog(@"%@: invalid address size %i ..", NSStringFromSelector(_cmd), _size);
50    return nil;
51  }
52
53  address = [[NGInternetSocketAddress allocWithZone:[self zone]]
54                                      initWithDomain:self
55                                      internalRepresentation:_data
56                                      size:_size];
57  return [address autorelease];
58}
59
60- (BOOL)prepareAddress:(id<NGSocketAddress>)_address
61  forBindWithSocket:(id<NGSocket>)_socket
62{
63  // nothing to prepare
64  return YES;
65}
66- (BOOL)cleanupAddress:(id<NGSocketAddress>)_address
67  afterCloseOfSocket:(id<NGSocket>)_socket
68{
69  // nothing to cleanup
70  return YES;
71}
72
73- (int)socketDomain {
74  return AF_INET;
75}
76
77- (int)addressRepresentationSize {
78  return sizeof(struct sockaddr_in);
79}
80
81- (int)protocol {
82  return 0;
83}
84
85/* NSCopying */
86
87- (id)copyWithZone:(NSZone *)_zone {
88  /* domain objects are immutable, just retain on copy */
89  return [self retain];
90}
91
92/* NSCoding */
93
94- (void)encodeWithCoder:(NSCoder *)_encoder {
95}
96- (id)initWithCoder:(NSCoder *)_decoder {
97  [self release]; self = nil;
98  return [domain retain];
99}
100
101- (id)awakeAfterUsingCoder:(NSCoder *)_decoder {
102  if (self != domain) {
103    [self release]; self = nil;
104    return [domain retain];
105  }
106  else
107    return self;
108}
109
110/* description */
111
112- (NSString *)description {
113  return [NSString stringWithFormat:@"<InternetDomain[0x%p]>", self];
114}
115
116@end /* NGInternetSocketDomain */
117