Check the return of getsockname
#pragma once
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
static void * mm__dup_(const void * src, size_t size) {
void * mem = malloc(size);
@@ -12,14 +16,14 @@ static void * mm__dup_(const void * src, size_t size) {
#define bind__sock_port0_(HTP) ({ \
struct sockaddr_in sin; \
socklen_t len = len = sizeof(struct sockaddr); \
- uint16_t port; \
+ uint16_t port = 0; \
\
evhtp_bind_socket(HTP, "127.0.0.1", 0, 128); \
\
- getsockname( \
+ if (getsockname( \
evconnlistener_get_fd(HTP->server), \
- (struct sockaddr *)&sin, &len); \
- \
+ (struct sockaddr *)&sin, &len) == 0) { \
port = ntohs(sin.sin_port); \
+ } \
port; \
})
