From: Jakob Haufe Date: Sat, 6 Apr 2013 10:16:40 +0000 (+0200) Subject: A bunch of fixes for various compiler warnings X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;ds=sidebyside;p=gsconf A bunch of fixes for various compiler warnings --- diff --git a/Makefile b/Makefile index c548187..0fd282d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc -CFLAGS=-I. -DEPS = +CFLAGS=-Wall -std=c99 +DEPS = OBJ = socket.o main.o gs105e.o shell.o shell_ip.o shell_vlan.o shell_sys.o shell_port.o %.o: %.c $(DEPS) diff --git a/gs105e.c b/gs105e.c index c594e86..381f0b1 100644 --- a/gs105e.c +++ b/gs105e.c @@ -5,8 +5,8 @@ #include #include -unsigned char * gs105e_queryData; -unsigned int gsDataLen; +char * gs105e_queryData; +int gsDataLen; struct vlan * getVlanSetting(unsigned int vlanId) { struct vlan * _vlan = settings.vlans; @@ -81,7 +81,7 @@ void makeHeader(unsigned int queryType) { - gs105e_queryData = (unsigned char * )realloc(gs105e_queryData, sizeof(char) * 32); + gs105e_queryData = realloc(gs105e_queryData, sizeof(char) * 32); gsDataLen = 32; @@ -123,7 +123,7 @@ void gs105e_query (void) { emptyBuffer(); gs105e_queryData[23] = newPacketId(); - if (gs105e_queryData[gsDataLen - 4] != 0xFF | gs105e_queryData[gsDataLen - 3] != 0xFF | gs105e_queryData[gsDataLen - 2] != 0x00 | gs105e_queryData[gsDataLen - 1] != 0x00) + if ((gs105e_queryData[gsDataLen - 4] != 0xFF) | (gs105e_queryData[gsDataLen - 3] != 0xFF) | (gs105e_queryData[gsDataLen - 2] != 0x00) | (gs105e_queryData[gsDataLen - 1] != 0x00)) addData("\xFF\xFF\x00\x00", 4); sendBroadcast(gs105e_queryData, gsDataLen); @@ -251,7 +251,7 @@ int gs105e__receive(void) { // printf("Received No or Invalid Packet\n"); return -1; } - if (memcmp(&data[8], myMac, 6) | data[0] != 0x01 | (!(data[1] == 0x02 | data[1] == 0x04))) { + if (memcmp(&data[8], myMac, 6) | (data[0] != 0x01) | (!((data[1] == 0x02) | (data[1] == 0x04)))) { return -1; } @@ -291,7 +291,7 @@ int gs105e_actRecv(void) { // printf("Received No or Invalid Packet\n"); return -1; } - if (memcmp(&data[8], myMac, 6) | data[0] != 0x01 | (!(data[1] == 0x02 | data[1] == 0x04))) { + if (memcmp(&data[8], myMac, 6) | (data[0] != 0x01) | (!((data[1] == 0x02) | (data[1] == 0x04)))) { gs105e_actRecv(); return -1; } @@ -350,7 +350,7 @@ int gs105e_delVlan(int vlanId) { return gs105e_act(); } -int gs105e_restart(int vlanId) { +int gs105e_restart(void) { makeHeader(QR_EXEC); char data[1] = {1}; diff --git a/gs105e.h b/gs105e.h index f856887..7723b3a 100644 --- a/gs105e.h +++ b/gs105e.h @@ -125,10 +125,18 @@ void gs105e_init(void) ; void makeHeader(unsigned int queryType); void gs105e_query (void); +void gs105e_queryAll(void); int gs105e_addVlan(int vlanId) ; int gs105e_delVlan(int vlanId) ; +int gs105e_setVlanMembers(unsigned int vlanId, unsigned int members, unsigned int tagged); +int gs105e_vlanEnable(); int gs105e_discover(void); +int gs105e_restart(void); int gs105e_setName(char * data); +int gs105e_dhcpSettings(int action); + +int gs105e_cableDiagnostics(int port); +int gs105e_mirrorPorts(int outputPort, int mirrorMask); #endif diff --git a/main.c b/main.c index 3150ae7..582e47c 100644 --- a/main.c +++ b/main.c @@ -12,15 +12,13 @@ int shellHandler = 0; int main () { - int n; - init_socket(); myMac = get_mac("eth0"); gs105e_init(); - shell(); + return shell(); } diff --git a/shell.c b/shell.c index 922442e..8f32679 100644 --- a/shell.c +++ b/shell.c @@ -67,7 +67,6 @@ void printError(int errCode) { void shell_set(char ** argv, int elem) { - int n; if (strncmp(argv[1], "name", 4) == 0) { if (elem != 3) { printf("set name [name]\n"); diff --git a/shell.h b/shell.h index 111487b..c243db6 100644 --- a/shell.h +++ b/shell.h @@ -1,12 +1,15 @@ #ifndef SHELL_H #define SHELL_H +#define _BSD_SOURCE + #include #include "socket.h" #include "gs105e.h" #include #include +#include #include @@ -19,5 +22,6 @@ void printError(int errCode); void printIp(char * data); void shell_port(char ** argv, int elem); void shell_sys(char ** argv, int elem); +void shell_vlan(char **argv, int elem); #endif diff --git a/shell_ip.c b/shell_ip.c index df50cdc..cc4b1b8 100644 --- a/shell_ip.c +++ b/shell_ip.c @@ -1,7 +1,6 @@ #include "shell.h" void shell_ip(char ** argv, int elem) { - int n; if (elem == 1) { printf(" ip [show|dhcp|set] \n"); return; diff --git a/shell_port.c b/shell_port.c index 2dbf94e..9ac059d 100644 --- a/shell_port.c +++ b/shell_port.c @@ -11,7 +11,7 @@ void shell_port(char ** argv, int elem) { if (strncmp(argv[1], "show", 4) == 0) { printf("Port\tSpeed\t\tBytes In\t\tBytes Out\n"); for (n = 0; n< 5; n++) { - printf("%i\t%s\t% 8lu\t\t% 8lu\n", n, + printf("%i\t%s\t%8lu\t\t%8lu\n", n, (settings.portStatistics[n].state == 0x05 ? "1000 Mbit/s" : (settings.portStatistics[n].state == 0x04 ? "100 Mbit/s" : (settings.portStatistics[n].state == 0x03 ? "10 Mbit/s": (settings.portStatistics[n].state == 0x00 ? "No Cable": "???")))), settings.portStatistics[n].bytesIn, settings.portStatistics[n].bytesOut @@ -25,7 +25,7 @@ void shell_port(char ** argv, int elem) { n = atoi(argv[2]); - if (n < 1 | n > 5) { + if ((n < 1) | (n > 5)) { printf("Invalid Port\n"); return; } @@ -66,7 +66,7 @@ void shell_port(char ** argv, int elem) { n = atoi(argv[2]); - if (n < 1 | n > 5) { + if ((n < 1) | (n > 5)) { printf("Invalid Port %i\n", n); return; } @@ -75,7 +75,7 @@ void shell_port(char ** argv, int elem) { for (m = 3; m < elem; m++) { i = atoi(argv[m]); - if (i < 1 | i > 5) { + if ((i < 1) | (i > 5)) { printf("Invalid Port %i\n", i); return; } diff --git a/shell_sys.c b/shell_sys.c index d8520d5..49f1443 100644 --- a/shell_sys.c +++ b/shell_sys.c @@ -3,7 +3,6 @@ void shell_sys(char ** argv, int elem) { - int n, i, m, o; if (elem == 1) { printf(" sys [show|name|password|restart] \n"); diff --git a/shell_vlan.c b/shell_vlan.c index 661eb3d..abe0382 100644 --- a/shell_vlan.c +++ b/shell_vlan.c @@ -32,7 +32,7 @@ void shell_vlan(char ** argv, int elem) { while (vl != NULL) { printf("%u\t", vl->id); for (n = 0; n < 5; n++) - printf("%s\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? "\033[93mT\033[0m" : "\033[92mU\033[0m") : "\033[91m-\033[0m", (unsigned int) vl->members); + printf("%s\t", vl->members & (0x80 >> n) ? (vl->tag & (0x80 >> n) ? "\033[93mT\033[0m" : "\033[92mU\033[0m") : "\033[91m-\033[0m" /*, (unsigned int) vl->members*/); printf("\n"); vl = vl->next; } @@ -96,7 +96,7 @@ void shell_vlan(char ** argv, int elem) { m = atoi(argv[3]); - if (m < 1 | m > 5) { + if ((m < 1) | (m > 5)) { printf("Invalid Port ID\n"); return; } @@ -134,7 +134,7 @@ void shell_vlan(char ** argv, int elem) { m = atoi(argv[3]); - if (m < 1 | m > 5) { + if ((m < 1) | (m > 5)) { printf("Invalid Port ID\n"); return; } diff --git a/socket.c b/socket.c index b8a46ec..8b3043c 100644 --- a/socket.c +++ b/socket.c @@ -1,3 +1,5 @@ +#define _BSD_SOURCE + #include #include #include @@ -79,8 +81,8 @@ int sendBroadcast(char * data, unsigned int len) { int recvBroadcast(char * data) { - struct sockaddr_in sa_in; - int sa_len = sizeof(sa_in); + struct sockaddr sa_in; + socklen_t sa_len = sizeof(sa_in); struct timeval tout; tout.tv_sec = 0; tout.tv_usec = 500000; @@ -90,7 +92,7 @@ int recvBroadcast(char * data) { int s = select(sock + 1, &fds, NULL, NULL, &tout); if (s <= 0) return -1; - return recvfrom(sock, data, PACKET_BUFFER, 0,(struct sockaddr * )&sa_in, &sa_len); + return recvfrom(sock, data, PACKET_BUFFER, 0, &sa_in, &sa_len); } @@ -98,7 +100,7 @@ int recvBroadcast(char * data) { int recvBroadcast_tout(char * data) { struct sockaddr_in sa_in; - int sa_len = sizeof(sa_in); + socklen_t sa_len = sizeof(sa_in); struct timeval tout; tout.tv_sec = 5; tout.tv_usec = 0; diff --git a/socket.h b/socket.h index cdbccea..ead9c6a 100644 --- a/socket.h +++ b/socket.h @@ -3,4 +3,8 @@ unsigned char * get_mac(const char *intf); unsigned char * myMac; +int sendBroadcast(char *data, unsigned int len); +int recvBroadcast(char * data); +int recvBroadcast_tout(char * data); + #define PACKET_BUFFER 2500