I am working on python socket program. below is a part of code, where am calling bind function with link local IPv6 address of the ethernet interface.
but the code is throwing error.
code:
import socket
localIP = "fe80::3c96:a2e2:a7ca:6323"
localPort = 20001
bufferSize = 1024
snd_adv = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
snd_adv.bind((localIP, localPort)) #this is throwing error
addr2 = ("fe80::faf5:32ff:fe4f:6340", 20003) #this is working good
msg = ['0x00', '0xf0']
snd_adv.sendto(bytes(msg), addr2)
Error:
snd_adv.bind((localIP, localPort))
OSError: [Errno 22] Invalid argument
why the code is throwing error? And also I have tried some of the code changes, like "fe80::3c96:a2e2:a7ca:6323%en0"-scope ID and getaddrinfo(). these also didn't work.
how can I use a link local IPv6 address in bind function of above code? python version is - Python 3.10.1
Eth interface:
enp1s10 Link encap:Ethernet HWaddr 1c:7e:e5:19:00:74
inet addr:10.78.7.1 Bcast:10.78.7.255 Mask:255.255.255.0
inet6 addr: 2001:2016:0:1::1/64 Scope:Global
inet6 addr: fe80::3c96:a2e2:a7ca:6323/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8397200 errors:0 dropped:0 overruns:0 frame:0
TX packets:7014580 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1367076016 (1.3 GB) TX bytes:7326419371 (7.3 GB)