c_cpp dns-block.c para spotify

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp dns-block.c para spotify相关的知识,希望对你有一定的参考价值。

#define _GNU_SOURCE

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <string.h>

#include <dlfcn.h>
//#include <stdlib.h>
//#include <stdarg.h>

#include <fnmatch.h>

#define WHITELIST_LENGTH   3
#define BLACKLIST_LENGTH   1

const char *hostname_whitelist[WHITELIST_LENGTH] =
    { "*.spotify.com", "*.cloudfront.net", "api.tunigo.com" };
    
const char *hostname_blacklist[BLACKLIST_LENGTH] =
    { "adeventtracker.spotify.com" };
 
int getaddrinfo(const char *hostname, const char *service,
                const struct addrinfo *hints, struct addrinfo **res)
{
    printf("getaddrinfo request: '%s' '%s' ", hostname, service);
    
    int block = 1;
    
    int i;
    for (i = 0; i < WHITELIST_LENGTH; i++) {
        if (fnmatch(hostname_whitelist[i], hostname, FNM_NOESCAPE) == 0) {
            block = 0;
            break;
        }
    }
    
    for (i = 0; i < BLACKLIST_LENGTH; i++) {
        if (fnmatch(hostname_blacklist[i], hostname, FNM_NOESCAPE) == 0) {
            block = 1;
            break;
        }
    }
    
    if (block) {
        printf("BLOCKED\n");
        return -1;
    } else {
        printf("ALLOWED\n");
    }
    
    static typeof(getaddrinfo) *old_getaddrinfo = NULL;
    
    if (!old_getaddrinfo) {
        old_getaddrinfo = dlsym(RTLD_NEXT, "getaddrinfo");
    }
    
    if (!old_getaddrinfo) {
        printf("can't find regular getaddrinfo function\n");
        return -1;
    }
    
    return old_getaddrinfo(hostname, service, hints, res);
}

以上是关于c_cpp dns-block.c para spotify的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp Taller para entrega 09/03/2017 prog1

c_cpp App para estudo de listas simplesmente encadeadas

sql BIT / IAM-2081 - sp2CES_ALU_ObtenerInfoInscripVigente - Se agrega para obtener la oferta edu

嵌入式ARM 混合编程,汇编调用C语言,在线等

xml 程序para Exportar para KML

如何使用 @para1 = @para2 等参数执行 Sql 服务器过程