Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1#ifndef UTILITY_H
2#define UTILITY_H
3
4#include <SNF/SNF.h>
5
6/// @brief Checks if Result is < 0 then printout the ErrorOut and exits with code 0
7/// @param Result Input to be checked if < 0
8/// @param ErrorOut Error Message content
9extern void checkerr(int Result, const char *ErrorOut);
10
11/// @brief Turns a sequence of bytes into a uint32 (Following big-endian)
12/// @param bytes Bytes sequence
13/// @param nBytes Bytes sequence's length
14/// @return bytes's value in uint32_t On Sucess || 0
15extern uint32_t snf_bytes_to_uint32(const char *bytes, int nBytes);
16
17/// @brief Turns a string's length into a sequence of bytes (Following big-endian)
18/// @param Str String whose length would be formatted into Bytes sequence
19/// @param nBytes Bytes sequence's length
20/// @return Byte sequence On Success | NULL On fail { Shall fail if Str is NULL || nBytes is a negative number || Str doesn't finish with a null character || an Error occured during allocation }
21extern char *snf_strlen_to_bytes(const char *Str, int nBytes);
22
23/// @brief Turns a uint32 into a sequence of bytes (Following big-endian)
24/// @param i uint32_t that would be formatted into Bytes sequence
25/// @param nBytes Bytes sequence's length
26/// @return Byte sequence On Success | NULL On fail { Shall fail if nBytes is a negative number || Str doesn't finish with a null character || an Error occured during allocation }
27extern char *snf_uint32_to_bytes(uint32_t i, int nBytes);
28
29/// @brief Sets a socket as non blocking.
30/// @param _sock Socket to be operated on
31/// @return See fcntl(..)
32extern int snf_setnonblocking(int _sock);
33#endif
This file includes necessary Checks and includes the the nesessary libraries of the library.
void checkerr(int Result, const char *ErrorOut)
Checks if Result is < 0 then printout the ErrorOut and exits with code 0.
int snf_setnonblocking(int _sock)
Sets a socket as non blocking.
char * snf_strlen_to_bytes(const char *Str, int nBytes)
Turns a string's length into a sequence of bytes (Following big-endian)
uint32_t snf_bytes_to_uint32(const char *bytes, int nBytes)
Turns a sequence of bytes into a uint32 (Following big-endian)
char * snf_uint32_to_bytes(uint32_t i, int nBytes)
Turns a uint32 into a sequence of bytes (Following big-endian)