0

I am implementing DNS server and DNS resolver and i am using socket programming in this. But i get error in function bind() as bind() failed and sendto() permission denied.

I had tried using different port numbers, also i am working as a root, but still it giving me same error.Please help me to solve those issues. Your answers are welcome. Thanks.

https://github.com/srijan/DNS-Server---Resolver/tree/c73a124a15f53eb985a4b4afc0dffedd432c8454

Jaap
  • 81,064
  • 34
  • 182
  • 193
P.Hajare
  • 17
  • 1
  • 1
  • 2
  • It usually means some other socket is open on the given port. – dbush Dec 06 '16 at 14:07
  • 1
    Possible duplicate of [Error: Address already in use while binding socket with address but the port number is shown free by \`netstat\`](http://stackoverflow.com/questions/5106674/error-address-already-in-use-while-binding-socket-with-address-but-the-port-num) – ctrl-shift-esc Dec 06 '16 at 14:10
  • Can you post some actual code on where the error is occurring plus the error message? http://stackoverflow.com/help/how-to-ask – garfbradaz Dec 06 '16 at 14:15
  • @ctrl-shift-esc That only applies to TCP sockets. This is UDP. – dbush Dec 06 '16 at 14:16
  • https://sites.google.com/site/pallavihajare3/dns_implementation-1 – P.Hajare Dec 06 '16 at 17:48
  • Writing a resolver is _hard_ - be prepared for lots and lots of edge conditions – Alnitak Dec 06 '16 at 17:56
  • @dbush not true - it's possible to `bind()` UDP sockets, too. – Alnitak Dec 06 '16 at 17:56
  • how come the Git repo is 5 years old and you're just asking now? – Alnitak Dec 06 '16 at 17:57
  • @Alnitak I was referring to the dup specifally, which deals with TCP sockets in TIME_WAIT. But yes, both TCP and UDP will fail to bind if another socket is open. – dbush Dec 06 '16 at 18:00
  • hello,dbush and Alnitak , i have shared my code on google site , i want IP address as a output , anyone could tell me ,what is going wrong in my code?Your suggestions are welcome.thanks. – P.Hajare Dec 06 '16 at 18:19
  • @P.Hajare it rather looks like _someones else's_ code to me... – Alnitak Dec 06 '16 at 18:46
  • Yeah,but i want to use this code , i had understood working of dns , but while implementing i m facing problem. – P.Hajare Dec 07 '16 at 07:24

2 Answers2

2

This error typically means some other socket in the system is open on the same port.

To see what other UDP sockets are open, run netstat -anu from the command line. You'll get a list of IP/port pairings. If you see one for port 53, that socket is conflicting with yours. If you are able to run as root and also use the -p option, it will additionally tell you the process number that owns each socket.

dbush
  • 205,898
  • 23
  • 218
  • 273
1

Run Netstat -anob with CLI in Windows.

C:\Windows\System32>socat TCP-LISTEN:443,fork,reuseaddr TCP:localhost:22
2021/02/01 16:22:41 socat[11240] E bind(5, {AF=2 0.0.0.0:443}, 16): Address already in use

C:\WINDOWS\system32>netstat -anob

Connexions actives

  Proto  Adresse locale         Adresse distante       État
  TCP    0.0.0.0:22             0.0.0.0:0              LISTENING       5676
 [sshd.exe]
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1244
  RpcSs
 [svchost.exe]
  TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       7396
 [vmware-hostd.exe]
  TCP    0.0.0.0:445            0.0.0.0:0              LISTENING       4

[vmware-hostd.exe] is the process that listen instead of [socat.exe].

In my case, I am using VMware Workstation 16 Pro and have disabled virtual machine sharing in Preferences, which is an deprecated option. All is now OK.

WMware Workstation Server deprecated

valorisa
  • 11
  • 2