Sockaddr structure - (sys / socket.h)

I read sys / socket.h all day and finally started to understand it and now started to use it, however, I don’t know why I cannot assign a value to a sa_familymember of the structure sockaddr.

Specification sockaddrStructure:

struct sockaddr{
    sa_family_t   sa_family       address family
    char          sa_data[]       socket address (variable-length data)
};

Data Type: sa_family_t- Unsigned integral type (2-4 bytes)

values:

Name                Purpose                          Man page
       AF_UNIX, AF_LOCAL   Local communication              unix(7)
       AF_INET             IPv4 Internet protocols          ip(7)
       AF_INET6            IPv6 Internet protocols          ipv6(7)
       AF_IPX              IPX - Novell protocols
       AF_NETLINK          Kernel user interface device     netlink(7)
       AF_X25              ITU-T X.25 / ISO-8208 protocol   x25(7)
       AF_AX25             Amateur radio AX.25 protocol
       AF_ATMPVC           Access to raw ATM PVCs
       AF_APPLETALK        AppleTalk                        ddp(7)
       AF_PACKET           Low level packet interface       packet(7)
       AF_ALG              Interface to kernel crypto API

This is a bit confusing since these chardata type values are not unsigned int.

A simple test:

#include<stdio.h>
#include<sys/socket.h> 

int main(void){
    struct sockaddr_in address;
    address.sin_family = AF_INET;
    printf("Socket Address Family: %s\n", address.sin_family);
    return 0;
}

Mistake:

storage size of ‘address’ isn’t known

It should be printed Socket Address Family: AF_INET... what am I missing here?

0
source share
1 answer

, . sockaddr_in <netinet/in.h>. . sockaddr_in

+2

Source: https://habr.com/ru/post/1607535/


All Articles