/* $Id: aprs-udp-tx.c,v 1.1 2005/08/10 12:10:10 james Exp james $ udpqx, transmit packet to stream Copyright (C) 2005 James Cameron This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef lint static char vcid[] = "$Id: aprs-udp-tx.c,v 1.1 2005/08/10 12:10:10 james Exp james $"; #endif /* lint */ #include #include #include #include #include #include int main (int argc, char *argv[]) { unsigned short port; char *host; int sock; struct sockaddr_in address; int len, stat; char buf[BUFSIZ]; port = 8135; if (argc > 1) host = argv[1]; if (argc > 2) port = atoi(argv[2]); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { perror("socket"); exit(1); } address.sin_family = AF_INET; address.sin_port = htons(port); if ((address.sin_addr.s_addr = inet_addr(host)) == -1) { struct hostent *hp; if ((hp = gethostbyname(host)) == NULL) { herror("gethostbyname"); exit(2); } else { address.sin_addr.s_addr = *(long *) hp->h_addr; } } while (1) { /* read chunk from stdin */ len = read(STDIN_FILENO, buf, BUFSIZ); if (len < 0) { perror("read"); exit(3); } /* stop on end of file */ if (len == 0) break; /* send chunk to stream */ stat = sendto(sock, buf, len, 0, (struct sockaddr *) &address, sizeof(struct sockaddr)); if (stat < 0) { perror("sendto"); exit(4); } } close(sock); }