#include #include #include #include #include int main(int argc, char *argv[]) { int sock; struct sockaddr_in addr; char buf[1024]; int bytes_read; if (argc < 2) { perror("no port provided"); exit(0); } sock = socket(AF_INET, SOCK_DGRAM, 0); if(sock < 0) { perror("Cant open socket"); exit(1); } addr.sin_family = AF_INET; addr.sin_port = htons(atoi(argv[1])); addr.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("bind"); exit(2); } while(1) { bytes_read = recvfrom(sock, buf, 1024, 0, NULL, NULL); buf[bytes_read] = '\0'; printf(buf); } return 0; }