I am trying to write a TFTP server. I have successfully completed the code, it is fully RFC 1350 compliant.
However, I wrote the whole thing in Haiku OS, and in Haiku, it works great. However, I also need a DHCP server, and I don't have one for Haiku. So I need to port my TFTP server to Linux.
Now the code compiles fine in linux, but does not receive any packets sent to it. I can do wireshark captures and see that the packets are arriving, but my server does not receive them. I added some debugging printfs and found that bind is returning a -1 (instead of 0 like in Haiku). I am running the executable as root, so its not a permissions issue. Am I doing something wrong? Here is some of my code:
#include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h>
int sock, length, n; struct sockaddr_in server; struct hostent *hp; unsigned char buffer; //Set up and open datagram socket sock=socket(AF_INET, SOCK_DGRAM, 0); //Setup socket properties server.sin_family = AF_INET; server.sin_addr.s_addr=INADDR_ANY; server.sin_port = htons(69); length = sizeof(struct sockaddr_in); n=bind(sock,(struct sockaddr *)&server,length); //Finish setting up datagram socket. It should be open. printf("%d\n",n);
So where did I go wrong?