diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 21b7b7db457518560a94cca9883884f9335280e7..7aa44c01807257007cffe85f392fc09288daf884 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -244,7 +244,7 @@ int AST_OPTIONAL_API_NAME(ast_websocket_write)(struct ast_websocket *session, en
 	if (length == 126) {
 		put_unaligned_uint16(&frame[2], htons(actual_length));
 	} else if (length == 127) {
-		put_unaligned_uint64(&frame[2], htonl(actual_length));
+		put_unaligned_uint64(&frame[2], htobe64(actual_length));
 	}
 
 	ao2_lock(session);