Recvfrom Error 14
Contents |
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
Sendto Errno 14
Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation sendto failed address family not supported by protocol Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just
C Recv Bad Address
like you, helping each other. Join them; it only takes a minute: Sign up Simple messaging application…getting errno 14: bad address up vote 4 down vote favorite I am writing a simple messaging application in C using sockets. sendto man When I use function recvfrom, it returns -1 and sets errno = 14 which is Bad address (which I am printing at the end). The strange thing is that it still reads from the socket and gets the correct message. That is, the application is working perfectly and as expected except for that error. My question is this: Why do you think I am getting this error? I cannot think of any reason. I was recvfrom c using inet_pton to set peer->sin_addr but I was getting the same error. // socket file descriptor to send data through int recv_sock_fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); // fill in the peer's address, loopback in this case struct sockaddr_in *peer = malloc(sizeof(struct sockaddr_in)); peer->sin_family = AF_INET; peer->sin_port = htons(11110); char *new = &(peer->sin_addr); new[0] = 127; new[1] = 0; new[2] = 0; new[3] = 1; for (int i = 0; i < 8; i++) { peer->sin_zero[i] = NULL; } bind(recv_sock_fd, peer, sizeof(struct sockaddr_in)); // check to see if the socket has any data...code removed char buff[32] = {0}; errno = 0; int bytes_received = recvfrom(recv_sock_fd, buff, sizeof(buff), NULL, (struct sockaddr *)peer, sizeof(struct sockaddr_in)); printf("Bytes recieved: %d: %d : %s\n", bytes_received, errno, strerror(errno)); c sockets errno share|improve this question asked Nov 30 '11 at 1:32 mtahmed 1,79732037 add a comment| 1 Answer 1 active oldest votes up vote 6 down vote accepted Look at the signature of recvfrom(2): ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); Last argument is an address, while you are giving it a plain integer. Then you're building of the IP address is wrong. Do use inet_pton(3), that's what it's for. Also check the return value of the bind(2), it's surely failing now. share|improve this answer edited Jun 16 '13 at 20:55 Drew Noakes 12
an error code of 14, EFAULT "Bad Address" - UNIX Programming I'll post the code at the bottom of the post. Whenever I try to retreive a udp packet sent via broadcast I get the
Sendto C
errorcode EFAULT(bad address). The same program sends out the packets without any complaints but it fails when retreiving, I'm lost as to why it would report this error. It returns the number of bytes correctly but returns the char* buffer as NULL. Any help would be appriciated and I wouldn't be supprised if I was just missing something simple with broacasting as I am still learning some aspects of socket programiing.Thanks http://stackoverflow.com/questions/8320090/simple-messaging-application-getting-errno-14-bad-address in advance to all whom ... Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode July 3rd,04:20 PM #1 recvfrom returns with an error code of 14, EFAULT "Bad Address" I'll post the code at the bottom of the post. Whenever I try to retreive a udp packet sent via broadcast I get the errorcode EFAULT(bad address). http://www.justskins.com/forums/recvfrom-returns-with-an-97652.html The same program sends out the packets without any complaints but it fails when retreiving, I'm lost as to why it would report this error. It returns the number of bytes correctly but returns the char* buffer as NULL. Any help would be appriciated and I wouldn't be supprised if I was just missing something simple with broacasting as I am still learning some aspects of socket programiing.Thanks in advance to all whom reply and here is the code: int Communications::GetBroadcastSocket() { int toReturn; int on = 1; // flag to turn on socket options memset(&broadcast, 0, sizeof(broadcast)); broadcast.sin_family = AF_INET; broadcast.sin_port = PORTNUM + 1; broadcast.sin_addr.s_addr = inet_addr(BCAST_ADDR); if((toReturn = socket(AF_INET, SOCK_DGRAM, 0)) == -1) return -1; if( SetNonBlocking(toReturn) < 0 || setsockopt(toReturn, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0 || setsockopt(toReturn, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0 || bind(toReturn, (sockaddr *) &broadcast, sizeof(broadcast)) < 0) { close(toReturn); return -1; } return toReturn; } Chris Ritchey Guest July 3rd,05:29 PM #2 Re: recvfrom returns with an error code of 14, EFAULT "Bad Address" In article <480de79d.0307030820.7b959e89posting.google.com >, Chris Ritchey
*buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen); ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); Description The recvfrom() and recvmsg() https://linux.die.net/man/2/recvfrom calls are used to receive messages from a socket, and may be used to receive data on a socket whether or not it is connection-oriented. If src_addr is not http://www.linuxquestions.org/questions/programming-9/recv-bad-address-unix-socket-programming-510194/ NULL, and the underlying protocol provides the source address, this source address is filled in. When src_addr is NULL, nothing is filled in; in this case, addrlen is recvfrom error not used, and should also be NULL. The argument addrlen is a value-result argument, which the caller should initialize before the call to the size of the buffer associated with src_addr, and modified on return to indicate the actual size of the source address. The returned address is truncated if the buffer provided is too small; recvfrom error 14 in this case, addrlen will return a value greater than was supplied to the call. The recv() call is normally used only on a connected socket (see connect(2)) and is identical to recvfrom() with a NULL src_addr argument. All three routines return the length of the message on successful completion. If a message is too long to fit in the supplied buffer, excess bytes may be discarded depending on the type of socket the message is received from. If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is nonblocking (see fcntl(2)), in which case the value -1 is returned and the external variable errno is set to EAGAIN or EWOULDBLOCK. The receive calls normally return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested. The select(2) or poll(2) call may be used to determine when more data arrives. The flags argument to a recv() call is formed
HCL Search Reviews Search ISOs Go to Page... LinuxQuestions.org > Forums > Non-*NIX Forums > Programming recv: Bad address (UNIX Socket programming) User Name Remember Me? Password Programming This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game. Notices Welcome to LinuxQuestions.org, a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today! Note that registered members see fewer ads, and ContentLink is completely disabled once you log in. Are you new to LinuxQuestions.org? Visit the following links: Site Howto | Site FAQ | Sitemap | Register Now If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here. Having a problem logging in? Please visit this page to clear all LQ-related cookies. Introduction to Linux - A Hands on Guide This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Click Here to receive this Complete Guide absolutely free. Search this Thread 12-13-2006, 06:40 PM #1 anamericanjoe Member Registered: May 2006 Posts: 69 Rep: recv: Bad address (UNIX Socket programming) I'm working on sending messag