~donmcc/ood

ref: 1182412fd4ece0cb55c4b3ebefee78b22c8c15bd ood/src/libood/ood/sockaddr_test.c -rw-r--r-- 742 bytes
1182412fDon McCaughey Add `ood_halt()` function. 7 months ago
                                                                                
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
32
33
34
#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "ood.h"


static void
test_sockaddr_alloc_formatted(void)
{
    struct sockaddr unspecified = {
            .sa_family = AF_UNSPEC,
    };
    char *formatted = ood_sockaddr_alloc_formatted(&unspecified);
    assert(0 == strcmp("(unknown)", formatted));

    free(formatted);

    struct sockaddr_in ipv4_address = {
            .sin_family = AF_INET,
            .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
            .sin_port = htons(80),
    };
    formatted = ood_sockaddr_alloc_formatted((struct sockaddr *)&ipv4_address);
    assert(0 == strcmp("127.0.0.1:80", formatted));
    free(formatted);
}


void
sockaddr_test(void)
{
    test_sockaddr_alloc_formatted();
}