/* * Simple UDP receiver * (c)2013 JBY */ #include <sys/socket.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #define PORT 5678 int main(int argc,char *argv[]) { struct sockaddr_in addr; int sock; char tampon[256]; sock = socket(PF_INET,SOCK_DGRAM,0); // Protocol family if (sock==-1) { perror("socket: "); exit(1); } addr.sin_family = AF_INET; // Address family addr.sin_port = htons(PORT); addr.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(sock,(struct sockaddr *)(&addr),sizeof(addr))==-1) { perror("bind: "); close(sock); exit(1); } while (1) { if (recv(sock,tampon,256,0)==-1) { perror("recv:"); close(sock); exit(1); } printf("Recu : %s\n",tampon); if (!strcmp(tampon,"quit")) break; } close(sock); return 0; }