Browse Source

ntk-console: Begin returning valid results in ntk-console-server

Alexander von Gluck IV 10 years ago
parent
commit
cea41ed409
2 changed files with 19 additions and 12 deletions
  1. 18
    11
      src/ntk-console-server.c
  2. 1
    1
      src/ntk-console.c

+ 18
- 11
src/ntk-console-server.c View File

94
 static void
94
 static void
95
 request_processing(int session_fd, cmd_packet_t packet)
95
 request_processing(int session_fd, cmd_packet_t packet)
96
 {
96
 {
97
+	char buffer[CONSOLE_BUFFER_LENGTH];
98
+	int maxBuffer = CONSOLE_BUFFER_LENGTH - 1;
99
+
97
 	switch (packet.command) {
100
 	switch (packet.command) {
98
 		case COMMAND_UPTIME:
101
 		case COMMAND_UPTIME:
99
-			send_response(session_fd, (char)time(0)-me.uptime);
102
+		{
103
+			int uptime = time(0) - me.uptime;
104
+			snprintf(buffer, maxBuffer, "node uptime: %d seconds", uptime);
100
 			break;
105
 			break;
106
+		}
101
 		case COMMAND_VERSION:
107
 		case COMMAND_VERSION:
102
-			send_response(session_fd, VERSION_STR);
108
+			snprintf(buffer, maxBuffer, "ntkd version: %s", VERSION_STR);
103
 			break;
109
 			break;
104
 		case COMMAND_CURIFS:
110
 		case COMMAND_CURIFS:
105
-			send_response(session_fd, (char)me.cur_ifs);
111
+			//send_response(session_fd, (char)me.cur_ifs);
106
 			break;
112
 			break;
107
 		case COMMAND_CURIFSCT:
113
 		case COMMAND_CURIFSCT:
108
-			send_response(session_fd, (char)me.cur_ifs_n);
114
+			snprintf(buffer, maxBuffer, "current interface count: %d", me.cur_ifs_n);
109
 			break;
115
 			break;
110
 		case COMMAND_INETCONN:
116
 		case COMMAND_INETCONN:
111
-			send_response(session_fd, (char)me.inet_connected);
117
+			//send_response(session_fd, (char)me.inet_connected);
112
 			break;
118
 			break;
113
 		case COMMAND_CURQSPNID:
119
 		case COMMAND_CURQSPNID:
114
-			send_response(session_fd, (char)me.cur_qspn_id);
120
+			//send_response(session_fd, (char)me.cur_qspn_id);
115
 			break;
121
 			break;
116
 		case COMMAND_CURIP:
122
 		case COMMAND_CURIP:
117
-			send_response(session_fd, (char)me.cur_ip.data);
123
+			//send_response(session_fd, (char)me.cur_ip.data);
118
 			break;
124
 			break;
119
 		case COMMAND_CURNODE:
125
 		case COMMAND_CURNODE:
120
-			send_response(session_fd, (char)me.cur_node);
126
+			//send_response(session_fd, (char)me.cur_node);
121
 			break;
127
 			break;
122
 		case COMMAND_IFS:
128
 		case COMMAND_IFS:
123
-			send_response(session_fd, "IFS: TODO");
129
+			//send_response(session_fd, "IFS: TODO");
124
 			break;
130
 			break;
125
 		case COMMAND_IFSCT:
131
 		case COMMAND_IFSCT:
126
-			send_response(session_fd, "IFS: TODO");
132
+			//send_response(session_fd, "IFS: TODO");
127
 			break;
133
 			break;
128
 		default:
134
 		default:
129
-			send_response(session_fd, "Provided command is invalid or yet to be implemented.");
135
+			snprintf(buffer, maxBuffer, "Provided command is invalid or not implemented in this API");
130
 			break;
136
 			break;
131
 	}
137
 	}
138
+	send_response(session_fd, buffer);
132
 }
139
 }
133
 
140
 
134
 
141
 

+ 1
- 1
src/ntk-console.c View File

158
 		exit(-1);
158
 		exit(-1);
159
 	}
159
 	}
160
 
160
 
161
-	printf("Response: '%s'\n", response);
161
+	printf("%s\n", response);
162
 	free(response);
162
 	free(response);
163
 	closesocket();
163
 	closesocket();
164
 }
164
 }

Loading…
Cancel
Save