/* DESC: This script sends a message to a remote UDP server. * Copyright (C) 2012 NetModule AG, Switzerland */ void usage() { printf("usage: udpclient.are \n"); exit(1); } if (argc < 4) { usage(); } SERVER = argv[1]; PORT = (int) argv[2]; MSG = ""; for (i = 3; i < argc; i++) { MSG = strcat(MSG, " ", argv[i]); } sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) { printf("Unable to open socket\n"); exit(1); } sent = sendto(sock, MSG, SERVER, PORT); if (sent == strlen(MSG)) { printf("Successfully sent message to %s:%d\n", SERVER, PORT); } else { printf("ERROR: Sending failed"); } exit(0);