EDESTADDRREQ
Linux / POSIXERRORCommonNetworkHIGH confidence

Destination Address Required

Production Risk

Programming error; UDP sockets require an explicit destination.

What this means

EDESTADDRREQ (errno 89) is returned when a send operation is performed on an unconnected socket without providing a destination address.

Why it happens
  1. 1Calling send() on a UDP socket without calling connect() first
  2. 2Using write() on an unconnected SOCK_DGRAM socket
  3. 3sendmsg() with a NULL msg_name on an unconnected socket
How to reproduce

send() on an unconnected UDP socket.

trigger — this will error
trigger — this will error
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
// send() without connect() or sendto()
send(sockfd, buf, len, 0);
// Returns -1, errno = EDESTADDRREQ

expected output

send: Destination address required (EDESTADDRREQ)

Fix 1

Use sendto() to specify destination address

WHEN Sending on an unconnected UDP socket

Use sendto() to specify destination address
struct sockaddr_in dest = {
  .sin_family = AF_INET,
  .sin_port = htons(12345),
  .sin_addr.s_addr = inet_addr("192.168.1.1")
};
sendto(sockfd, buf, len, 0, (struct sockaddr*)&dest, sizeof(dest));

Why this works

sendto() accepts a destination address directly, avoiding the need for connect().

Fix 2

Connect the socket first

WHEN Sending to the same address repeatedly

Connect the socket first
connect(sockfd, (struct sockaddr*)&dest, sizeof(dest));
// Now send() and write() work
send(sockfd, buf, len, 0);

Why this works

connect() on UDP sets the default destination; send() and write() then work without an explicit address.

Sources
Official documentation ↗

Linux Programmer Manual send(2)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors