Skip to content

Instantly share code, notes, and snippets.

@alivelee
Created December 31, 2012 13:41
Show Gist options
  • Save alivelee/4419815 to your computer and use it in GitHub Desktop.
Save alivelee/4419815 to your computer and use it in GitHub Desktop.
Index: openvpn-2.2.1/socket.c
===================================================================
--- openvpn-2.2.1.orig/socket.c 2012-11-23 16:32:15.000000000 +0800
+++ openvpn-2.2.1/socket.c 2012-11-23 16:32:44.000000000 +0800
@@ -48,6 +48,16 @@
#endif
};
+int
+buffer_mask (struct buffer *buf, int mask) {
+ int i;
+ uint8_t *b;
+ for (i = 0, b = BPTR (buf); i < BLEN (buf); i++, b++) {
+ *b = *b ^ mask;
+ }
+ return BLEN (buf);
+}
+
/*
* Convert sockflags/getaddr_flags into getaddr_flags
*/
Index: openvpn-2.2.1/socket.h
===================================================================
--- openvpn-2.2.1.orig/socket.h 2012-11-23 16:32:19.000000000 +0800
+++ openvpn-2.2.1/socket.h 2012-11-23 16:35:15.000000000 +0800
@@ -251,6 +251,11 @@
#endif
};
+#define BUFFER_MASK 88
+/* bitwise XOR with mask */
+int
+buffer_mask (struct buffer *buf, int mask);
+
/*
* Some Posix/Win32 differences.
*/
@@ -925,28 +930,28 @@
int maxsize,
struct link_socket_actual *from)
{
+ int res;
if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */
{
- int res;
-
#ifdef WIN32
res = link_socket_read_udp_win32 (sock, buf, from);
#else
res = link_socket_read_udp_posix (sock, buf, maxsize, from);
#endif
- return res;
}
else if (proto_is_tcp(sock->info.proto)) /* unified TCPv4 and TCPv6 */
{
/* from address was returned by accept */
addr_copy_sa(&from->dest, &sock->info.lsa->actual.dest);
- return link_socket_read_tcp (sock, buf);
+ res = link_socket_read_tcp (sock, buf);
}
else
{
ASSERT (0);
return -1; /* NOTREACHED */
}
+ buffer_mask(buf, BUFFER_MASK);
+ return res;
}
/*
@@ -1032,6 +1037,7 @@
struct buffer *buf,
struct link_socket_actual *to)
{
+ buffer_mask(buf, BUFFER_MASK);
if (proto_is_udp(sock->info.proto)) /* unified UDPv4 and UDPv6 */
{
return link_socket_write_udp (sock, buf, to);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment