Skip to content

Instantly share code, notes, and snippets.

@cho0h5
Created March 1, 2022 09:14
Show Gist options
  • Save cho0h5/b34cdaf94a5a8e9368d9d061dc2b230e to your computer and use it in GitHub Desktop.
Save cho0h5/b34cdaf94a5a8e9368d9d061dc2b230e to your computer and use it in GitHub Desktop.
INADDR_ANY, INADDR_BROADCAST, INADDR_LOOPBACK
#include <stdio.h>
#include <netinet/in.h>
void print_addr(unsigned int addr) {
printf("%d.", (char)(addr >> 24));
printf("%d.", (char)(addr >> 16));
printf("%d.", (char)(addr >> 8));
printf("%d\n", (char)addr);
}
int main() {
print_addr(INADDR_ANY); // 0.0.0.0
print_addr(INADDR_BROADCAST); // 255.255.255.255
print_addr(INADDR_LOOPBACK); // 127.0.0.1
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment