File: eutils.h

package info (click to toggle)
libevhtp 1.2.18-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,024 kB
  • sloc: ansic: 10,208; sh: 118; makefile: 19
file content (31 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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);

    return mem ? memcpy(mem, src, size) : NULL;
}

#define mm__alloc_(type, ...) \
    (type *)mm__dup_((type[]) {__VA_ARGS__ }, sizeof(type))

#define bind__sock_port0_(HTP) ({                      \
        struct sockaddr_in sin;                        \
        socklen_t len = sizeof(struct sockaddr);       \
        uint16_t port = 0;                             \
                                                       \
        evhtp_bind_socket(HTP, "127.0.0.1", 9999, 128);   \
                                                       \
        if (getsockname(                               \
                evconnlistener_get_fd(HTP->server),    \
                (struct sockaddr *)&sin, &len) == 0) { \
            port = ntohs(sin.sin_port);                \
        }                                              \
        port;                                          \
    })