user974703
user974703

Reputation: 1653

Address family not supported by protocol? sendto

I'm encountering a strange problem with my program.

I've been using UDP to transfer a file, with the standard sendto and recvfrom.

I have the server and client communicate back and forth many times during the program.

I've just added a new sendto call in the server's code, and it's giving me this error on execution.

Address family not supported by protocol. and that's coming from my sendto function.

Here is the code it's executing:

if ((numbytes = sendto(sockfd,sDropped,strlen(sDropped), 0,
         (struct sockaddr *)&their_addr, p->ai_addrlen)) == -1) {
    perror("talker: sendto");
    exit(1);
    }

As i said, this code works about 4 other times earlier in the program, so I'm sure i've got everything hooked up right.

Is anyone familiar with this issue, and could give me some insights on what to check for in my program that might produce this problem?

Thanks.

Upvotes: 1

Views: 31998

Answers (2)

teknopaul
teknopaul

Reputation: 6772

Use of a cast means any old junk in their_addr will compile.

(struct sockaddr *)&their_addr

Is their_addr already a pointer? so &their_addr gives a pointer to a pointer?

Upvotes: 0

Iskren
Iskren

Reputation: 1341

See if their_addr.sin_family is set, just wasted a couple of hours fighting with the same message just for that mistake.

Upvotes: 10

Related Questions