NET_GetLocalAddresses(3)
π NET_GetLocalAddresses(3) π
okay bestie, welcome to the SDL_net3 function fam, where we're talking about NET_GetLocalAddresses β the girl whose whole job is handing you a lil list of the local addresses living on your system. she's niche, she's specific, and she's lowkey overhated. let's get into it π«Ά
β¨ SYNOPSIS β¨
#include <SDL3_net/SDL_net.h>
extern SDL_DECLSPEC NET_Address **SDLCALL NET_GetLocalAddresses(int *num_addresses);
that signature ate, no cap. look at her go π
πΈ DESCRIPTION πΈ
so what she does is: she returns addresses that you could theoretically bind a socket to, so you can accept connections from other machines at that address. theoretically!! key word!! π
now listen. you almost never need this function. and I mean it. two reasons, bestie, and both are real:
- first off, it's genuinely hard to tell what counts as a good address to bind to without just... asking the user. and spoiler alert: the user is gonna find it equally hard to decide. it's giving "nobody knows what's happening" π
- second, most machines have a whole pile of private addresses that are reachable on the same LAN, but basically no public ones that the outside Internet can get to. so the list is kinda mid for actual public use.
usually it's way better to just call NET_CreateServer() or NET_CreateDatagramSocket() with a NULL address β that's you saying "bind to all interfaces," and honestly? iconic behavior. do that instead π
the array of addresses she hands back is guaranteed to be NULL-terminated. and you can also pass a pointer to an int and she'll drop the final count in there β that count does not include the NULL sitting at the end of the array, she's not like that.
when you're done with the returned array, pass it to NET_FreeLocalAddresses. and yes, you can absolutely keep any of the addresses from that array even after you call that function β as long as you called NET_RefAddress() on them first. ref them or lose them, that's the rule π
π§ FUNCTION PARAMETERS π§
num_addressesβ on exit, this gets set to the number of addresses returned. it's allowed to beNULL, she won't be mad. no thoughts, head empty, totally valid π«§
π RETURN VALUE π
she returns a NULL-terminated array of NET_Address pointers, one for each bindable address on the system. so cute. so organized.
but if something goes wrong, you get NULL back π β and in that case, call SDL_GetError() for the details. she'll tell you what happened, she's not mysterious like that.
π THREAD SAFETY π
it is safe to call this function from any thread. go wild, queen. multithreaded and unbothered β¨
β AVAILABILITY β
this function has been available since SDL_net 3.0.0. she's a veteran fr fr π
heads up bestie: the returned array is yours to manage β hand it back toNET_FreeLocalAddresseswhen you're done, andNET_RefAddress()anything you wanna keep past that. don't leave her hanging π
and that's the whole page, periodt. π¦
this adorable little manual page comes to you from SDL_net, version 3.2.0. drink some water, bind responsibly, and remember: NULL means "all interfaces" and that's the main character move. bye bestie!! ππβ¨
π¦ where this page comes from
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 43: SDL3_net-devel 3.2.0-2.fc43 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- fedora 44: SDL3_net-devel 3.2.0-2.fc44 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms