summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-12-23 15:54:40 +0100
committerHåkon Nessjøen <haakon.nessjoen@gmail.com>2010-12-23 15:54:40 +0100
commitc91ff9668142a9d0aac0bc364ccaf40611fa9c72 (patch)
tree980304707df6d5e7820208db017dbfb9ccdf0384
parent20746581ba3e8c6cda0851e47b27528401168247 (diff)
downloadMAC-Telnet-c91ff9668142a9d0aac0bc364ccaf40611fa9c72.tar.gz
MAC-Telnet-c91ff9668142a9d0aac0bc364ccaf40611fa9c72.zip
Cleaned up code and added -Wall to the compiler flags. Moved packet types over to enums for more ease of use.
-rw-r--r--Makefile6
-rw-r--r--devices.c17
-rw-r--r--devices.h6
-rw-r--r--mactelnet.c64
-rw-r--r--mactelnetd.c55
-rw-r--r--protocol.c9
-rw-r--r--protocol.h48
-rw-r--r--users.c12
-rw-r--r--users.h6
9 files changed, 110 insertions, 113 deletions
diff --git a/Makefile b/Makefile
index d6e6d7b..ce31dd4 100644
--- a/Makefile
+++ b/Makefile
@@ -15,10 +15,10 @@ install: all
chmod 600 $(DESTDIR)/etc/mactelnetd.users
mactelnet: config.h udp.h udp.c mactelnet.c mactelnet.h protocol.c protocol.h console.c console.h devices.c devices.h md5.c md5.h
- gcc -g -DUSERSFILE='"/etc/mactelnetd.users"' -o mactelnet mactelnet.c udp.c protocol.c console.c devices.c md5.c
+ gcc -Wall -g -DUSERSFILE='"/etc/mactelnetd.users"' -o mactelnet mactelnet.c udp.c protocol.c console.c devices.c md5.c
mactelnetd: config.h mactelnetd.c udp.h udp.c protocol.c protocol.h console.c console.h users.c users.h md5.c md5.h
- gcc -g -DUSERSFILE='"/etc/mactelnetd.users"' -o mactelnetd mactelnetd.c udp.c protocol.c console.c users.c md5.c
+ gcc -Wall -g -DUSERSFILE='"/etc/mactelnetd.users"' -o mactelnetd mactelnetd.c udp.c protocol.c console.c users.c md5.c
mndp: config.h mndp.c protocol.c protocol.h
- gcc -g -o mndp mndp.c protocol.c
+ gcc -Wall -g -o mndp mndp.c protocol.c
diff --git a/devices.c b/devices.c
index 9fafdb7..a40ee9d 100644
--- a/devices.c
+++ b/devices.c
@@ -35,7 +35,7 @@
/* Functions using NETDEVICE api */
-int getDeviceIndex(int sockfd, unsigned char *deviceName) {
+int getDeviceIndex(int sockfd, char *deviceName) {
struct ifreq ifr;
/* Find interface index from deviceName */
@@ -48,7 +48,7 @@ int getDeviceIndex(int sockfd, unsigned char *deviceName) {
return ifr.ifr_ifindex;
}
-int getDeviceMAC(const int sockfd, const unsigned char *deviceName, unsigned char *mac) {
+int getDeviceMAC(const int sockfd, const char *deviceName, unsigned char *mac) {
struct ifreq ifr;
/* Find interface hardware address from deviceName */
@@ -62,7 +62,7 @@ int getDeviceMAC(const int sockfd, const unsigned char *deviceName, unsigned cha
return 1;
}
-int getDeviceIp(const int sockfd, const unsigned char *deviceName, struct sockaddr_in *ip) {
+int getDeviceIp(const int sockfd, const char *deviceName, struct sockaddr_in *ip) {
struct ifconf ifc;
struct ifreq *ifr;
int i,numDevices;
@@ -134,11 +134,10 @@ int getIps(char *name, int nameLen, struct sockaddr_in *ip) {
int_cursor = int_cursor->ifa_next;
}
}
- if (int_cursor == NULL) {
- if (int_addrs != NULL) {
- freeifaddrs(int_addrs);
- int_addrs = NULL;
- }
- return 0;
+ if (int_addrs != NULL) {
+ freeifaddrs(int_addrs);
+ int_addrs = NULL;
}
+ return 0;
+
}
diff --git a/devices.h b/devices.h
index ab83821..d917401 100644
--- a/devices.h
+++ b/devices.h
@@ -1,4 +1,4 @@
-extern int getDeviceIndex(int sockfd, unsigned char *deviceName);
-extern int getDeviceMAC(const int sockfd, const unsigned char *deviceName, unsigned char *mac);
-extern int getDeviceIp(const int sockfd, const unsigned char *deviceName, struct sockaddr_in *ip);
+extern int getDeviceIndex(int sockfd, char *deviceName);
+extern int getDeviceMAC(const int sockfd, const char *deviceName, unsigned char *mac);
+extern int getDeviceIp(const int sockfd, const char *deviceName, struct sockaddr_in *ip);
int getIps(char *name, int nameLen, struct sockaddr_in *ip);
diff --git a/mactelnet.c b/mactelnet.c
index 2c54982..8049ff3 100644
--- a/mactelnet.c
+++ b/mactelnet.c
@@ -60,15 +60,15 @@ int sourceport;
int connect_timeout = CONNECT_TIMEOUT;
unsigned char encryptionkey[128];
-unsigned char username[255];
-unsigned char password[255];
+char username[255];
+char password[255];
/* Protocol data direction */
unsigned char mt_direction_fromserver = 0;
unsigned int sendSocket;
-int sendUDP(struct mt_packet *packet) {
+static int sendUDP(struct mt_packet *packet) {
if (broadcastMode) {
/* Init SendTo struct */
@@ -84,16 +84,15 @@ int sendUDP(struct mt_packet *packet) {
}
-void sendAuthData(unsigned char *username, unsigned char *password) {
+static void sendAuthData(char *username, char *password) {
struct mt_packet data;
- unsigned char *terminal = (unsigned char *)getenv("TERM");
unsigned short width = 0;
unsigned short height = 0;
- unsigned char md5data[100];
+ char *terminal = getenv("TERM");
+ char md5data[100];
unsigned char md5sum[17];
int result;
- int plen;
- int databytes;
+ int plen = 0;
md5_state_t state;
/* Concat string of 0 + password + encryptionkey */
@@ -109,8 +108,7 @@ void sendAuthData(unsigned char *username, unsigned char *password) {
md5sum[0] = 0;
/* Send combined packet to server */
- plen = initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- databytes = plen;
+ initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
plen += addControlPacket(&data, MT_CPTYPE_PASSWORD, md5sum, 17);
plen += addControlPacket(&data, MT_CPTYPE_USERNAME, username, strlen(username));
plen += addControlPacket(&data, MT_CPTYPE_TERM_TYPE, terminal, strlen(terminal));
@@ -120,24 +118,23 @@ void sendAuthData(unsigned char *username, unsigned char *password) {
plen += addControlPacket(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
}
- outcounter += plen - databytes;
+ outcounter += plen;
/* TODO: handle result */
result = sendUDP(&data);
}
-void sig_winch(int sig) {
+static void sig_winch(int sig) {
unsigned short width,height;
struct mt_packet data;
- int result,plen,databytes;
+ int result,plen;
/* terminal height/width has changed, inform server */
if (getTerminalSize(&width, &height) != -1) {
- plen = initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- databytes = plen;
- plen += addControlPacket(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
+ initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ plen = addControlPacket(&data, MT_CPTYPE_TERM_WIDTH, &width, 2);
plen += addControlPacket(&data, MT_CPTYPE_TERM_HEIGHT, &height, 2);
- outcounter += plen - databytes;
+ outcounter += plen;
result = sendUDP(&data);
}
@@ -146,7 +143,7 @@ void sig_winch(int sig) {
signal(SIGWINCH, sig_winch);
}
-void handlePacket(unsigned char *data, int data_len) {
+static void handlePacket(unsigned char *data, int data_len) {
struct mt_mactelnet_hdr pkthdr;
parsePacket(data, &pkthdr);
@@ -159,11 +156,11 @@ void handlePacket(unsigned char *data, int data_len) {
if (pkthdr.ptype == MT_PTYPE_DATA) {
struct mt_packet odata;
struct mt_mactelnet_control_hdr cpkt;
- int plen=0,result=0;
+ int result=0;
int success = 0;
/* Always transmit ACKNOWLEDGE packets in response to DATA packets */
- plen = initPacket(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, pkthdr.counter + (data_len - MT_HEADER_LEN));
+ initPacket(&odata, MT_PTYPE_ACK, srcmac, dstmac, sessionkey, pkthdr.counter + (data_len - MT_HEADER_LEN));
result = sendUDP(&odata);
/* Accept first packet, and all packets greater than incounter, and if counter has
@@ -218,10 +215,10 @@ void handlePacket(unsigned char *data, int data_len) {
/* The server wants to terminate the connection, we have to oblige */
else if (pkthdr.ptype == MT_PTYPE_END) {
struct mt_packet odata;
- int plen=0,result=0;
+ int result=0;
/* Acknowledge the disconnection by sending a END packet in return */
- plen = initPacket(&odata, MT_PTYPE_END, srcmac, dstmac, pkthdr.seskey, 0);
+ initPacket(&odata, MT_PTYPE_END, srcmac, dstmac, pkthdr.seskey, 0);
result = sendUDP(&odata);
fprintf(stderr, "Connection closed.\n");
@@ -233,18 +230,17 @@ void handlePacket(unsigned char *data, int data_len) {
}
}
-int findInterface() {
+static int findInterface() {
struct mt_packet data;
struct sockaddr_in myip;
int success;
- unsigned char devicename[128];
+ char devicename[128];
int testsocket;
fd_set read_fds;
struct timeval timeout;
int optval = 1;
- int i,ii, selected;
- while (success = getIps(devicename, 128, &myip)) {
+ while ((success = getIps(devicename, 128, &myip))) {
char str[INET_ADDRSTRLEN];
/* Skip loopback interfaces */
@@ -309,11 +305,9 @@ int main (int argc, char **argv) {
struct mt_packet data;
struct sockaddr_in si_me;
unsigned char buff[1500];
- int plen = 0;
struct timeval timeout;
int keepalive_counter = 0;
fd_set read_fds;
- unsigned char devicename[30];
unsigned char printHelp = 0, haveUsername = 0, havePassword = 0;
int c;
int optval = 1;
@@ -409,7 +403,7 @@ int main (int argc, char **argv) {
/* Check for identity name or mac address */
{
- unsigned char *p = argv[optind];
+ char *p = argv[optind];
int colons = 0;
while (*p++) {
if (*p == ':') {
@@ -436,7 +430,6 @@ int main (int argc, char **argv) {
}
if (!haveUsername) {
- int ret=0;
printf("Login: ");
scanf("%254s", username);
}
@@ -480,7 +473,7 @@ int main (int argc, char **argv) {
return 1;
}
- if (!findInterface() || recvfrom(insockfd, buff, 1400, 0, 0, 0) < 1) {
+ if (!findInterface() || (result = recvfrom(insockfd, buff, 1400, 0, 0, 0)) < 1) {
fprintf(stderr, "Connection failed.\n");
return 1;
}
@@ -493,9 +486,8 @@ int main (int argc, char **argv) {
* TODO: Should resubmit whenever a PTYPE_DATA packet is sent, and an ACK packet with correct datacounter is received
* or time out the connection, in all other cases.
*/
- plen = initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, 0);
- plen = addControlPacket(&data, MT_CPTYPE_BEGINAUTH, NULL, 0);
- outcounter += plen;
+ initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, 0);
+ outcounter += addControlPacket(&data, MT_CPTYPE_BEGINAUTH, NULL, 0);
/* TODO: handle result of sendUDP */
result = sendUDP(&data);
@@ -526,8 +518,8 @@ int main (int argc, char **argv) {
datalen = read(STDIN_FILENO, &keydata, 512);
- plen = initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
- plen += addControlPacket(&data, MT_CPTYPE_PLAINDATA, &keydata, datalen);
+ initPacket(&data, MT_PTYPE_DATA, srcmac, dstmac, sessionkey, outcounter);
+ addControlPacket(&data, MT_CPTYPE_PLAINDATA, &keydata, datalen);
outcounter += datalen;
result = sendUDP(&data);
}
diff --git a/mactelnetd.c b/mactelnetd.c
index 157c8de..79fa680 100644
--- a/mactelnetd.c
+++ b/mactelnetd.c
@@ -35,6 +35,7 @@
#include <string.h>
#include <linux/if_ether.h>
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <pwd.h>
#include <utmp.h>
#include <syslog.h>
@@ -81,7 +82,7 @@ struct mt_connection {
int pid;
int waitForAck;
- unsigned char username[30];
+ char username[30];
unsigned char srcip[4];
unsigned char srcmac[6];
unsigned short srcport;
@@ -89,17 +90,17 @@ struct mt_connection {
unsigned char enckey[16];
unsigned short terminal_width;
unsigned short terminal_height;
- unsigned char terminal_type[30];
+ char terminal_type[30];
struct mt_connection *next;
};
-void uwtmp_login(struct mt_connection *);
-void uwtmp_logout(struct mt_connection *);
+static void uwtmp_login(struct mt_connection *);
+static void uwtmp_logout(struct mt_connection *);
struct mt_connection *connections_head = NULL;
-void list_addConnection(struct mt_connection *conn) {
+static void list_addConnection(struct mt_connection *conn) {
struct mt_connection *p;
struct mt_connection *last;
if (connections_head == NULL) {
@@ -112,7 +113,7 @@ void list_addConnection(struct mt_connection *conn) {
conn->next = NULL;
}
-void list_removeConnection(struct mt_connection *conn) {
+static void list_removeConnection(struct mt_connection *conn) {
struct mt_connection *p;
struct mt_connection *last;
if (connections_head == NULL)
@@ -143,7 +144,7 @@ void list_removeConnection(struct mt_connection *conn) {
}
}
-struct mt_connection *list_findConnection(unsigned short seskey, unsigned char *srcmac) {
+static struct mt_connection *list_findConnection(unsigned short seskey, unsigned char *srcmac) {
struct mt_connection *p;
if (connections_head == NULL)
@@ -158,11 +159,11 @@ struct mt_connection *list_findConnection(unsigned short seskey, unsigned char *
return NULL;
}
-int sendUDP(const struct mt_connection *conn, const struct mt_packet *data) {
+static int sendUDP(const struct mt_connection *conn, const struct mt_packet *data) {
return sendCustomUDP(sockfd, 2, conn->dstmac, conn->srcmac, &sourceip, sourceport, &destip, conn->srcport, data->data, data->size);
}
-void displayMotd() {
+static void displayMotd() {
FILE *fp;
int c;
@@ -174,7 +175,7 @@ void displayMotd() {
}
}
-void displayNologin() {
+static void displayNologin() {
FILE *fp;
int c;
@@ -186,7 +187,7 @@ void displayNologin() {
}
}
-void uwtmp_login(struct mt_connection *conn) {
+static void uwtmp_login(struct mt_connection *conn) {
struct utmp utent;
pid_t pid;
@@ -213,7 +214,7 @@ void uwtmp_login(struct mt_connection *conn) {
updwtmp(_PATH_WTMP, &utent);
}
-void uwtmp_logout(struct mt_connection *conn) {
+static void uwtmp_logout(struct mt_connection *conn) {
if (conn->pid > 0) {
struct utmp *utentp;
struct utmp utent;
@@ -238,7 +239,7 @@ void uwtmp_logout(struct mt_connection *conn) {
}
}
-void abortConnection(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, char *message) {
+static void abortConnection(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, char *message) {
struct mt_packet pdata;
initPacket(&pdata, MT_PTYPE_DATA, pkthdr->dstaddr, pkthdr->srcaddr, pkthdr->seskey, curconn->outcounter);
@@ -251,12 +252,11 @@ void abortConnection(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkt
sendUDP(curconn, &pdata);
}
-void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr) {
+static void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr) {
struct mt_packet pdata;
unsigned char md5sum[17];
- unsigned char md5data[100];
+ char md5data[100];
struct mt_credentials *user;
- char shouldDoLogin = 0;
char *slavename;
/* Reparse user file before each login */
@@ -390,7 +390,7 @@ void userLogin(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr) {
}
-void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, int data_len) {
+static void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_hdr *pkthdr, int data_len) {
struct mt_mactelnet_control_hdr cpkt;
struct mt_packet pdata;
unsigned char *data = pkthdr->data;
@@ -470,14 +470,14 @@ void handleDataPacket(struct mt_connection *curconn, struct mt_mactelnet_hdr *pk
}
}
-void terminate() {
+static void terminate() {
syslog(LOG_NOTICE, "Exiting.");
exit(0);
}
-void handlePacket(unsigned char *data, int data_len, const struct sockaddr_in *address) {
+static void handlePacket(unsigned char *data, int data_len, const struct sockaddr_in *address) {
struct mt_mactelnet_hdr pkthdr;
- struct mt_connection *curconn;
+ struct mt_connection *curconn = NULL;
struct mt_packet pdata;
parsePacket(data, &pkthdr);
@@ -557,16 +557,18 @@ void handlePacket(unsigned char *data, int data_len, const struct sockaddr_in *a
handleDataPacket(curconn, &pkthdr, data_len);
break;
default:
- syslog(LOG_WARNING, "(%d) Unhandeled packet type: %d", curconn->seskey, pkthdr.ptype);
- initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
- sendUDP(curconn, &pdata);
- }
+ if (curconn) {
+ syslog(LOG_WARNING, "(%d) Unhandeled packet type: %d", curconn->seskey, pkthdr.ptype);
+ initPacket(&pdata, MT_PTYPE_ACK, pkthdr.dstaddr, pkthdr.srcaddr, pkthdr.seskey, pkthdr.counter);
+ sendUDP(curconn, &pdata);
+ }
+ }
if (0 && curconn != NULL) {
printf("Packet, incounter %d, outcounter %d\n", curconn->incounter, curconn->outcounter);
}
}
-void daemonize() {
+static void daemonize() {
int pid,fd;
pid = fork();
@@ -601,7 +603,6 @@ int main (int argc, char **argv) {
int result;
struct sockaddr_in si_me;
struct timeval timeout;
- int keepalive_counter = 0;
struct mt_packet pdata;
fd_set read_fds;
@@ -690,7 +691,7 @@ int main (int argc, char **argv) {
if (FD_ISSET(insockfd, &read_fds)) {
unsigned char buff[1500];
struct sockaddr_in saddress;
- int slen = sizeof(saddress);
+ unsigned int slen = sizeof(saddress);
result = recvfrom(insockfd, buff, 1500, 0, (struct sockaddr *)&saddress, &slen);
handlePacket(buff, result, &saddress);
}
diff --git a/protocol.c b/protocol.c
index ad17910..7202292 100644
--- a/protocol.c
+++ b/protocol.c
@@ -23,6 +23,7 @@
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ether.h>
+#include <time.h>
#include "protocol.h"
#include "config.h"
@@ -30,7 +31,7 @@ unsigned char mt_mactelnet_cpmagic[4] = { 0x56, 0x34, 0x12, 0xff };
unsigned char mt_mactelnet_clienttype[2] = { 0x00, 0x15 };
-int initPacket(struct mt_packet *packet, unsigned char ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter) {
+int initPacket(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter) {
unsigned char *data = packet->data;
/* Packet version */
@@ -72,7 +73,7 @@ int initPacket(struct mt_packet *packet, unsigned char ptype, unsigned char *src
return 22;
}
-int addControlPacket(struct mt_packet *packet, char cptype, void *cpdata, int data_len) {
+int addControlPacket(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len) {
unsigned char *data = packet->data + packet->size;
/* Something is really wrong. Packets should never become over 1500 bytes */
@@ -204,7 +205,7 @@ int parseControlPacket(unsigned char *packetdata, int data_len, struct mt_mactel
}
}
-struct mt_mndp_packet *parseMNDP(const char *data, const int packetLen) {
+struct mt_mndp_packet *parseMNDP(const unsigned char *data, const int packetLen) {
static struct mt_mndp_packet packet;
unsigned short nameLen = 0;
@@ -232,7 +233,7 @@ struct mt_mndp_packet *parseMNDP(const char *data, const int packetLen) {
return &packet;
}
-int queryMNDP(const unsigned char *identity, unsigned char *mac) {
+int queryMNDP(const char *identity, unsigned char *mac) {
int fastlookup = 0;
int sock, length;
int optval = 1;
diff --git a/protocol.h b/protocol.h
index 9068708..72445da 100644
--- a/protocol.h
+++ b/protocol.h
@@ -32,27 +32,31 @@
#define MT_MNDP_LONGTIMEOUT 120
/* Packet type */
-#define MT_PTYPE_SESSIONSTART 0
-#define MT_PTYPE_DATA 1
-#define MT_PTYPE_ACK 2
-#define MT_PTYPE_END 255
+enum mt_ptype {
+ MT_PTYPE_SESSIONSTART,
+ MT_PTYPE_DATA,
+ MT_PTYPE_ACK,
+ MT_PTYPE_END = 255
+};
/* Control packet type */
-#define MT_CPTYPE_BEGINAUTH 0
-#define MT_CPTYPE_ENCRYPTIONKEY 1
-#define MT_CPTYPE_PASSWORD 2
-#define MT_CPTYPE_USERNAME 3
-#define MT_CPTYPE_TERM_TYPE 4
-#define MT_CPTYPE_TERM_WIDTH 5
-#define MT_CPTYPE_TERM_HEIGHT 6
-#define MT_CPTYPE_PACKET_ERROR 7
-#define MT_CPTYPE_END_AUTH 9
-/* Internal CPTYPE, not part of protocol */
-#define MT_CPTYPE_PLAINDATA -1
+enum mt_cptype {
+ MT_CPTYPE_BEGINAUTH,
+ MT_CPTYPE_ENCRYPTIONKEY,
+ MT_CPTYPE_PASSWORD,
+ MT_CPTYPE_USERNAME,
+ MT_CPTYPE_TERM_TYPE,
+ MT_CPTYPE_TERM_WIDTH,
+ MT_CPTYPE_TERM_HEIGHT,
+ MT_CPTYPE_PACKET_ERROR,
+ MT_CPTYPE_END_AUTH = 9,
+ /* Internal CPTYPE, not part of protocol */
+ MT_CPTYPE_PLAINDATA = -1
+};
struct mt_mactelnet_hdr {
unsigned char ver;
- unsigned char ptype;
+ enum mt_ptype ptype;
unsigned int clienttype;
unsigned char srcaddr[6];
unsigned char dstaddr[6];
@@ -62,7 +66,7 @@ struct mt_mactelnet_hdr {
};
struct mt_mactelnet_control_hdr {
- signed char cptype;
+ enum mt_cptype cptype;
unsigned int length;
unsigned char *data;
};
@@ -70,7 +74,7 @@ struct mt_mactelnet_control_hdr {
/* TODO: Add all the other information obtainable from mndp */
struct mt_mndp_packet {
unsigned char address[ETH_ALEN];
- unsigned char identity[MT_MNDP_MAX_IDENTITY_LENGTH];
+ char identity[MT_MNDP_MAX_IDENTITY_LENGTH];
};
struct mt_packet {
@@ -79,14 +83,14 @@ struct mt_packet {
};
/* MacTelnet/Winbox packets */
-extern int initPacket(struct mt_packet *packet, unsigned char ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter);
-extern int addControlPacket(struct mt_packet *packet, char cptype, void *cpdata, int data_len);
+extern int initPacket(struct mt_packet *packet, enum mt_ptype ptype, unsigned char *srcmac, unsigned char *dstmac, unsigned short sessionkey, unsigned int counter);
+extern int addControlPacket(struct mt_packet *packet, enum mt_cptype cptype, void *cpdata, int data_len);
extern void parsePacket(unsigned char *data, struct mt_mactelnet_hdr *pkthdr);
extern int parseControlPacket(unsigned char *data, int data_len, struct mt_mactelnet_control_hdr *cpkthdr);
/* MNDP packets */
-struct mt_mndp_packet *parseMNDP(const char *data, const int packetLen);
-int queryMNDP(const unsigned char *identity, unsigned char *mac);
+struct mt_mndp_packet *parseMNDP(const unsigned char *data, const int packetLen);
+int queryMNDP(const char *identity, unsigned char *mac);
/* Control packet magic header */
extern unsigned char mt_mactelnet_cpmagic[4];
diff --git a/users.c b/users.c
index 6ae39c8..1c0bb7d 100644
--- a/users.c
+++ b/users.c
@@ -27,7 +27,7 @@ struct mt_credentials mt_users[MT_CRED_MAXNUM];
void readUserfile() {
FILE *file = fopen(USERSFILE, "r");
- unsigned char line [BUFSIZ];
+ char line [BUFSIZ];
int i = 0;
if (file == NULL) {
@@ -36,11 +36,11 @@ void readUserfile() {
}
while ( fgets(line, sizeof line, file) ) {
- unsigned char *user;
- unsigned char *password;
+ char *user;
+ char *password;
- user = (unsigned char *)strtok(line, ":");
- password = (unsigned char *)strtok(NULL, "\n");
+ user = strtok(line, ":");
+ password = strtok(NULL, "\n");
if (user == NULL || password == NULL) {
continue;
@@ -60,7 +60,7 @@ void readUserfile() {
fclose(file);
}
-struct mt_credentials* findUser(unsigned char *username) {
+struct mt_credentials* findUser(char *username) {
int i = 0;
while (i < MT_CRED_MAXNUM && mt_users[i].username[0] != 0) {
diff --git a/users.h b/users.h
index 5f2bf56..a478434 100644
--- a/users.h
+++ b/users.h
@@ -5,13 +5,13 @@
#define MT_CRED_MAXNUM 128
struct mt_credentials {
- unsigned char username[MT_CRED_LEN];
- unsigned char password[MT_CRED_LEN];
+ char username[MT_CRED_LEN];
+ char password[MT_CRED_LEN];
};
extern struct mt_credentials mt_users[MT_CRED_MAXNUM];
extern void readUserfile();
-struct mt_credentials* findUser(unsigned char *username);
+struct mt_credentials* findUser(char *username);
#endif