summaryrefslogtreecommitdiffhomepage
path: root/examples/network/network_resolve_host.c
blob: a00ccb2d22febbdc8d84914fc426f86388fec28c (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************************
*
*   raylib [network] example - Resolve Host
*
*   This example has been created using raylib 3.0 (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*   Copyright (c) 2019-2020 Jak Barnes (@syphonx) and Ramon Santamaria (@raysan5)
*
********************************************************************************************/

#include "raylib.h"

#define RNET_IMPLEMENTATION
#include "extras/rnet.h"

int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [network] example - resolve host");

    InitNetworkDevice();    // Init network communications

    char buffer[ADDRESS_IPV6_ADDRSTRLEN];
    unsigned short port = 0;

    AddressInformation *address = LoadAddressList(1);

    // Address info flags
    //  ADDRESS_INFO_NUMERICHOST    // or try them in conjunction to
    //  ADDRESS_INFO_NUMERICSERV    // specify custom behaviour from
    //  ADDRESS_INFO_DNS_ONLY       // the function getaddrinfo()
    //  ADDRESS_INFO_ALL            //
    //  ADDRESS_INFO_FQDN           // e.g. ADDRESS_INFO_CANONNAME | ADDRESS_INFO_NUMERICSERV
    int count = ResolveHost(NULL, "5210", ADDRESS_TYPE_IPV4, 0, address);

    if (count > 0)
    {
        GetAddressHostAndPort(address[0], buffer, &port);
        TraceLog(LOG_INFO, "Resolved to ip %s::%d", buffer, port);
    }

    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();

            ClearBackground(RAYWHITE);

            // TODO: Draw relevant connection info

        EndDrawing();
        //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseNetworkDevice();   // Close network communication

    CloseWindow();          // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}