From 95ad45214da5982baa554e669769b33ff88cb1d6 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Fri, 19 Jul 2013 15:57:21 -0400 Subject: [PATCH] Add that missing new source file --- .gitignore | 1 + noport53.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 noport53.c diff --git a/.gitignore b/.gitignore index 2b2dd5e..1e587e4 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ krb5-1.8.3-pdf.tar.gz /krb5-1.11.3.tar.gz /krb5-1.11.3.tar.gz.asc /krb5-1.11.3-pdf.tar.xz +/nss_wrapper.tar.bz2 diff --git a/noport53.c b/noport53.c new file mode 100644 index 0000000..2b69083 --- /dev/null +++ b/noport53.c @@ -0,0 +1,86 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +int +connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) +{ + unsigned short port; + static int (*next_connect)(int, const struct sockaddr *, socklen_t); + + if (next_connect == NULL) { + next_connect = dlsym(RTLD_NEXT, "connect"); + if (next_connect == NULL) { + errno = ENOSYS; + return -1; + } + } + + if (getenv("NOPORT53") == NULL) { + return next_connect(sockfd, addr, addrlen); + } + + switch (addr->sa_family) { + case AF_INET: + port = ntohs(((struct sockaddr_in *)addr)->sin_port); + if (port == 53) { + errno = ECONNREFUSED; + return -1; + } + break; + case AF_INET6: + port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port); + if (port == 53) { + errno = ECONNREFUSED; + return -1; + } + break; + default: + break; + } + return next_connect(sockfd, addr, addrlen); +} + +ssize_t +sendto(int sockfd, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen) +{ + unsigned short port; + static int (*next_sendto)(int, const void *, size_t, int, + const struct sockaddr *, socklen_t); + + if (next_sendto == NULL) { + next_sendto = dlsym(RTLD_NEXT, "sendto"); + if (next_sendto == NULL) { + errno = ENOSYS; + return -1; + } + } + + if (getenv("NOPORT53") == NULL) { + return next_sendto(sockfd, buf, len, flags, dest_addr, addrlen); + } + + switch (dest_addr->sa_family) { + case AF_INET: + port = ntohs(((struct sockaddr_in *)dest_addr)->sin_port); + if (port == 53) { + errno = ECONNREFUSED; + return -1; + } + break; + case AF_INET6: + port = ntohs(((struct sockaddr_in6 *)dest_addr)->sin6_port); + if (port == 53) { + errno = ECONNREFUSED; + return -1; + } + break; + default: + break; + } + return next_sendto(sockfd, buf, len, flags, dest_addr, addrlen); +}