Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
utility.h File Reference

Go to the source code of this file.

Functions

void checkerr (int Result, const char *ErrorOut)
 Checks if Result is < 0 then printout the ErrorOut and exits with code 0.
 
uint32_t snf_bytes_to_uint32 (const char *bytes, int nBytes)
 Turns a sequence of bytes into a uint32 (Following big-endian)
 
char * snf_strlen_to_bytes (const char *Str, int nBytes)
 Turns a string's length into a sequence of bytes (Following big-endian)
 
char * snf_uint32_to_bytes (uint32_t i, int nBytes)
 Turns a uint32 into a sequence of bytes (Following big-endian)
 
int snf_setnonblocking (int _sock)
 Sets a socket as non blocking.
 

Function Documentation

◆ checkerr()

void checkerr ( int Result,
const char * ErrorOut )
extern

Checks if Result is < 0 then printout the ErrorOut and exits with code 0.

Parameters
ResultInput to be checked if < 0
ErrorOutError Message content

◆ snf_bytes_to_uint32()

uint32_t snf_bytes_to_uint32 ( const char * bytes,
int nBytes )
extern

Turns a sequence of bytes into a uint32 (Following big-endian)

Parameters
bytesBytes sequence
nBytesBytes sequence's length
Returns
bytes's value in uint32_t On Sucess || 0

◆ snf_strlen_to_bytes()

char * snf_strlen_to_bytes ( const char * Str,
int nBytes )
extern

Turns a string's length into a sequence of bytes (Following big-endian)

Parameters
StrString whose length would be formatted into Bytes sequence
nBytesBytes sequence's length
Returns
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 }

◆ snf_uint32_to_bytes()

char * snf_uint32_to_bytes ( uint32_t i,
int nBytes )
extern

Turns a uint32 into a sequence of bytes (Following big-endian)

Parameters
iuint32_t that would be formatted into Bytes sequence
nBytesBytes sequence's length
Returns
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 }

◆ snf_setnonblocking()

int snf_setnonblocking ( int _sock)
extern

Sets a socket as non blocking.

Parameters
_sockSocket to be operated on
Returns
See fcntl(..)