Proxima ASA 7911 User Manual
Page 104

98
13 #define DATA1 0
14
15 main(argc, argv)
16 int argc;
17 char *argv[];
18 {
19 int i, sock;
20 short dataLength;
21 short networkDataLength;
22 long npackets= 0;
23 char buf[1024];
24 struct sockaddr_in name;
25 struct hostent *hp, *gethostbyname();
26
27 if (argc < 3) {
28
printf(“Usage: udpsend hostname port#\n”);
29
exit(3);
30 }
31
32 /* Create socket on which to send:
33
Protocol family= Internet (AF_INET)
34
Type = UDP (SOCK_DGRAM)
35
Protocol = 0: This field is not used
36 */
37 sock= socket(AF_INET, SOCK_DGRAM, 0);
38 if (sock < 0) {
39
perror(“opening datagram socket”);
40
exit(1);
41 }
42
43 /* Create a name, with no wildcards, of the destination socket.
44 Gethostbyname() returns an IP address, given a host name.
45 */
46 hp= gethostbyname(argv[1]);
47 if (hp==0) {
48
fprintf(stderr, “%s: Unknown host\n”, argv[1]);
49
exit(2);
50 }
51
52 /* Fill in socket data structure with destination IP address,
53 socket protocol family, and port number. */
54 memcpy( (char *)&name.sin_addr, (char *)hp->h_addr, hp->h_length);