|
@@ -91,82 +91,64 @@ send_response(int session_fd, char response[CONSOLE_BUFFER_LENGTH], ...)
|
91
|
91
|
* to data from ntkd structures such as: me
|
92
|
92
|
* into a response for the ntk console client. */
|
93
|
93
|
|
94
|
|
-static int
|
95
|
|
-request_processing(int session_fd, char unprocessed_request[CONSOLE_BUFFER_LENGTH])
|
96
|
|
-{
|
97
|
|
- if(strncmp(unprocessed_request,"uptime", (int)strlen(unprocessed_request)) == 0)
|
98
|
|
- send_response(session_fd, (char)time(0)-me.uptime);
|
99
|
|
-
|
100
|
|
- else if(strncmp(unprocessed_request,"version", (int)strlen(unprocessed_request)) == 0)
|
101
|
|
- send_response(session_fd, VERSION_STR);
|
102
|
|
-
|
103
|
|
- else if(strncmp(unprocessed_request,"inet_connected", (int)strlen(unprocessed_request)) == 0)
|
104
|
|
- send_response(session_fd, (char)me.inet_connected);
|
105
|
|
-
|
106
|
|
- else if(strncmp(unprocessed_request,"cur_ifs", (int)strlen(unprocessed_request)) == 0)
|
107
|
|
- send_response(session_fd, (char)me.cur_ifs);
|
108
|
|
-
|
109
|
|
- else if(strncmp(unprocessed_request,"cur_ifs_n", (int)strlen(unprocessed_request)) == 0)
|
110
|
|
- send_response(session_fd, (char)me.cur_ifs_n);
|
111
|
|
-
|
112
|
|
- else if(strncmp(unprocessed_request,"cur_qspn_id", (int)strlen(unprocessed_request)) == 0)
|
113
|
|
- send_response(session_fd, (char)me.cur_qspn_id);
|
114
|
|
-
|
115
|
|
- else if(strncmp(unprocessed_request,"cur_ip", (int)strlen(unprocessed_request)) == 0)
|
116
|
|
- send_response(session_fd, (char)me.cur_ip.data);
|
117
|
|
-
|
118
|
|
- /*else if(strncmp(unprocessed_request,"cur_node", (int)strlen(unprocessed_request)) == 0)
|
119
|
|
- send_response(me.cur_node);
|
120
|
|
-
|
121
|
|
- else if(strncmp(unprocessed_request,"ifs", (int)strlen(unprocessed_request)) == 0)
|
122
|
|
- return 0;
|
123
|
|
-
|
124
|
|
- else if(strncmp(unprocessed_request,"ifs_n", (int)strlen(unprocessed_request)) == 0)
|
125
|
|
- return 0;*/
|
126
|
|
- send_response(session_fd, unprocessed_request, " Is invalid or yet to be implemented.");
|
127
|
|
- return -1;
|
128
|
|
-}
|
129
|
|
-
|
130
|
|
-
|
131
|
|
-static int
|
132
|
|
-request_receive(int sock, char message[], int max)
|
|
94
|
+static void
|
|
95
|
+request_processing(int session_fd, cmd_packet_t packet)
|
133
|
96
|
{
|
134
|
|
- int total = 0;
|
135
|
|
- const int bsize = 1024;
|
136
|
|
- char buffer[bsize+1];
|
137
|
|
- int read = bsize;
|
138
|
|
-
|
139
|
|
- message[0] = 0; // initialize for strcat()
|
140
|
|
-
|
141
|
|
- while(read == bsize) {
|
142
|
|
- read = recv(sock, buffer, bsize, 0);
|
143
|
|
- if(read < 0)
|
144
|
|
- return -1; // error, bail out
|
145
|
|
- total += read;
|
146
|
|
- if(total > max)
|
147
|
|
- return -2; // overflow
|
148
|
|
- buffer[read] = 0;
|
149
|
|
- strcat(message, buffer);
|
|
97
|
+ switch (packet.command) {
|
|
98
|
+ case COMMAND_UPTIME:
|
|
99
|
+ send_response(session_fd, (char)time(0)-me.uptime);
|
|
100
|
+ break;
|
|
101
|
+ case COMMAND_VERSION:
|
|
102
|
+ send_response(session_fd, VERSION_STR);
|
|
103
|
+ break;
|
|
104
|
+ case COMMAND_CURIFS:
|
|
105
|
+ send_response(session_fd, (char)me.cur_ifs);
|
|
106
|
+ break;
|
|
107
|
+ case COMMAND_CURIFSCT:
|
|
108
|
+ send_response(session_fd, (char)me.cur_ifs_n);
|
|
109
|
+ break;
|
|
110
|
+ case COMMAND_INETCONN:
|
|
111
|
+ send_response(session_fd, (char)me.inet_connected);
|
|
112
|
+ break;
|
|
113
|
+ case COMMAND_CURQSPNID:
|
|
114
|
+ send_response(session_fd, (char)me.cur_qspn_id);
|
|
115
|
+ break;
|
|
116
|
+ case COMMAND_CURIP:
|
|
117
|
+ send_response(session_fd, (char)me.cur_ip.data);
|
|
118
|
+ break;
|
|
119
|
+ case COMMAND_CURNODE:
|
|
120
|
+ send_response(session_fd, (char)me.cur_node);
|
|
121
|
+ break;
|
|
122
|
+ case COMMAND_IFS:
|
|
123
|
+ send_response(session_fd, "IFS: TODO");
|
|
124
|
+ break;
|
|
125
|
+ case COMMAND_IFSCT:
|
|
126
|
+ send_response(session_fd, "IFS: TODO");
|
|
127
|
+ break;
|
|
128
|
+ default:
|
|
129
|
+ send_response(session_fd, "Provided command is invalid or yet to be implemented.");
|
|
130
|
+ break;
|
150
|
131
|
}
|
151
|
|
-
|
152
|
|
- return total;
|
153
|
132
|
}
|
154
|
133
|
|
155
|
134
|
|
|
135
|
+
|
156
|
136
|
static void
|
157
|
137
|
handle_session(int session_fd)
|
158
|
138
|
{
|
159
|
|
- char request[CONSOLE_BUFFER_LENGTH];
|
|
139
|
+ cmd_packet_t packetIn;
|
160
|
140
|
|
161
|
|
- rc = request_receive(session_fd, request, CONSOLE_BUFFER_LENGTH);
|
162
|
|
- if (rc < 0) {
|
|
141
|
+ rc = recv(session_fd, &packetIn, sizeof(packetIn), 0);
|
|
142
|
+
|
|
143
|
+ printf("%d bytes of data were received\n", rc);
|
|
144
|
+ if (rc < sizeof(packetIn)) {
|
163
|
145
|
perror("recv() failed");
|
164
|
146
|
exit(-1);
|
165
|
147
|
}
|
166
|
148
|
|
167
|
|
- printf("%d bytes of data were received\n", rc);
|
|
149
|
+ printf("0x%x command received\n", packetIn.command);
|
168
|
150
|
|
169
|
|
- request_processing(session_fd, request);
|
|
151
|
+ request_processing(session_fd, packetIn);
|
170
|
152
|
}
|
171
|
153
|
|
172
|
154
|
|