Shadow Network Framework  0.0.2-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
6extern void (*SNF_ERR_OUT)(const char*);
7
8/// @brief Checks if Result is < 0 then printout the ErrorOut and exits with code 0
9/// @param Result Input to be checked if < 0
10/// @param ErrorOut Error Message content
11extern void checkerr(int Result, const char *ErrorOut);
12
13/// @brief Turns a sequence of bytes into a uint32 (Following big-endian)
14/// @param bytes Bytes sequence
15/// @param nBytes Bytes sequence's length
16/// @return bytes's value in uint32_t On Sucess || 0
17extern uint32_t snf_bytes_to_uint32(const char *bytes, int nBytes);
18
19/// @brief Turns a string's length into a sequence of bytes (Following big-endian)
20/// @param Str String whose length would be formatted into Bytes sequence
21/// @param nBytes Bytes sequence's length
22/// @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 }
23extern char *snf_strlen_to_bytes(const char *Str, int nBytes);
24
25/// @brief Turns a uint32 into a sequence of bytes (Following big-endian)
26/// @param i uint32_t that would be formatted into Bytes sequence
27/// @param nBytes Bytes sequence's length
28/// @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 }
29extern char *snf_uint32_to_bytes(uint32_t i, int nBytes);
30
31/// @brief Sets a socket as non blocking.
32/// @param _sock Socket to be operated on
33/// @return See fcntl(..)
34extern int snf_setnonblocking(int _sock);
35
36
37extern void snf_print_err(const char* StrErr);
38
39#endif
Main Header FileThis File Calls for all the header files exisitng in this 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)
void(* SNF_ERR_OUT)(const char *)
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)
void snf_print_err(const char *StrErr)