Skip to content

Instantly share code, notes, and snippets.

@mdierolf
Last active January 20, 2022 14:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mdierolf/7751f9c4535a6d402438e219617cf4c3 to your computer and use it in GitHub Desktop.
Save mdierolf/7751f9c4535a6d402438e219617cf4c3 to your computer and use it in GitHub Desktop.
An LD_PRELOAD fix for a really stupid spotify problem
// Save this file somewhere as spotify.preload.c
// Then build the library:
// gcc -fPIC -shared -o ~/spotify.preload.so spotify.preload.c -ldl
// When you execute spotify, you need to preload this library, which wraps the "setsockopt" function call with another function that gives spotify the results it expects:
// LD_PRELOAD=~/spotify.preload.so spotify
// To make the desktop icon work, edit: /usr/share/applications/spotify.desktop
// Change Exec=... to:
// Exec=LD_PRELOAD=~/spotify.preload.so spotify %U
#define _GNU_SOURCE
#include <dlfcn.h>
#include <sys/socket.h>
#include <netinet/in.h>
static int (*real_setsockopt)(int socket, int level, int option_name, const void *option_value, socklen_t option_len);
int setsockopt(int socket, int level, int option_name, const void *option_value, socklen_t option_len) {
real_setsockopt = dlsym(RTLD_NEXT,"setsockopt");
int ret = real_setsockopt(socket,level,option_name,option_value,option_len);
if (level == SOL_IP && option_name == IP_MULTICAST_IF) {
return 0;
}
return ret;
}
@akachida
Copy link

akachida commented May 3, 2018

Works on terminal but not with Desktop Shortcut.
If i run LD_PRELOAD=~/spotify.preload.so spotify %U works greate, but changing the .desktop display error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment