📄 listener.lst
字号:
C51 COMPILER V6.02 LISTENER 04/22/2003 14:33:57 PAGE 1
C51 COMPILER V6.02, COMPILATION OF MODULE LISTENER
OBJECT MODULE PLACED IN D:\NET\PRO2\LISTENER.OBJ
COMPILER INVOKED BY: D:\SOFT\WAVE\COMP51\C51.EXE D:\NET\PRO2\LISTENER.C DB SB OE
stmt level source
1 // Phillip Hoang
2 // Arun Gupta
3 // May 31, 2001
4 //=============================================================================
5
6 // ----------------------------------------------------------------
7 // Version 0.2
8 // A while(1) loop was inserted so that it would constantly look
9 // for udp packets.
10 // The webpage also now includes a 1 second refresh
11 // ----------------------------------------------------------------
12 // Version 0.1
13 // Added file I/O to the program so that it creates a webpage.
14 // ----------------------------------------------------------------
15 // Version 0.0
16 // This receives temperature information from the udp packet.
17 // Takes buf[0] the first byte of the packet and does some
18 // calculations to display the temperature in degrees farenheit.
19 // ----------------------------------------------------------------
20
21 //=============================================================================
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <errno.h>
*** ERROR 318 IN LINE 25 OF D:\NET\PRO2\LISTENER.C: can't open file 'errno.h'
26 #include <string.h>
27 #include <sys/types.h>
*** ERROR 318 IN LINE 27 OF D:\NET\PRO2\LISTENER.C: can't open file 'sys/types.h'
28 #include <netinet/in.h>
*** ERROR 318 IN LINE 28 OF D:\NET\PRO2\LISTENER.C: can't open file 'netinet/in.h'
29 #include <sys/socket.h>
*** ERROR 318 IN LINE 29 OF D:\NET\PRO2\LISTENER.C: can't open file 'sys/socket.h'
30 #include <sys/wait.h>
*** ERROR 318 IN LINE 30 OF D:\NET\PRO2\LISTENER.C: can't open file 'sys/wait.h'
31
32 //=============================================================================
33
34 #define MYPORT 4950 /* the port users will be sending to */
35 #define MAXBUFLEN 100
36
37 //=============================================================================
38
39 void create_html_file(float fahr, float remainder)
40 {
41 1 FILE *WebFile;
*** ERROR C202 IN LINE 41 OF D:\NET\PRO2\LISTENER.C: 'FILE': undefined identifier
42 1
43 1 // Create File
44 1 WebFile = fopen("temperature.html", "w");
*** ERROR C202 IN LINE 44 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
45 1 if( WebFile == NULL ) {
*** ERROR C202 IN LINE 45 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
46 2 puts("Error opening file temperature.html");
47 2 exit(0);
C51 COMPILER V6.02 LISTENER 04/22/2003 14:33:57 PAGE 2
*** WARNING C206 IN LINE 47 OF D:\NET\PRO2\LISTENER.C: 'exit': missing function-prototype
*** ERROR C267 IN LINE 47 OF D:\NET\PRO2\LISTENER.C: 'exit': requires ANSI-style prototype
48 2 }
49 1
50 1 // Write to file
51 1 fprintf(WebFile,"<html>\n");
*** ERROR C202 IN LINE 51 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
52 1
53 1 // Meta Refresh
54 1 fprintf(WebFile,"<head>\n");
*** ERROR C202 IN LINE 54 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
55 1 fprintf(WebFile,"<META HTTP-EQUIV=\"refresh\" content=\"1;URL=temperature.html\">");
*** ERROR C202 IN LINE 55 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
56 1 fprintf(WebFile,"</head>\n");
*** ERROR C202 IN LINE 56 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
57 1
58 1 // Display Temperature
59 1 fprintf(WebFile,"Temperature: %d.%d \n",(int)fahr,(int)remainder);
*** ERROR C202 IN LINE 59 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
60 1 fprintf(WebFile,"</html>");
*** ERROR C202 IN LINE 60 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
61 1
62 1 fclose(WebFile);
*** ERROR C202 IN LINE 62 OF D:\NET\PRO2\LISTENER.C: 'WebFile': undefined identifier
63 1 }
64
65 //=============================================================================
66
67 void print_temperature(char temp)
68 {
69 1 float fahr;
70 1 float remainder;
71 1
72 1 fahr = 1.8 * (int)temp + 32;
73 1 remainder = fahr;
74 1 remainder = fahr - (int)fahr;
75 1 remainder = remainder * 10;
76 1
77 1 printf("Temperature: %d.%d \n",(int)fahr,(int)remainder);
78 1
79 1 create_html_file(fahr, remainder);
80 1 }
81
82 //=============================================================================
83
84 int main(void)
85 {
86 1 int sockfd;
87 1
88 1 struct sockaddr_in my_addr; /* my address information */
*** ERROR C230 IN LINE 88 OF D:\NET\PRO2\LISTENER.C: 'sockaddr_in': unknown struct/union/enum tag
89 1 struct sockaddr_in their_addr; /* connector's address information */
*** ERROR C230 IN LINE 89 OF D:\NET\PRO2\LISTENER.C: 'sockaddr_in': unknown struct/union/enum tag
90 1 int addr_len, numbytes;
91 1
92 1 char buf[MAXBUFLEN];
93 1
94 1 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
*** ERROR C202 IN LINE 94 OF D:\NET\PRO2\LISTENER.C: 'AF_INET': undefined identifier
95 2 perror("socket");
*** WARNING C206 IN LINE 95 OF D:\NET\PRO2\LISTENER.C: 'perror': missing function-prototype
96 2 exit(1);
C51 COMPILER V6.02 LISTENER 04/22/2003 14:33:57 PAGE 3
97 2 }
98 1
99 1 my_addr.sin_family = AF_INET; /* host byte order */
*** ERROR C202 IN LINE 99 OF D:\NET\PRO2\LISTENER.C: 'my_addr': undefined identifier
100 1 my_addr.sin_port = htons(MYPORT); /* short, network byte order */
*** ERROR C202 IN LINE 100 OF D:\NET\PRO2\LISTENER.C: 'my_addr': undefined identifier
101 1 my_addr.sin_addr.s_addr = INADDR_ANY; /* auto-fill with my IP */
*** ERROR C202 IN LINE 101 OF D:\NET\PRO2\LISTENER.C: 'my_addr': undefined identifier
102 1 bzero(&(my_addr.sin_zero), 8); /* zero the rest of the struct */
*** ERROR C202 IN LINE 102 OF D:\NET\PRO2\LISTENER.C: 'my_addr': undefined identifier
103 1
104 1 // Open a Socket
105 1 if(bind(sockfd,(struct sockaddr *)&my_addr,sizeof(struct sockaddr)) == -1)
*** WARNING C206 IN LINE 105 OF D:\NET\PRO2\LISTENER.C: 'bind': missing function-prototype
*** ERROR C202 IN LINE 105 OF D:\NET\PRO2\LISTENER.C: 'my_addr': undefined identifier
106 1 {
107 2 perror("bind");
108 2 exit(1);
109 2 }
110 1
111 1 addr_len = sizeof(struct sockaddr);
*** ERROR C230 IN LINE 111 OF D:\NET\PRO2\LISTENER.C: 'sockaddr': unknown struct/union/enum tag
112 1
113 1 // Wait for UDP packet with temperature information, and Display temperature.
114 1 while(1) {
115 2
116 2 if ((numbytes=recvfrom(sockfd, buf, MAXBUFLEN, 0,
*** WARNING C206 IN LINE 116 OF D:\NET\PRO2\LISTENER.C: 'recvfrom': missing function-prototype
117 2 (struct sockaddr *)&their_addr, &addr_len)) == -1)
*** ERROR C202 IN LINE 117 OF D:\NET\PRO2\LISTENER.C: 'their_addr': undefined identifier
118 2 {
119 3 perror("recvfrom");
120 3 exit(1);
121 3 }
122 2
123 2 printf("got packet from %s\n",inet_ntoa(their_addr.sin_addr));
*** ERROR C202 IN LINE 123 OF D:\NET\PRO2\LISTENER.C: 'their_addr': undefined identifier
124 2 printf("packet is %d bytes long\n",numbytes);
125 2 buf[numbytes] = '\0';
*** ERROR C213 IN LINE 125 OF D:\NET\PRO2\LISTENER.C: left side of asn-op not an lvalue
126 2 print_temperature(buf[0]);
127 2
128 2 }
129 1
130 1 close(sockfd);
*** WARNING C206 IN LINE 130 OF D:\NET\PRO2\LISTENER.C: 'close': missing function-prototype
131 1
132 1 return 0;
133 1 }
134
135 //=============================================================================
C51 COMPILATION COMPLETE. 5 WARNING(S), 28 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -