13#define DATA1 0

15main(argc, argv)

16int argc;

17char *argv[];

18{

19int i, sock;

20short dataLength;

21short networkDataLength;

22long npackets= 0;

23char buf[1024];

24struct sockaddr_in name;

25struct hostent *hp, *gethostbyname();

27if (argc < 3) {

28printf(“Usage: udpsend hostname port#\n”);

29exit(3);

30}

31

32/* Create socket on which to send:

33Protocol family= Internet (AF_INET)

34Type = UDP (SOCK_DGRAM)

35Protocol = 0: This field is not used

36*/

37sock= socket(AF_INET, SOCK_DGRAM, 0);

38if (sock < 0) {

39perror(“opening datagram socket”);

40exit(1);

41}

42

43/* Create a name, with no wildcards, of the destination socket.

44Gethostbyname() returns an IP address, given a host name.

45*/

46hp= gethostbyname(argv[1]);

47if (hp==0) {

48fprintf(stderr, “%s: Unknown host\n”, argv[1]);

49exit(2);

50}

51

52/* Fill in socket data structure with destination IP address,

53socket protocol family, and port number. */

54memcpy( (char *)&name.sin_addr, (char *)hp->h_addr, hp->h_length);

98

Page 104
Image 104
Proxima ASA 7910, 7911 manual