diff options
author | Christian Beier <dontmind@freeshell.org> | 2010-09-29 23:42:52 +0200 |
---|---|---|
committer | Christian Beier <dontmind@freeshell.org> | 2010-09-29 23:42:52 +0200 |
commit | 0797e42a4aaf8131ae71899faea2d682ed81cb59 (patch) | |
tree | db5c79c95472f45c2dfd3eb942923ecf6245b81f /libvncclient/sockets.c | |
parent | c0373e9cd48b0fc22ac295fdab51a29e3df7a0cd (diff) | |
download | libtdevnc-0797e42a4aaf8131ae71899faea2d682ed81cb59.tar.gz libtdevnc-0797e42a4aaf8131ae71899faea2d682ed81cb59.zip |
IP QoS support in libvncclient.
This enables setting the DSCP/Traffic Class field of IP/IPv6 packets
sent by a client. For example starting a client with -qosdscp 184
marks all outgoing traffic for expedited forwarding.
Implementation for Win32 is still a TODO, though. See
http://betelco.blogspot.com/2009/03/dscp-marking-under-windows-at.html
for an overview of the Win32 QoS API mess...
Diffstat (limited to 'libvncclient/sockets.c')
-rw-r--r-- | libvncclient/sockets.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/libvncclient/sockets.c b/libvncclient/sockets.c index 28b0256..e9a4b53 100644 --- a/libvncclient/sockets.c +++ b/libvncclient/sockets.c @@ -566,6 +566,55 @@ SetNonBlocking(int sock) } + +/* + * SetDSCP sets a socket's IP QoS parameters aka Differentiated Services Code Point field + */ + +rfbBool +SetDSCP(int sock, int dscp) +{ +#ifdef WIN32 + rfbClientErr("Setting of QoS IP DSCP not implemented for Windows\n"); + return TRUE; +#else + int level, cmd; + struct sockaddr addr; + socklen_t addrlen = sizeof(addr); + + if(getsockname(sock, &addr, &addrlen) != 0) { + rfbClientErr("Setting socket QoS failed while getting socket address: %s\n",strerror(errno)); + return FALSE; + } + + switch(addr.sa_family) + { +#ifdef LIBVNCSERVER_IPv6 + case AF_INET6: + level = IPPROTO_IPV6; + cmd = IPV6_TCLASS; + break; +#endif + case AF_INET: + level = IPPROTO_IP; + cmd = IP_TOS; + break; + default: + rfbClientErr("Setting socket QoS failed: Not bound to IP address"); + return FALSE; + } + + if(setsockopt(sock, level, cmd, (void*)&dscp, sizeof(dscp)) != 0) { + rfbClientErr("Setting socket QoS failed: %s\n", strerror(errno)); + return FALSE; + } + + return TRUE; +#endif +} + + + /* * StringToIPAddr - convert a host string to an IP address. */ |