|
#include <pantheios/pantheios.h>
#include <pantheios/internal/safestr.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <winsock2.h>
extern const char PANTHEIOS_FE_PROCESS_IDENTITY[] = "pantheios-C";
int connect_to_peer_1(struct in_addr const* addr)
{
pantheios_logprintf(PANTHEIOS_SEV_DEBUG
, "connect_to_peer(%u.%u.%u.%u)"
, (NULL == addr) ? 0 : ((addr->s_addr & 0x000000ff) >> 0)
, (NULL == addr) ? 0 : ((addr->s_addr & 0x0000ff00) >> 8)
, (NULL == addr) ? 0 : ((addr->s_addr & 0x00ff0000) >> 16)
, (NULL == addr) ? 0 : ((addr->s_addr & 0xff000000) >> 24));
return 0;
}
char const* convert_addr(char* buff, size_t cchBuff, struct in_addr const* addr)
{
assert(cchBuff >= 16);
#ifdef PANTHEIOS_USING_SAFE_STR_FUNCTIONS
sprintf_s(buff, cchBuff
#else /* ? PANTHEIOS_USING_SAFE_STR_FUNCTIONS */
sprintf(buff
#endif /* PANTHEIOS_USING_SAFE_STR_FUNCTIONS */
, "%u.%u.%u.%u"
, (NULL == addr) ? 0 : ((addr->s_addr & 0x000000ff) >> 0)
, (NULL == addr) ? 0 : ((addr->s_addr & 0x0000ff00) >> 8)
, (NULL == addr) ? 0 : ((addr->s_addr & 0x00ff0000) >> 16)
, (NULL == addr) ? 0 : ((addr->s_addr & 0xff000000) >> 24));
return buff;
}
int connect_to_peer_2(struct in_addr const* addr)
{
char buff[16];
pantheios_logprintf(PANTHEIOS_SEV_DEBUG
, "connect_to_peer(%s)"
, convert_addr(&buff[0], STLSOFT_NUM_ELEMENTS(buff), addr));
return 0;
}
int main()
{
int panres = pantheios_init();
if(panres < 0)
{
fprintf(stderr, "Failed to initialise the Pantheios libraries: %s\n", pantheios_getInitErrorString(panres));
return EXIT_FAILURE;
}
else
{
pantheios_logprintf(PANTHEIOS_SEV_DEBUG, "main()");
/* . . . rest of program */
{
int i = 10;
double d = 9.9;
pantheios_logprintf(PANTHEIOS_SEV_NOTICE, "i=%d, d=%G", i, d);
}
{
struct in_addr addr;
memset(&addr, 1, sizeof(addr));
connect_to_peer_1(&addr);
}
{
struct in_addr addr;
memset(&addr, 2, sizeof(addr));
connect_to_peer_2(&addr);
}
pantheios_uninit();
return EXIT_SUCCESS;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.