/* udpsource.c by Michael Thorpe 2000-11-20 */ #include #include #include #include #include #include #include #include int main(int argc,char **argv) { int i,l,s; struct hostent *he; struct sockaddr_in sa; char *buf; if(argc != 4) { fprintf(stderr,"usage: %s \n",argv[0]); return(1); } l=atoi(argv[3]); buf=(char *)malloc(l); if(!buf) { perror("malloc"); return(-1); } for(i=0;ih_addr,(char *)&sa.sin_addr,he->h_length); sa.sin_family=he->h_addrtype; sa.sin_port=htons(atoi(argv[2])); s=socket(AF_INET,SOCK_DGRAM,0); if(s<0) { perror("socket"); return(-1); } if(0>connect(s,(struct sockaddr *)&sa,sizeof(sa))) { perror("connect"); return(-1); } while(1) { i=write(s,buf,l); if(i<0) { perror("write"); return(-1); } /* printf("Wrote %d bytes\n",i); */ } return(-1); }