Compare commits

...

2 Commits

Author SHA1 Message Date
John Crispin
2e478d18f7 hostapd: fix MAC overlap with MBSSID enabled
Reverse byte order in non-OUI part of MAC address to prevent overlap
when MBSSID is enabled. Swaps bytes 3 and 5 and masks lower nibble
of byte 5 before applying index XOR.

Signed-off-by: John Crispin <john@phrozen.org>
2025-09-18 14:02:36 +02:00
John Crispin
fe850fc7e9 ucentral-tools: fix compiler warnings and modernize code
- Fixed format-nonliteral error in dnsprobe.c by using explicit format strings
- Fixed cast-qual error by preserving const qualifier in type casting
- Removed unused format variable and unused parameter warnings
- Updated parse_reply function signature to remove unused parameter
- Made string literals const for better type safety
- Fixed variable type warnings (unsigned long vs int)

These changes ensure the code compiles without warnings under strict
compiler flags including -Werror, -Wformat-nonliteral, -Wcast-qual,
-Wunused-parameter, and -Wunused-variable.

Signed-off-by: John Crispin <john@phrozen.org>
2025-09-12 07:17:13 +02:00
9 changed files with 1293 additions and 1185 deletions

View File

@@ -259,8 +259,13 @@ const phy_proto = {
addr[0] ^= idx << 2;
break;
case "b5":
if (mbssid)
if (mbssid) {
let b5 = addr[5];
addr[5] = addr[3];
addr[3] = b5;
addr[5] &= ~0xf;
addr[0] |= 2;
}
addr[5] ^= idx;
break;
default:

View File

@@ -18,7 +18,7 @@ endef
define Package/ucentral-tools/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/{dhcpdiscover,dnsprobe,radiusprobe,ip-collide} $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/{dhcpdiscover,dnsprobe,radiusprobe} $(1)/usr/sbin/
$(CP) ./files/* $(1)
endef

View File

@@ -0,0 +1,60 @@
---
# clang-format configuration for ucentral-tools
BasedOnStyle: LLVM
# Indentation
IndentWidth: 8
TabWidth: 8
UseTab: ForIndentation
IndentCaseLabels: true
IndentPPDirectives: BeforeHash
# Line length
ColumnLimit: 100
# Braces
BreakBeforeBraces: Linux
Cpp11BracedListStyle: false
# Spacing
SpaceAfterCStyleCast: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
# Alignment
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: true
AlignTrailingComments: true
# Breaking
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakStringLiterals: true
# Pointers and references
PointerAlignment: Right
DerivePointerAlignment: false
# Comments
ReflowComments: true
# Sorting
SortIncludes: true
IncludeBlocks: Preserve
# Function calls
BinPackArguments: true
BinPackParameters: true
# Other
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2

View File

@@ -1,36 +1,108 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.10)
PROJECT(openwifi-tools C)
INCLUDE(GNUInstallDirs)
ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 -Wmissing-declarations)
project(openwifi-tools C)
include(GNUInstallDirs)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
# Set C standard
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
ADD_EXECUTABLE(firstcontact firstcontact.c)
TARGET_LINK_LIBRARIES(firstcontact curl crypto ssl ubox)
INSTALL(TARGETS firstcontact
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
# Comprehensive warning flags (cross-compilation friendly)
set(WARNING_FLAGS
-Wall
-Wextra
-Werror
-Wformat=2
-Wformat-security
-Wnull-dereference
-Warray-bounds=2
-Wimplicit-fallthrough=3
-Wshift-overflow=2
-Wcast-qual
-Wstringop-overflow=4
-Wlogical-op
-Wduplicated-cond
-Wduplicated-branches
-Wformat-overflow=2
-Wformat-truncation=2
-Wmissing-declarations
-Wredundant-decls
-Wshadow
-Wstrict-overflow=4
-Wundef
-Wstrict-prototypes
-Wswitch-default
-Wbad-function-cast
-Wwrite-strings
-Wjump-misses-init
-Wold-style-definition
-Wmissing-prototypes
)
ADD_EXECUTABLE(dhcpdiscover dhcpdiscover.c)
INSTALL(TARGETS dhcpdiscover
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
# Security hardening flags (cross-compilation friendly)
set(SECURITY_FLAGS
-fstack-protector-strong
)
ADD_EXECUTABLE(dnsprobe dnsprobe.c)
TARGET_LINK_LIBRARIES(dnsprobe ubox resolv)
INSTALL(TARGETS dnsprobe
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
# Linker security flags (cross-compilation friendly)
set(SECURITY_LINKER_FLAGS
-Wl,-z,relro
-Wl,-z,now
)
ADD_EXECUTABLE(radiusprobe radiusprobe.c)
TARGET_LINK_LIBRARIES(radiusprobe radcli)
INSTALL(TARGETS radiusprobe
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
# Debug flags
set(DEBUG_FLAGS
-g3
-ggdb
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
)
ADD_EXECUTABLE(ip-collide ip-collide.c)
TARGET_LINK_LIBRARIES(ip-collide ubox)
INSTALL(TARGETS ip-collide
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
# Release optimization flags
set(RELEASE_FLAGS
-O2
-flto
-ffunction-sections
-fdata-sections
)
set(RELEASE_LINKER_FLAGS
-Wl,--gc-sections
-flto
)
# Apply flags based on build type
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(${WARNING_FLAGS} ${SECURITY_FLAGS} ${DEBUG_FLAGS})
add_link_options(${SECURITY_LINKER_FLAGS})
else()
add_compile_options(${WARNING_FLAGS} ${SECURITY_FLAGS} ${RELEASE_FLAGS})
add_link_options(${SECURITY_LINKER_FLAGS} ${RELEASE_LINKER_FLAGS})
endif()
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
# Define all targets
set(TARGETS firstcontact dhcpdiscover dnsprobe radiusprobe)
# firstcontact executable
add_executable(firstcontact firstcontact.c)
target_link_libraries(firstcontact PRIVATE curl crypto ssl ubox)
# dhcpdiscover executable
add_executable(dhcpdiscover dhcpdiscover.c)
# dnsprobe executable
add_executable(dnsprobe dnsprobe.c)
target_link_libraries(dnsprobe PRIVATE ubox resolv)
# radiusprobe executable
add_executable(radiusprobe radiusprobe.c)
target_link_libraries(radiusprobe PRIVATE radcli)
# Install all targets
install(TARGETS ${TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}
COMPONENT Runtime
)

File diff suppressed because it is too large Load Diff

View File

@@ -16,54 +16,54 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//config:config NSLOOKUP_OPENWRT
//config: bool "nslookup_openwrt"
//config: depends on !NSLOOKUP
//config: default y
//config: help
//config: nslookup is a tool to query Internet name servers (LEDE flavor).
//config:
//config:config FEATURE_NSLOOKUP_OPENWRT_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on NSLOOKUP_OPENWRT && LONG_OPTS
//config: help
//config: Support long options for the nslookup applet.
// config:config NSLOOKUP_OPENWRT
// config: bool "nslookup_openwrt"
// config: depends on !NSLOOKUP
// config: default y
// config: help
// config: nslookup is a tool to query Internet name servers (LEDE flavor).
// config:
// config:config FEATURE_NSLOOKUP_OPENWRT_LONG_OPTIONS
// config: bool "Enable long options"
// config: default y
// config: depends on NSLOOKUP_OPENWRT && LONG_OPTS
// config: help
// config: Support long options for the nslookup applet.
//applet:IF_NSLOOKUP_OPENWRT(APPLET(nslookup, BB_DIR_USR_BIN, BB_SUID_DROP))
// applet:IF_NSLOOKUP_OPENWRT(APPLET(nslookup, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NSLOOKUP_OPENWRT) += nslookup_lede.o
// kbuild:lib-$(CONFIG_NSLOOKUP_OPENWRT) += nslookup_lede.o
//usage:#define nslookup_lede_trivial_usage
//usage: "[HOST] [SERVER]"
//usage:#define nslookup_lede_full_usage "\n\n"
//usage: "Query the nameserver for the IP address of the given HOST\n"
//usage: "optionally using a specified DNS server"
//usage:
//usage:#define nslookup_lede_example_usage
//usage: "$ nslookup localhost\n"
//usage: "Server: default\n"
//usage: "Address: default\n"
//usage: "\n"
//usage: "Name: debian\n"
//usage: "Address: 127.0.0.1\n"
// usage:#define nslookup_lede_trivial_usage
// usage: "[HOST] [SERVER]"
// usage:#define nslookup_lede_full_usage "\n\n"
// usage: "Query the nameserver for the IP address of the given HOST\n"
// usage: "optionally using a specified DNS server"
// usage:
// usage:#define nslookup_lede_example_usage
// usage: "$ nslookup localhost\n"
// usage: "Server: default\n"
// usage: "Address: default\n"
// usage: "\n"
// usage: "Name: debian\n"
// usage: "Address: 127.0.0.1\n"
#include <stdio.h>
#include <resolv.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <poll.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include <net/if.h>
#include <netdb.h>
#include <poll.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#include <libubox/ulog.h>
#define ENABLE_FEATURE_IPV6 1
#define ENABLE_FEATURE_IPV6 1
typedef struct len_and_sockaddr {
socklen_t len;
@@ -91,171 +91,169 @@ struct query {
int rcode, n_ns;
};
static const char *rcodes[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
static const char *rcodes[] = { "NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN",
"NOTIMP", "REFUSED", "YXDOMAIN", "YXRRSET",
"NXRRSET", "NOTAUTH", "NOTZONE", "RESERVED11",
"RESERVED12", "RESERVED13", "RESERVED14", "RESERVED15",
"BADVERS" };
static unsigned int default_port = 53;
static unsigned int default_retry = 1;
static unsigned int default_timeout = 2;
static int parse_reply(const unsigned char *msg, size_t len, int *bb_style_counter)
static int parse_reply(const unsigned char *msg, size_t len)
{
ns_msg handle;
ns_rr rr;
int i, n, rdlen;
const char *format = NULL;
char astr[INET6_ADDRSTRLEN], dname[MAXDNAME];
const unsigned char *cp;
if (ns_initparse(msg, len, &handle) != 0) {
//fprintf(stderr, "Unable to parse reply: %s\n", strerror(errno));
// fprintf(stderr, "Unable to parse reply: %s\n", strerror(errno));
return -1;
}
for (i = 0; i < ns_msg_count(handle, ns_s_an); i++) {
if (ns_parserr(&handle, ns_s_an, i, &rr) != 0) {
//fprintf(stderr, "Unable to parse resource record: %s\n", strerror(errno));
// fprintf(stderr, "Unable to parse resource record: %s\n",
// strerror(errno));
return -1;
}
rdlen = ns_rr_rdlen(rr);
switch (ns_rr_type(rr))
{
case ns_t_a:
if (rdlen != 4) {
//fprintf(stderr, "Unexpected A record length\n");
return -1;
}
inet_ntop(AF_INET, ns_rr_rdata(rr), astr, sizeof(astr));
printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
break;
switch (ns_rr_type(rr)) {
case ns_t_a:
if (rdlen != 4) {
// fprintf(stderr, "Unexpected A record length\n");
return -1;
}
inet_ntop(AF_INET, ns_rr_rdata(rr), astr, sizeof(astr));
printf("Name:\t%s\nAddress: %s\n", ns_rr_name(rr), astr);
break;
#if ENABLE_FEATURE_IPV6
case ns_t_aaaa:
if (rdlen != 16) {
//fprintf(stderr, "Unexpected AAAA record length\n");
return -1;
}
inet_ntop(AF_INET6, ns_rr_rdata(rr), astr, sizeof(astr));
printf("%s\thas AAAA address %s\n", ns_rr_name(rr), astr);
break;
case ns_t_aaaa:
if (rdlen != 16) {
// fprintf(stderr, "Unexpected AAAA record length\n");
return -1;
}
inet_ntop(AF_INET6, ns_rr_rdata(rr), astr, sizeof(astr));
printf("%s\thas AAAA address %s\n", ns_rr_name(rr), astr);
break;
#endif
case ns_t_ns:
if (!format)
format = "%s\tnameserver = %s\n";
/* fall through */
case ns_t_ns:
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr), dname, sizeof(dname)) < 0) {
// fprintf(stderr, "Unable to uncompress domain: %s\n",
// strerror(errno));
return -1;
}
printf("%s\tnameserver = %s\n", ns_rr_name(rr), dname);
break;
case ns_t_cname:
if (!format)
format = "%s\tcanonical name = %s\n";
/* fall through */
case ns_t_cname:
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr), dname, sizeof(dname)) < 0) {
// fprintf(stderr, "Unable to uncompress domain: %s\n",
// strerror(errno));
return -1;
}
printf("%s\tcanonical name = %s\n", ns_rr_name(rr), dname);
break;
case ns_t_ptr:
if (!format)
format = "%s\tname = %s\n";
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr), dname, sizeof(dname)) < 0) {
//fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
return -1;
}
printf(format, ns_rr_name(rr), dname);
break;
case ns_t_ptr:
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr), dname, sizeof(dname)) < 0) {
// fprintf(stderr, "Unable to uncompress domain: %s\n",
// strerror(errno));
return -1;
}
printf("%s\tname = %s\n", ns_rr_name(rr), dname);
break;
case ns_t_mx:
if (rdlen < 2) {
fprintf(stderr, "MX record too short\n");
return -1;
}
n = ns_get16(ns_rr_rdata(rr));
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr) + 2, dname, sizeof(dname)) < 0) {
//fprintf(stderr, "Cannot uncompress MX domain: %s\n", strerror(errno));
return -1;
}
printf("%s\tmail exchanger = %d %s\n", ns_rr_name(rr), n, dname);
break;
case ns_t_mx:
if (rdlen < 2) {
fprintf(stderr, "MX record too short\n");
return -1;
}
n = ns_get16(ns_rr_rdata(rr));
if (ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
ns_rr_rdata(rr) + 2, dname,
sizeof(dname)) < 0) {
// fprintf(stderr, "Cannot uncompress MX domain: %s\n",
// strerror(errno));
return -1;
}
printf("%s\tmail exchanger = %d %s\n", ns_rr_name(rr), n, dname);
break;
case ns_t_txt:
if (rdlen < 1) {
//fprintf(stderr, "TXT record too short\n");
return -1;
}
n = *(unsigned char *)ns_rr_rdata(rr);
if (n > 0) {
memset(dname, 0, sizeof(dname));
memcpy(dname, ns_rr_rdata(rr) + 1, n);
printf("%s\ttext = \"%s\"\n", ns_rr_name(rr), dname);
}
break;
case ns_t_txt:
if (rdlen < 1) {
// fprintf(stderr, "TXT record too short\n");
return -1;
}
n = *((const unsigned char *) ns_rr_rdata(rr));
if (n > 0) {
memset(dname, 0, sizeof(dname));
memcpy(dname, ns_rr_rdata(rr) + 1, n);
printf("%s\ttext = \"%s\"\n", ns_rr_name(rr), dname);
}
break;
case ns_t_soa:
if (rdlen < 20) {
//fprintf(stderr, "SOA record too short\n");
return -1;
}
case ns_t_soa:
if (rdlen < 20) {
// fprintf(stderr, "SOA record too short\n");
return -1;
}
printf("%s\n", ns_rr_name(rr));
printf("%s\n", ns_rr_name(rr));
cp = ns_rr_rdata(rr);
n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
cp, dname, sizeof(dname));
cp = ns_rr_rdata(rr);
n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), cp,
dname, sizeof(dname));
if (n < 0) {
//fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
return -1;
}
if (n < 0) {
// fprintf(stderr, "Unable to uncompress domain: %s\n",
// strerror(errno));
return -1;
}
printf("\torigin = %s\n", dname);
cp += n;
printf("\torigin = %s\n", dname);
cp += n;
n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle),
cp, dname, sizeof(dname));
n = ns_name_uncompress(ns_msg_base(handle), ns_msg_end(handle), cp,
dname, sizeof(dname));
if (n < 0) {
//fprintf(stderr, "Unable to uncompress domain: %s\n", strerror(errno));
return -1;
}
if (n < 0) {
// fprintf(stderr, "Unable to uncompress domain: %s\n",
// strerror(errno));
return -1;
}
printf("\tmail addr = %s\n", dname);
cp += n;
printf("\tmail addr = %s\n", dname);
cp += n;
printf("\tserial = %lu\n", ns_get32(cp));
cp += 4;
printf("\tserial = %lu\n", ns_get32(cp));
cp += 4;
printf("\trefresh = %lu\n", ns_get32(cp));
cp += 4;
printf("\trefresh = %lu\n", ns_get32(cp));
cp += 4;
printf("\tretry = %lu\n", ns_get32(cp));
cp += 4;
printf("\tretry = %lu\n", ns_get32(cp));
cp += 4;
printf("\texpire = %lu\n", ns_get32(cp));
cp += 4;
printf("\texpire = %lu\n", ns_get32(cp));
cp += 4;
printf("\tminimum = %lu\n", ns_get32(cp));
break;
printf("\tminimum = %lu\n", ns_get32(cp));
break;
default:
break;
default:
break;
}
}
@@ -326,7 +324,7 @@ static unsigned long mtime(void)
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
return (unsigned long)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
return (unsigned long) ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}
#if ENABLE_FEATURE_IPV6
@@ -335,11 +333,9 @@ static void to_v4_mapped(len_and_sockaddr *a)
if (a->u.sa.sa_family != AF_INET)
return;
memcpy(a->u.sin6.sin6_addr.s6_addr + 12,
&a->u.sin.sin_addr, 4);
memcpy(a->u.sin6.sin6_addr.s6_addr + 12, &a->u.sin.sin_addr, 4);
memcpy(a->u.sin6.sin6_addr.s6_addr,
"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
memcpy(a->u.sin6.sin6_addr.s6_addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
a->u.sin6.sin6_family = AF_INET6;
a->u.sin6.sin6_flowinfo = 0;
@@ -356,8 +352,10 @@ static void to_v4_mapped(len_and_sockaddr *a)
static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_queries)
{
int fd;
int timeout = default_timeout * 1000, retry_interval, servfail_retry = 0;
len_and_sockaddr from = { };
unsigned long timeout = default_timeout * 1000;
unsigned long retry_interval;
int servfail_retry = 0;
len_and_sockaddr from = {};
#if ENABLE_FEATURE_IPV6
int one = 1;
#endif
@@ -381,12 +379,12 @@ static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_qu
#endif
/* Get local address and open/bind a socket */
fd = socket(from.u.sa.sa_family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
fd = socket(from.u.sa.sa_family, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
#if ENABLE_FEATURE_IPV6
/* Handle case where system lacks IPv6 support */
if (fd < 0 && from.u.sa.sa_family == AF_INET6 && errno == EAFNOSUPPORT) {
fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
fd = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
from.u.sa.sa_family = AF_INET;
}
#endif
@@ -432,13 +430,13 @@ static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_qu
}
/* Wait for a response, or until time to retry */
if (poll(&pfd, 1, t1+retry_interval-t2) <= 0)
if (poll(&pfd, 1, t1 + retry_interval - t2) <= 0)
continue;
while (1) {
recvlen = recvfrom(fd, queries[next_query].reply,
sizeof(queries[next_query].reply), 0,
&from.u.sa, &from.len);
recvlen =
recvfrom(fd, queries[next_query].reply,
sizeof(queries[next_query].reply), 0, &from.u.sa, &from.len);
/* read error */
if (recvlen < 0)
@@ -474,20 +472,21 @@ static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_qu
* retry immediately on server failure, and ignore
* all other codes such as refusal. */
switch (queries[qn].rcode) {
case 0:
case 3:
break;
case 0:
case 3:
break;
case 2:
if (servfail_retry && servfail_retry--) {
ns[nn].failures++;
sendto(fd, queries[qn].query, queries[qn].qlen,
MSG_NOSIGNAL, &ns[nn].addr.u.sa, ns[nn].addr.len);
}
/* fall through */
case 2:
if (servfail_retry && servfail_retry--) {
ns[nn].failures++;
sendto(fd, queries[qn].query, queries[qn].qlen,
MSG_NOSIGNAL, &ns[nn].addr.u.sa,
ns[nn].addr.len);
}
/* fall through */
default:
continue;
default:
continue;
}
/* Store answer */
@@ -502,8 +501,7 @@ static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_qu
next_query++;
}
}
else {
} else {
memcpy(queries[qn].reply, queries[next_query].reply, recvlen);
}
@@ -518,12 +516,10 @@ static int send_queries(struct ns *ns, int n_ns, struct query *queries, int n_qu
static struct ns *add_ns(struct ns **ns, int *n_ns, const char *addr)
{
char portstr[sizeof("65535")], *p;
len_and_sockaddr a = { };
len_and_sockaddr a = {};
struct ns *tmp;
struct addrinfo *ai, *aip, hints = {
.ai_flags = AI_NUMERICSERV,
.ai_socktype = SOCK_DGRAM
};
struct addrinfo *ai, *aip,
hints = { .ai_flags = AI_NUMERICSERV, .ai_socktype = SOCK_DGRAM };
if (parse_nsaddr(addr, &a)) {
/* Maybe we got a domain name, attempt to resolve it using the standard
@@ -531,7 +527,7 @@ static struct ns *add_ns(struct ns **ns, int *n_ns, const char *addr)
p = strchr(addr, '#');
snprintf(portstr, sizeof(portstr), "%hu",
(unsigned short)(p ? strtoul(p, NULL, 10) : default_port));
(unsigned short) (p ? strtoul(p, NULL, 10) : default_port));
if (!getaddrinfo(addr, portstr, &hints, &ai)) {
for (aip = ai; aip; aip = aip->ai_next) {
@@ -539,7 +535,7 @@ static struct ns *add_ns(struct ns **ns, int *n_ns, const char *addr)
aip->ai_addr->sa_family != AF_INET6)
continue;
#if ! ENABLE_FEATURE_IPV6
#if !ENABLE_FEATURE_IPV6
if (aip->ai_addr->sa_family != AF_INET)
continue;
#endif
@@ -584,8 +580,7 @@ static struct ns *add_ns(struct ns **ns, int *n_ns, const char *addr)
return &(*ns)[(*n_ns)++];
}
static struct query *add_query(struct query **queries, int *n_queries,
int type, const char *dname)
static struct query *add_query(struct query **queries, int *n_queries, int type, const char *dname)
{
struct query *tmp;
ssize_t qlen;
@@ -597,8 +592,8 @@ static struct query *add_query(struct query **queries, int *n_queries,
memset(&tmp[*n_queries], 0, sizeof(*tmp));
qlen = res_mkquery(QUERY, dname, C_IN, type, NULL, 0, NULL,
tmp[*n_queries].query, sizeof(tmp[*n_queries].query));
qlen = res_mkquery(QUERY, dname, C_IN, type, NULL, 0, NULL, tmp[*n_queries].query,
sizeof(tmp[*n_queries].query));
tmp[*n_queries].qlen = qlen;
tmp[*n_queries].name = dname;
@@ -615,8 +610,8 @@ int main(int argc, char **argv)
int n_ns = 0, n_queries = 0;
int c = 0;
char *url = "telecominfraproject.com";
char *server = "127.0.0.1";
const char *url = "telecominfraproject.com";
const char *server = "127.0.0.1";
int v6 = 0;
while (1) {
@@ -626,29 +621,28 @@ int main(int argc, char **argv)
break;
switch (option) {
case '6':
v6 = 1;
break;
case 'u':
url = optarg;
break;
case 's':
server = optarg;
break;
default:
case 'h':
printf("Usage: dnsprobe OPTIONS\n"
" -6 - use ipv6\n"
" -u <url>\n"
" -s <server>\n");
return -1;
case '6':
v6 = 1;
break;
case 'u':
url = optarg;
break;
case 's':
server = optarg;
break;
default:
case 'h':
printf("Usage: dnsprobe OPTIONS\n"
" -6 - use ipv6\n"
" -u <url>\n"
" -s <server>\n");
return -1;
}
}
ulog_open(ULOG_SYSLOG | ULOG_STDIO, LOG_DAEMON, "dnsprobe");
ULOG_INFO("attempting to probe dns - %s %s %s\n",
url, server, v6 ? "ipv6" : "");
ULOG_INFO("attempting to probe dns - %s %s %s\n", url, server, v6 ? "ipv6" : "");
add_query(&queries, &n_queries, v6 ? T_AAAA : T_A, url);
@@ -663,13 +657,12 @@ int main(int argc, char **argv)
}
if (queries[0].rcode != 0) {
printf("** server can't find %s: %s\n", queries[0].name,
rcodes[queries[0].rcode]);
printf("** server can't find %s: %s\n", queries[0].name, rcodes[queries[0].rcode]);
goto out;
}
if (queries[0].rlen) {
c = parse_reply(queries[0].reply, queries[0].rlen, NULL);
c = parse_reply(queries[0].reply, queries[0].rlen);
}
if (c == 0)

View File

@@ -1,15 +1,15 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <getopt.h>
#include <stdio.h>
#include <curl/curl.h>
#include <libubox/ulog.h>
static const char *file_cert = "/etc/open-wifi/client.pem";
static const char *file_key = "/etc/open-wifi/client_dec.key";
static const char *file_key = "/etc/open-wifi/client_dec.key";
static const char *file_json = "/etc/open-wifi/redirector.json";
static const char *file_dbg = "/tmp/firstcontact.hdr";
static const char *file_dbg = "/tmp/firstcontact.hdr";
int main(int argc, char **argv)
{
@@ -27,26 +27,26 @@ int main(int argc, char **argv)
break;
switch (option) {
case 'k':
file_key = optarg;
break;
case 'c':
file_cert = optarg;
break;
case 'o':
file_json = optarg;
break;
case 'i':
devid = optarg;
break;
default:
case 'h':
printf("Usage: firstcontact OPTIONS\n"
" -k <keyfile>\n"
" -c <certfile>\n"
" -o <outfile>\n"
" -i <devid>\n");
return -1;
case 'k':
file_key = optarg;
break;
case 'c':
file_cert = optarg;
break;
case 'o':
file_json = optarg;
break;
case 'i':
devid = optarg;
break;
default:
case 'h':
printf("Usage: firstcontact OPTIONS\n"
" -k <keyfile>\n"
" -c <certfile>\n"
" -o <outfile>\n"
" -i <devid>\n");
return -1;
}
}
@@ -72,7 +72,8 @@ int main(int argc, char **argv)
return -1;
}
if (asprintf(&url, "https://clientauth.demo.one.digicert.com/iot/api/v2/device/%s", devid) < 0) {
if (asprintf(&url, "https://clientauth.demo.one.digicert.com/iot/api/v2/device/%s", devid) <
0) {
ULOG_ERR("failed to assemble url\n");
return -1;
}

View File

@@ -1,86 +0,0 @@
#include <arpa/inet.h>
#include <net/if.h>
#include <libubox/list.h>
#include <libubox/ulog.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct route {
struct list_head list;
char devname[64];
uint32_t domain;
uint32_t mask;
};
static struct list_head routes = LIST_HEAD_INIT(routes);
static int parse_routes(void)
{
FILE *fp = fopen("/proc/net/route", "r");
int flgs, ref, use, metric, mtu, win, ir;
struct route *route;
unsigned long g;
int r;
r = fscanf(fp, "%*[^\n]\n");
if (r < 0) {
fprintf(stderr, "failed to parse routes\n");
return -1;
}
while (1) {
route = malloc(sizeof(*route));
if (!route)
break;
memset(route, 0, sizeof(*route));
r = fscanf(fp, "%63s%x%lx%X%d%d%d%x%d%d%d\n",
route->devname, &route->domain, &g, &flgs, &ref, &use, &metric, &route->mask,
&mtu, &win, &ir);
if (r != 11 && (r < 0) && feof(fp))
break;
list_add(&route->list, &routes);
printf("1 %s %x %x\n", route->devname, ntohl(route->domain), ntohl(route->mask));
}
fclose(fp);
return 0;
}
static int find_collisions(void)
{
struct route *route;
list_for_each_entry(route, &routes, list) {
struct route *compare;
if (!route->domain || !route->mask)
continue;
list_for_each_entry(compare, &routes, list) {
if (!compare->domain || !compare->mask)
continue;
if (compare == route)
continue;
if (((route->domain & route->mask) == (compare->domain & route->mask)) ||
((route->domain & compare->mask) == (compare->domain & compare->mask))) {
ULOG_ERR("collision detected\n");
return 1;
}
}
}
ULOG_INFO("no collision detected\n");
return 0;
}
int main(int argc, char **argv)
{
ulog_open(ULOG_SYSLOG | ULOG_STDIO, LOG_DAEMON, "ip-collide");
parse_routes();
if (!list_empty(&routes))
return find_collisions();
return 0;
}

View File

@@ -1,10 +1,11 @@
#include <radcli/radcli.h>
#include <stdio.h>
#include <string.h>
#include <radcli/radcli.h>
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
(void) argc;
(void) argv;
int result;
char username[128];
char passwd[AUTH_PASS_LEN + 1];