Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial cleanups #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.o
Makefile.depend
*.d
udptunnel
42 changes: 22 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
prefix = /usr/local

PREFIX ?= /usr/local
DESTDIR ?=
BINDIR ?= $(PREFIX)/bin
CFLAGS ?= -g -O2

INSTALL ?= install
PKG_CONFIG ?= pkg-config

ifeq ($(shell $(PKG_CONFIG) --exists libsystemd || echo NO),)
DEFS += -DHAVE_SYSTEMD_SD_DAEMON_H $(shell $(PKG_CONFIG) --cflags libsystemd)
LDADD += $(shell $(PKG_CONFIG) --libs libsystemd)
CPPFLAGS += -DHAVE_SYSTEMD_SD_DAEMON_H $(shell $(PKG_CONFIG) --cflags libsystemd)
LDLIBS += $(shell $(PKG_CONFIG) --libs libsystemd)
endif

CPPFLAGS += $(DEFS) $(INCLUDES)
CFLAGS += -MMD -MP
CFLAGS += -Wall -Wextra

OBJECTS := log.o network.o utils.o udptunnel.o

all: depend udptunnel
ifneq ($(V),1)
BUILT_IN_LINK.o := $(LINK.o)
LINK.o = @echo " LD $@";
LINK.o += $(BUILT_IN_LINK.o)
BUILT_IN_COMPILE.c := $(COMPILE.c)
COMPILE.c = @echo " CC $@";
COMPILE.c += $(BUILT_IN_COMPILE.c)
endif

all: udptunnel

install:
$(INSTALL) -d $(BASEDIR)$(prefix)/sbin/
$(INSTALL) -m 0755 udptunnel $(BASEDIR)$(prefix)/sbin/
install: udptunnel
@$(INSTALL) -v -d "$(DESTDIR)$(BINDIR)" && install -v -m 0755 udptunnel "$(DESTDIR)$(BINDIR)/udptunnel"

clean:
rm -f Makefile.depend $(OBJECTS) udptunnel

%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
@$(RM) -vf $(OBJECTS) $(OBJECTS:%.o=%.d) udptunnel

udptunnel: $(OBJECTS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDADD) $(LIBS)

depend: Makefile.depend
Makefile.depend:
$(CC) $(CPPFLAGS) $(CFLAGS) -MM -MG *.c > $@

-include Makefile.depend
.PHONY: all install clean
-include *.d
13 changes: 7 additions & 6 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

char *print_addr_port(const struct sockaddr *addr, socklen_t addrlen)
{
static char buf[1100], address[1025], port[32];
static char buf[NI_MAXHOST + NI_MAXSERV + 4];
char address[NI_MAXHOST], port[NI_MAXSERV];
int err;

err = getnameinfo(addr, addrlen, address, sizeof(address),
Expand All @@ -48,9 +49,9 @@ char *print_addr_port(const struct sockaddr *addr, socklen_t addrlen)
log_printf_exit(1, log_err, "getnameinfo: %s", gai_strerror(err));

if (addr->sa_family == AF_INET6)
snprintf(buf, sizeof(buf) - 1, "[%s]:%s", address, port);
snprintf(buf, sizeof(buf), "[%s]:%s", address, port);
else
snprintf(buf, sizeof(buf) - 1, "%s:%s", address, port);
snprintf(buf, sizeof(buf), "%s:%s", address, port);

return buf;
}
Expand Down Expand Up @@ -207,7 +208,7 @@ int *tcp_listener(const char *s)
if (listen(fd, 128) < 0)
err_sys("listen");

if (allocated_fds < fd_num + 1 + 1) {
if (allocated_fds < (size_t)fd_num + 1 + 1) {
allocated_fds += 8;
fd_list = realloc(fd_list, allocated_fds * sizeof(int));
}
Expand All @@ -218,7 +219,7 @@ int *tcp_listener(const char *s)
}

/* and then add -1 as the list terminator */
if (allocated_fds < fd_num + 1 + 1)
if (allocated_fds < (size_t)fd_num + 1 + 1)
fd_list = realloc(fd_list, ++allocated_fds * sizeof(int));
fd_list[fd_num] = -1;

Expand Down Expand Up @@ -262,7 +263,7 @@ int accept_connections(int listening_sockets[])

for (i = 0; listening_sockets[i] != -1; i++) {
int listen_sock;
struct sockaddr_storage client_addr;
struct sockaddr_storage client_addr = { 0 };
socklen_t addrlen = sizeof(client_addr);

if (!FD_ISSET(listening_sockets[i], &readfds))
Expand Down
1 change: 1 addition & 0 deletions udptunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ static void send_handshake(struct relay *relay)

static void wait_for_child(int sig)
{
(void)sig;
while (waitpid(-1, NULL, WNOHANG) > 0);
}

Expand Down