NET_GetAddressBytes(3)

πŸ“¦
version 3.2.0 Β· 2 versions
, in fedora 43, fedora 44

πŸ’– NET_GetAddressBytes(3) πŸ’–

okay bestie, welcome to the SDL_net3 functions corner of the universe, this one's literally called NET_GetAddressBytes and it does exactly what it says on the tin: it gets you the protocol-level bytes of a network address from a resolved address. iykyk πŸ¦‹


✨ NAME ✨

NET_GetAddressBytes β€” get the protocol-level bytes of a network address from a resolved address πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3_net/SDL_net.h>

const void * NET_GetAddressBytes(NET_Address *address, int *num_bytes);

πŸŽ€ DESCRIPTION πŸŽ€

okay so first thing, no cap: this data is not human-readable, it's protocol-specific, and it might not even be in a specific byte order. it's giving raw gremlin bytes πŸ™ˆ

what is it even good for?? honestly, it's only useful for possibly hashing β€” like to map an address to a specific player in a game β€” or possibly for handing to a system-level networking API. and btw, that second one is not recommended; an app does this at their own risk. you've been warned, bestie 😭

🚨 do NOT store these bytes for future runs of the program. there is no promise the format won't change. periodt.

on return, *num_bytes will hold the number of bytes provided with the address. and since the data is not NULL-terminated, this is literally the only way to determine its size β€” as such, this parameter must not be NULL πŸ’€

also do not free or modify the returned data, okay?? it belongs to the NET_Address that was queried, and it's valid as long as the object lives. so either make sure the address has a reference for as long as you need this, or make a copy of the bytes. your call, bestie 🫢

this will return NULL if resolution is still in progress, or if resolution failed. you can use NET_GetAddressStatus() or NET_WaitUntilResolved() to make sure resolution has successfully completed before calling this. vibe check first, then call ✨

and fyi, a human-readable version is available in NET_GetAddressString(), and it isn't any less efficient to query than the raw bytes. so like… if you just want to read it, go there πŸ‘‘


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • address β€” the NET_Address to query. the main character of this whole operation πŸ’œ
  • num_bytes β€” on return, will be set to the number of bytes returned. she's reporting back πŸ“

🌈 RETURN VALUE 🌈

returns a pointer to bytes, or NULL on error. and if you get that NULL, call SDL_GetError() for details, she'll tell you what went wrong πŸ”


πŸ’… THREAD SAFETY πŸ’…

it is safe to call this function from any thread. go off, multithreaded queen πŸ‘‘


⭐ AVAILABILITY ⭐

this function is available since SDL_net 3.0.0. vintage but iconic πŸŽ€


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie!! this lil slice of wisdom comes to you from SDL_net, version SDL_net 3.2.0 🫢 go forth and hash responsibly, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from