linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #04459
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2602: Socket fixes
------------------------------------------------------------
revno: 2602
committer: Jacek Sieka <arnetheduck@xxxxxxxxx>
branch nick: dcplusplus
timestamp: Fri 2011-08-26 22:17:04 +0200
message:
Socket fixes
modified:
dcpp/Socket.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/Socket.cpp'
--- dcpp/Socket.cpp 2011-08-19 18:07:56 +0000
+++ dcpp/Socket.cpp 2011-08-26 20:17:04 +0000
@@ -113,9 +113,9 @@
return val;
}
-inline int setSocketOpt2(socket_t sock, int option, int val) {
+inline int setSocketOpt2(socket_t sock, int level, int option, int val) {
int len = sizeof(val);
- return ::setsockopt(sock, SOL_SOCKET, option, (char*)&val, len);
+ return ::setsockopt(sock, level, option, (char*)&val, len);
}
inline bool isConnected(socket_t sock) {
@@ -204,18 +204,21 @@
socket_t Socket::setSock(socket_t s, int af) {
setBlocking2(s, false);
- setSocketOpt2(s, SO_REUSEADDR, 1);
+ setSocketOpt2(s, SOL_SOCKET, SO_REUSEADDR, 1);
-#ifdef IPV6_V6ONLY
- setSocketOpt2(s, IPV6_V6ONLY, 1);
-#endif
if(af == AF_INET) {
dcassert(sock4 == INVALID_SOCKET);
sock4 = s;
- } else {
+ } else if(af == AF_INET6) {
+#ifdef IPV6_V6ONLY
+ setSocketOpt2(s, IPPROTO_IPV6, IPV6_V6ONLY, 1);
+#endif
+
dcassert(sock6 == INVALID_SOCKET);
sock6 = s;
+ } else {
+ throw SocketException(str(F_("Unknown protocol %d") % af));
}
return s;
@@ -577,9 +580,6 @@
throw SocketException(EADDRNOTAVAIL);
}
- if(!sock4.valid() || !sock6.valid()) {
-
- }
auto buf = (const uint8_t*)aBuffer;
int sent;
@@ -761,14 +761,13 @@
addrinfo *result = 0;
+ std::string ret;
if(getaddrinfo(aDns.c_str(), NULL, &hints, &result) == 0) {
- if (result->ai_addr != NULL)
- return string(inet_ntoa(((sockaddr_in*)(result->ai_addr))->sin_addr));
-
- freeaddrinfo(result);
+ ret = resolveName(result->ai_addr, result->ai_addrlen);
+ ::freeaddrinfo(result);
}
- return string();
+ return ret;
}
Socket::addrinfo_p Socket::resolveAddr(const string& name, const string& port, int family, int flags) {