- Program listens on 127.0.0.1:8080 then sends a "Success" string to client(browser etc.)
- Requires a Visual Studio C++ Desktop Development toolset and link with ws2_32.dll
struct sockaddr {
unsigned short sa_family; // 2 Byte AF_INET, AF_BLUETOOTH vb.)
char sa_data[14]; // 14 Byte
};
- When (SOCKADDR*)&serverAddr passed to functions (bind,accept...) ,
- Function checks first two bytes (which is common in both structures) ,
- and decides whether it is a ipv4 address or not , then simply reads that memory for struct sockaddr_in definition.
struct sockaddr_in {
short sin_family; // 2 Byte (AF_INET)
unsigned short sin_port; // 2 Byte (Port )
struct in_addr sin_addr; // 4 Byte (IP )
char sin_zero[8]; // 8 Byte
};
OOP Analogy:
Pseudo Base Struct => struct sockaddr
Pseudo Derived Struct => struct sockaddr_in
Result: Pointing to a derived struct using a base struct pointer.
AF_INET (2) → Treats memory as struct sockaddr_in
AF_INET6 (23) → Treats memory as struct sockaddr_in6
AF_BLUETOOTH (32) → Treats memory as Bluetooth-specific structure