Error Sending On Udp Network Is Unreachable 51
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Linux: How to send udp packet to unreachable ip address up vote 1 down vote favorite My program (c++ socket) receives broadcast udp datagram from another network but my program can't send udp reply to this address because "Network is unreachable" error is raised on "sendto" method. Need to ignore netmask on reply. Is there any socket flag to resolve this problem? P.S. I have simple device that works just so. SOLUTION To send packet to any network you should set default gateway with it's own ip address. My method: int32_t setNewIp(uint8_t A_, uint8_t B_, uint8_t C_, uint8_t D_) { uint8_t ip_cmd[60]; snprintf((char*) ip_cmd, sizeof (ip_cmd), "ifconfig eth0 inet %hhu.%hhu.%hhu.%hhu", A_, B_, C_, D_); int32_t res = system((char*) ip_cmd); if (res != 0) goto exit; snprintf((char*) ip_cmd, sizeof (ip_cmd), "route add default gw %hhu.%hhu.%hhu.%hhu", A_, B_, C_, D_); res = system((char*) ip_cmd); exit: return res == 0 ? OK : SYSTEM_ERR; } c++ linux sockets udp broadcast share|improve this question edited Jan 27 '14 at 8:20 asked Jan 24 '14 at 10:02 Andrey Burykin 325111 1 Normally broadcasts will not transmitted over network borders, meaning a router. It seems you need to configure the router in a way that it forwards that packages. Also you need to configure the route to the remote network on your local pc –hek2mgl Jan 24 '14 at 10:05 1 Either 1. You do not have a route set up to the remote network. 2. You have a route (e.g. the default route) that cannot reach this other network (so it gives an ICMP network unreachable reply b
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Broadcast sendto failed up vote 0 down vote favorite I am trying to broadcast data but the output http://stackoverflow.com/questions/21329693/linux-how-to-send-udp-packet-to-unreachable-ip-address is udp send failed. I chose a random port 33333. What's wrong with my code? int main() { struct sockaddr_in udpaddr = { sin_family : AF_INET }; int xudpsock_fd,sock,len = 0,ret = 0,optVal = 0; char buffer[255]; char szSocket[64]; memset(buffer,0x00,sizeof(buffer)); memset(&udpaddr,0,sizeof(udpaddr)); udpaddr.sin_addr.s_addr = INADDR_BROADCAST; udpaddr.sin_port = htons(33333); xudpsock_fd = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); optVal = 1; ret = setsockopt(xudpsock_fd,SOL_SOCKET,SO_BROADCAST,(char*)&optVal,sizeof(optVal)); strcpy(buffer,"this is a test msg"); len = sizeof(buffer); ret = sendto(xudpsock_fd,buffer,len,0,(struct sockaddr*)&udpaddr,sizeof(udpaddr)); if (ret == -1) http://stackoverflow.com/questions/17426197/broadcast-sendto-failed printf("udp send failed\n"); else printf("udp send succeed\n"); return (0); } sockets udp broadcast sendto share|improve this question asked Jul 2 '13 at 12:54 Brknl 398 What does errno say about the failure? –Joe Jul 2 '13 at 12:55 It says 101, Nertwork is unreachable but i don't understand what does it mean with unreachable,i can send tcp packets on the same network. –Brknl Jul 2 '13 at 13:14 Just because a TCP connection will traverse the network it doesn't mean that the UDP broadcast will. –Joe Jul 2 '13 at 13:22 see the following link : stackoverflow.com/questions/2782259/sendto-network-unreachable –jhonnash Jul 2 '13 at 13:26 I solved the problem. I changed the udpaddr.sin_addr.s_addr = INADDR_BROADCAST; to udpaddr.sin_addr.s_addr = inet_addr("127.255.255.255"); and it works but i don't understand why. –Brknl Jul 2 '13 at 14:15 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote One problem is that the address family you are trying to send to is zero (AF_UNSPEC). Although you initialize the family to AF_INET at the top of the function, you later zero it out with memset. On the system I tested with, the send actually works anyway for some strange reason despite the invalid address family, but you should defi
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow http://superuser.com/questions/744848/tcp-vs-udp-sending-data-on-a-closed-port the company Business Learn more about hiring developers or posting ads with us Super User Questions Tags Users Badges Unanswered Ask Question _ Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute: Sign up Here's how it works: Anybody can ask a question Anybody can answer The best answers are voted up and rise to the top TCP vs UDP. Sending data error sending on a closed port up vote 2 down vote favorite 2 I try to understand differences between TCP and UDP packet on the error-checking. I know that UDP packets are connectionless and doesn't care that the packet will arrive the destination safely. And TCP packet is the opposite of UDP. My question is, if a packet send into a closed port of a remote host, what action will take place on UDP and error sending on TCP packets? UDP packet - response with an ICMP (Code-3)? TCP packet - response with a RST packet? tcp udp packet share|improve this question asked Apr 23 '14 at 0:47 ebyrock 1123 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote According to the RFC 793 Reset Generation rules: As a general rule, reset (RST) must be sent whenever a segment arrives which apparently is not intended for the current connection. A reset must not be sent if it is not clear that this is the case. There are three groups of states: 1. If the connection does not exist (CLOSED) then a reset is sent in response to any incoming segment except another reset. In particular, SYNs addressed to a non-existent connection are rejected by this means. Since the port is closed (not listening or communicating) there is no connections and because of that TCP is supposed to reply with a RST package. RFC 768 for UDP does not specify any action on a closed port but the ICMP RFC 792 specifies a message Type 3 Code 3, Destination Unreachable: Destination port unreachable that may be sent. However, ports only actually do this if they are unfiltered. Filtered connections do not reply at all and simply drop the packet. Filtering is usually d