2 * FILE: $Header: /home/egg/src/RCS/testudp.c,v 1.2 1998/07/21 11:34:48 ghn Exp $
3 * PURPOSE: Testing UDP communications (fake basket)
7 * REVISED: $Log: testudp.c,v $
8 * REVISED: Revision 1.2 1998/07/21 11:34:48 ghn
9 * REVISED: Testing UDP communications (fake basket)
11 * Copyright 1998 - Greg Nelson
12 * Redistributable under the terms of the GNU Public Licence (GPL)
18 #include <netinet/in.h>
26 int main(int argc, char *argv[]) {
30 struct sockaddr_in rhost;
37 printf("Usage: %s <host>\n", pgmname);
41 if ((pp = getprotobyname("udp")) == NULL) {
42 perror("getprotobyname");
46 if ((hp = gethostbyname(argv[1])) == NULL) {
47 fprintf(stderr, "gethostbyname(%s): %s", argv[1], strerror(errno));
51 if (hp->h_addrtype != AF_INET) {
52 fprintf(stderr, "Host is not on the internet!\n");
56 rhost.sin_port = htons(EGGPORT);
57 rhost.sin_family = AF_INET;
58 memcpy(&(rhost.sin_addr), hp->h_addr, hp->h_length);
60 rhdr.type = REQ_PACKET;
61 rhdr.pktsize = sizeof(ReqHeader);
62 rhdr.eggid = 30800; /* halebopp! */
68 rhdr.cksum = BlockCRC16((byte *)&rhdr, sizeof(ReqHeader)-2);
70 if ((out_sock = socket(AF_INET, SOCK_DGRAM, pp->p_proto)) < 0) {
75 i = sendto(out_sock, &rhdr, rhdr.pktsize,
76 0, (struct sockaddr *)&rhost,
77 sizeof(struct sockaddr));
82 if (i != rhdr.pktsize) {
83 fprintf(stderr, "Failed to send complete packet (%ld/%d)\n",