I use a IPv6 UDP socket connection in my code. The execution fails, because the device does not exist.
strerror(errno)
responded with
No such device
I use a link local address.
Server
fe80::213:afff:fe94:d75
Client
fe80::f2d5:bfff:fe10:f1b1
I got the scope_id by ifconfig:
bt0: flags=4177<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1280
inet6 fe80::f2d5:bfff:fe10:f1b1 prefixlen 64 scopeid 0x20<link>
unspec F0-D5-BF-FF-FE-10-F1-B1-00-00-00-00-00-00-00-00 txqueuelen 1000 (UNSPEC)
RX packets 3 bytes 84 (84.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11 bytes 370 (370.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Since another interface has the same scope_id, I guess the scope_id means here the IPv6 scope. 0x20 = link_local.
enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.4 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::fb58:43b9:10fa:101 prefixlen 64 scopeid 0x20<link>
inet6 2a02:8109:b6bf:ca24:ae7f:b967:932e:b2f4 prefixlen 64 scopeid 0x0<global>
inet6 2a02:8109:b6bf:ca24:51f:6c37:66c4:5282 prefixlen 64 scopeid 0x0<global>
ether c8:5b:76:98:55:bf txqueuelen 1000 (Ethernet)
RX packets 16413820 bytes 20299047086 (20.2 GB)
RX errors 18 dropped 0 overruns 0 frame 16
TX packets 6110718 bytes 714537636 (714.5 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0xf1200000-f1220000
So, I used this scope_id in my code:
#define CLIENT_ADDRESS { 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0xd5, 0xbf, 0xff, 0xfe, 0x10, 0xf1, 0xb1 };
struct sockaddr_in6 client_addr;
unsigned int client_addr_len = sizeof(client_addr);
memset(&client_addr, 0, client_addr_len);
client_addr.sin6_family = AF_INET6;
client_addr.sin6_port = htons(PORT);
client_addr.sin6_scope_id = 0x20;
uint8_t address[16] = CLIENT_ADDRESS;
memcpy(&client_addr.sin6_addr, address, 16);
This is not the correct interface.
So my question: Where can I find the correct scope_id for my interface?
Is there some linux tool to get it?