How to initialize struct sockaddr_in using initializer lists
This way of initializing a struct sockaddr_in
uses modern C and avoids all the raw of days that should long be forgotten, at least for most applications. I use this approach successfully e.g. for ESP32 microcontrollers.
struct sockaddr_in server_addr = {
.sin_family = AF_INET,
.sin_port = htons(46118),
.sin_addr = {.s_addr = htonl(INADDR_ANY)}
};