mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 21:42:59 +03:00
46 lines
989 B
C
46 lines
989 B
C
#define _GNU_SOURCE
|
|
|
|
#include "helpers.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
|
|
void print_sockaddr(const struct sockaddr *sa)
|
|
{
|
|
char str[64];
|
|
switch (sa->sa_family)
|
|
{
|
|
case AF_INET:
|
|
if (inet_ntop(sa->sa_family, &((struct sockaddr_in*)sa)->sin_addr, str, sizeof(str)))
|
|
printf("%s:%d", str, ntohs(((struct sockaddr_in*)sa)->sin_port));
|
|
break;
|
|
case AF_INET6:
|
|
if (inet_ntop(sa->sa_family, &((struct sockaddr_in6*)sa)->sin6_addr, str, sizeof(str)))
|
|
printf("%s:%d", str, ntohs(((struct sockaddr_in6*)sa)->sin6_port));
|
|
break;
|
|
default:
|
|
printf("UNKNOWN_FAMILY_%d", sa->sa_family);
|
|
}
|
|
}
|
|
|
|
char *strncasestr(const char *s,const char *find, size_t slen)
|
|
{
|
|
char c, sc;
|
|
size_t len;
|
|
|
|
if ((c = *find++) != '\0')
|
|
{
|
|
len = strlen(find);
|
|
do
|
|
{
|
|
do
|
|
{
|
|
if (slen-- < 1 || (sc = *s++) == '\0') return NULL;
|
|
} while (toupper(c) != toupper(sc));
|
|
if (len > slen) return NULL;
|
|
} while (strncasecmp(s, find, len) != 0);
|
|
s--;
|
|
}
|
|
return (char *)s;
|
|
}
|