00001
00002
00003 #include "ace/SOCK_SEQPACK_Association.h"
00004
00005 #include "ace/Auto_Ptr.h"
00006 #include "ace/Log_Msg.h"
00007 #include "ace/OS_Memory.h"
00008 #include "ace/OS_NS_string.h"
00009
00010 #if !defined (__ACE_INLINE__)
00011 #include "ace/SOCK_SEQPACK_Association.inl"
00012 #endif
00013
00014 ACE_RCSID(ace, SOCK_SEQPACK_Association, "SOCK_SEQPACK_Association.cpp,v 4.15 2006/04/19 19:13:09 jwillemsen Exp")
00015
00016 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00017
00018 ACE_ALLOC_HOOK_DEFINE(ACE_SOCK_SEQPACK_Association)
00019
00020 void
00021 ACE_SOCK_SEQPACK_Association::dump (void) const
00022 {
00023 #if defined (ACE_HAS_DUMP)
00024 ACE_TRACE ("ACE_SOCK_SEQPACK_Association::dump");
00025 #endif
00026 }
00027
00028 int
00029 ACE_SOCK_SEQPACK_Association::close (void)
00030 {
00031 #if defined (ACE_WIN32)
00032
00033
00034
00035
00036
00037
00038 this->close_writer ();
00039 #endif
00040
00041 return ACE_SOCK::close ();
00042 }
00043
00044
00045
00046
00047 int
00048 ACE_SOCK_SEQPACK_Association::abort (void)
00049 {
00050
00051
00052
00053
00054 linger slinger;
00055
00056 slinger.l_onoff = 1;
00057 slinger.l_linger = 0;
00058
00059 if (-1 == ACE_OS::setsockopt (this->get_handle (),
00060 SOL_SOCKET,
00061 SO_LINGER,
00062 reinterpret_cast<const char *> (&slinger),
00063 sizeof (linger)))
00064 {
00065 return -1;
00066 }
00067
00068 return this->close ();
00069 }
00070
00071 int
00072 ACE_SOCK_SEQPACK_Association::get_local_addrs (ACE_INET_Addr *addrs, size_t &size) const
00073 {
00074 ACE_TRACE ("ACE_SOCK_SEQPACK_Association::get_local_addrs");
00075
00076 #if defined (ACE_HAS_LKSCTP)
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 sockaddr_in *si = 0;
00095 sockaddr *laddrs = 0;
00096 int err = 0;
00097 size_t len = 0;
00098
00099 err = sctp_getladdrs(this->get_handle(), 0, &laddrs);
00100 if (err > 0)
00101 {
00102 len = err;
00103
00104
00105 if (len > size)
00106 {
00107
00108
00109 len = size;
00110 }
00111
00112 for (size_t i = 0; i < len; i++)
00113 {
00114
00115
00116 si = (sockaddr_in *) (&(laddrs[i]));
00117
00118
00119 addrs[i].set_addr(si, sizeof(sockaddr_in));
00120 addrs[i].set_type(si->sin_family);
00121 addrs[i].set_size(sizeof(sockaddr_in));
00122 }
00123 }
00124 else
00125 {
00126
00127 return -1;
00128 }
00129
00130
00131 size = len;
00132
00133
00134 sctp_freeladdrs(laddrs);
00135
00136 #else
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 ACE_Auto_Array_Ptr<sockaddr_in> addr_structs;
00156
00157
00158
00159
00160
00161 {
00162 sockaddr_in *addr_structs_bootstrap = 0;
00163 ACE_NEW_RETURN (addr_structs_bootstrap, sockaddr_in[size], -1);
00164 addr_structs.reset(addr_structs_bootstrap);
00165 }
00166
00167
00168
00169 size_t physical_size = size * sizeof(sockaddr_in);
00170
00171
00172 ACE_OS::memset(addr_structs.get(),
00173 0,
00174 physical_size);
00175
00176
00177
00178
00179
00180
00181
00182 int name_size = static_cast<int> (physical_size);
00183 if (ACE_OS::getsockname (this->get_handle (),
00184 reinterpret_cast<sockaddr *> (addr_structs.get()),
00185 &name_size) == -1)
00186 return -1;
00187
00188
00189 name_size /= sizeof (sockaddr_in);
00190 size = static_cast<size_t> (name_size);
00191
00192
00193
00194 const int addrlen (static_cast<int> (sizeof (sockaddr_in)));
00195 for (int i = 0; i < name_size; ++i)
00196 {
00197 addrs[i].set_addr (&(addr_structs[i]), addrlen);
00198 addrs[i].set_type (addr_structs[i].sin_family);
00199 addrs[i].set_size (addrlen);
00200 }
00201 #endif
00202 return 0;
00203 }
00204
00205
00206 int
00207 ACE_SOCK_SEQPACK_Association::get_remote_addrs (ACE_INET_Addr *addrs, size_t &size) const
00208 {
00209 ACE_TRACE ("ACE_SOCK_SEQPACK_Association::get_remote_addrs");
00210 #if defined (ACE_HAS_LKSCTP)
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228 sockaddr_in *si = 0;
00229 sockaddr *paddrs = 0;
00230 int err = 0;
00231 size_t len = 0;
00232
00233 err = sctp_getpaddrs(this->get_handle(), 0, &paddrs);
00234 if (err > 0)
00235 {
00236 len = err;
00237
00238
00239 if (len > size)
00240 {
00241
00242
00243 len = size;
00244 }
00245
00246 for (size_t i = 0; i < len; i++)
00247 {
00248
00249
00250 si = (sockaddr_in *) (&(paddrs[i]));
00251
00252
00253 addrs[i].set_addr(si, sizeof(sockaddr_in));
00254 addrs[i].set_type(si->sin_family);
00255 addrs[i].set_size(sizeof(sockaddr_in));
00256 }
00257 }
00258 else
00259 {
00260
00261 return -1;
00262 }
00263
00264
00265 size = len;
00266
00267
00268 sctp_freepaddrs(paddrs);
00269
00270 #else
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 ACE_Auto_Array_Ptr<sockaddr_in> addr_structs;
00290
00291
00292
00293
00294
00295 {
00296 sockaddr_in *addr_structs_bootstrap = 0;
00297 ACE_NEW_RETURN (addr_structs_bootstrap, sockaddr_in[size], -1);
00298 addr_structs.reset(addr_structs_bootstrap);
00299 }
00300
00301
00302
00303 size_t physical_size = size * sizeof(sockaddr_in);
00304
00305
00306 ACE_OS::memset(addr_structs.get(),
00307 0,
00308 physical_size);
00309
00310
00311
00312
00313
00314
00315
00316 int name_size = static_cast<int> (physical_size);
00317 if (ACE_OS::getpeername (this->get_handle (),
00318 reinterpret_cast<sockaddr *> (addr_structs.get()),
00319 &name_size) == -1)
00320 return -1;
00321
00322
00323 name_size /= sizeof (sockaddr_in);
00324 size = static_cast<size_t> (name_size);
00325
00326
00327
00328 const int addrlen (static_cast<int> (sizeof (sockaddr_in)));
00329 for (int i = 0; i < name_size; ++i)
00330 {
00331 addrs[i].set_addr (&(addr_structs[i]), addrlen);
00332 addrs[i].set_type (addr_structs[i].sin_family);
00333 addrs[i].set_size (addrlen);
00334 }
00335 #endif
00336 return 0;
00337 }
00338
00339 ACE_END_VERSIONED_NAMESPACE_DECL