hello, I want to develop a program that interact with the browser using the socket but I can't understand the difference between the two structureandCode:struct sockaddr { }and why casting sockaddr_in to sockaddrCode:struct sockaddr_in { }
hello, I want to develop a program that interact with the browser using the socket but I can't understand the difference between the two structureandCode:struct sockaddr { }and why casting sockaddr_in to sockaddrCode:struct sockaddr_in { }
"struct sockaddr" is a generic address, while "struct sockaddr_in" is an IPv4 address.
It allows functions like accept(2) to work for any address type (that is, you don't need accept_ipv4(), accept_ipv6(), and so on). All of the struct sockaddr types will have a common beginning sequence which contains the address family, so accept(2) can simply peek at that to decide how to proceed.and why casting sockaddr_in to sockaddr
It's a nice example of class inheritance in C. In OOP terms, sockaddr is the base class, and sockaddr_in and sockaddr_in6 (and others like sockaddr_un) are derived classes.
Here's a good page that explains what these structures are in more depth: struct sockaddr and pals