Felipe Salazar Felipe Salazar - 1 year ago 75
C Question

Getting IPV4 address from a sockaddr structure

How can I extract an IP address into a string? I can't find a reference that tells me how

char sa_data[14]
is encoded.

Answer Source

Once sockaddr cast to sockaddr_in, it becomes this:

struct sockaddr_in {
    u_short     sin_family;
    u_short     sin_port;
    struct      in_addr sin_addr;
    char        sin_zero[8];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download