Proxima ASA 7911 User Manual
Page 105
99
55 name.sin_family= AF_INET;
56 /* htons() converts a 16-bit integer from host to network byte order */
57 name.sin_port= htons(atoi(argv[2]));
58
59 /* Construct message, including Serial Adapter header. */
60 buf[0]= DATA1;
61 buf[3]= 0x1b;
62 dataLength= strlen(DATA);
63 networkDataLength= htons(dataLength);
64 memcpy(&buf[1], (char *)&networkDataLength, sizeof(short));
65 strcpy(&buf[4], DATA);
66 printf(“%s\n”, &buf[4]);
67
68 /* Repeatedly send message to serial adapter */
69 for(i=0; i< 10; i++)
70 {
71
sleep(1);
72
/* Sendto() parameters:
73
1. Local socket which will handle the data.
74
2. Pointer to buffer containing data to be sent.
75
3. Number of bytes of data to be sent.
76
4. Flags (ex. MSG_OOB for TCP urgent data)
77
5. Destination IP address and port number.
78
6. Length of data structure containing destination
79
IP Address/port info.
80
*/
81
if(sendto(sock, buf, dataLength+4, 0,
82
(struct sockaddr *)&name, sizeof(name)) < 0)
83
perror(“Sending datagram message”);
84
npackets++;
85
if (!(npackets % 1000))
86
printf(“%ld packets sent\n”, npackets);
87 }
88 close(sock);
89 exit(0);
90
91