Proxima ASA 7911 User Manual

Page 101

Advertising
background image

95

40 hp= gethostbyname(argv[1]);
41 if (hp==0) {
42

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

43

exit(2);

44 }
45 memcpy( (char *)&server.sin_addr, (char *)hp->h_addr, hp-h_length);
46 server.sin_port= htons(atoi(argv[2]));
47
48 /* Use the connect() socket call to initiate a TCP connection with
49 the remote machine. */
50 printf(“Connecting...\n”);
51 if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0 ) {
52

perror(“Connecting stream socket”);

53

exit(1);

54 }
55 printf(“Connected.\n”);
56
57 /* Construct message, including Serial Adapter header bytes */
58 buf[0]= DATA1;
59 buf[3]= 0xf0;
60 dataLength= strlen(DATA);
61 memcpy(&buf[1], &(htons(dataLength)), sizeof(short));
62 strcpy(&buf[4], DATA);
63 printf(“%s\n”, &buf[4]);
64
65 /* Send message */
66 if(write (sock, buf, dataLength+4) < 0)
67

perror(“Sending stream message”);

68
69 /* Send $QUIT string to the serial adapter to tell it to close its
70 side of the TCP connection. */
71 dataLength= 5;
72 memcpy(&buf[1], &(htons(dataLength)), sizeof(short));
73 memcpy(&buf[4], “$QUIT”, 5);
74 if(write (sock, buf, dataLength+4) < 0)
75

perror(“Sending $QUIT message”);

76
77 close(sock);
78 exit(0);
79
80 }

Advertising
This manual is related to the following products: