summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-28 15:28:49 (UTC)
committer mjm <mjm>2002-12-28 15:28:49 (UTC)
commit94ac3da47b0b36316cff680d319dab23c9339308 (patch) (side-by-side diff)
tree5161a4da84fb05c53fd5225be5674ab75087ff3f
parent0ab4ac99bead80d8af18988045748fd2b3dd3a15 (diff)
downloadopie-94ac3da47b0b36316cff680d319dab23c9339308.zip
opie-94ac3da47b0b36316cff680d319dab23c9339308.tar.gz
opie-94ac3da47b0b36316cff680d319dab23c9339308.tar.bz2
cleanup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc46
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc6
3 files changed, 23 insertions, 31 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
index 5317f52..ae6d406 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -34,98 +34,90 @@ int get_field(const char *buffer, char *out)
/* Copy buffer to out pointer */
memset(out, 0, atoi(len) + 1);
memcpy(out, buffer + 3, atoi(len));
/* Return length of whole field (including 3 byte length) */
return (atoi(len) + 3);
}
/* Send found network to UI */
int send_network_found (const char *guihost, int guiport, void *structure)
{
wl_network_t *ptr;
- char buffer[2048];
- char temp[128];
- int retval=0, len=0;
-
- memset(temp, 0, sizeof(temp));
+ char buffer[2048], temp[5];
+ int len = 0;
ptr = (wl_network_t *)structure;
/* Type = Found new net (without length field) */
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%.2d", NETFOUND);
memcpy(buffer, temp, 2);
len += 2;
/* Set Net-type */
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%d", ptr->net_type);
- retval = add_field(buffer + len, temp, 1);
- len += retval;
+ len += add_field(buffer + len, temp, 1);
/* Set channel */
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
- retval = add_field(buffer + len, temp, 2);
- len += retval;
+ len += add_field(buffer + len, temp, 2);
/* Set WEP y/n */
memset(temp, 0, sizeof(temp));
snprintf(temp, sizeof(temp), "%d", ptr->wep);
- retval = add_field(buffer + len, temp, 1);
- len += retval;
+ len += add_field(buffer + len, temp, 1);
/* Set Mac */
- retval = add_field(buffer + len, ptr->mac, 17);
- len += retval;
+ len += add_field(buffer + len, ptr->mac, 17);
/* Set ssid */
- retval = add_field(buffer + len, ptr->bssid, ptr->ssid_len);
+ if(len + ptr->ssid_len < sizeof(buffer) - 1)
+ len += add_field(buffer + len, ptr->bssid, ptr->ssid_len);
+ else
+ len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1);
/* Send prepared buffer to UI */
#ifdef DEBUG
wl_loginfo("Sending network to UI: '%s'", buffer);
#endif
return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
}
/* Fill buffer into structur */
int get_network_found (void *structure, const char *buffer)
{
wl_network_t *ptr;
- char temp[512];
- int retval=0, len=0;
+ char temp[5];
+ int len = 0;
ptr = (wl_network_t *)structure;
- /* packet type already determined */
+ /* packet type already determined, skip check */
len += 2;
- /* Get net type */
+ /* Get net type (accesspoint || ad-hoc || ...) */
memset(temp, 0, sizeof(temp));
- retval = get_field(buffer + len, temp);
- len += retval;
+ len += get_field(buffer + len, temp);
ptr->net_type = atoi(temp);
/* Get channel */
memset(temp, 0, sizeof(temp));
- retval = get_field(buffer + len, temp);
- len += retval;
+ len += get_field(buffer + len, temp);
ptr->channel = atoi(temp);
/* Set WEP y/n */
memset(temp, 0, sizeof(temp));
- retval = get_field(buffer + len, temp);
- len += retval;
+ len += get_field(buffer + len, temp);
ptr->wep = atoi(temp);
/* Set MAC address */
- retval = get_field(buffer + len, ptr->mac);
- len += retval;
+ len += get_field(buffer + len, ptr->mac);
/* Set BSSID */
- retval = get_field(buffer + len, ptr->bssid);
+ len += get_field(buffer + len, ptr->bssid);
return 1;
}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
index f755589..a196091 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
@@ -13,16 +13,16 @@
#define STARTSNIFF 98
#define STOPSNIFF 99
int send_network_found (const char *, int, void *);
int get_network_found (void *, const char *);
typedef struct {
int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */
int ssid_len; /* Length of SSID */
int channel; /* Channel */
int wep; /* 1 = WEP enabled ; 0 = disabled */
char mac[64]; /* MAC address of Accesspoint */
- char bssid[128]; /* BSSID of Accesspoint */
+ char bssid[128]; /* BSSID of Net */
} wl_network_t;
#endif /* WLPROTO_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
index 4942fba..db6b7b8 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
@@ -4,25 +4,25 @@
* $Id$
*/
#include "wl_sock.hh"
#include "wl_log.hh"
/* Setup UDP Socket for incoming commands */
int wl_setupsock(const char *host, int port)
{
struct sockaddr_in saddr;
int sock;
- if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
wl_logerr("Cannot set up socket: %s", strerror(errno));
return -1;
}
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = PF_INET;
saddr.sin_port = htons(port);
saddr.sin_addr.s_addr = inet_addr(host);
if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0)
{
@@ -44,48 +44,48 @@ int wl_send(const char *host, int port, const char *string, ...)
/* Generate string */
memset(buffer, 0, sizeof(buffer));
va_start(ap, string);
vsnprintf(buffer, sizeof(buffer)-1, string, ap);
va_end(ap);
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
saddr.sin_addr.s_addr = inet_addr(host);
/* Setup socket */
- if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
wl_logerr("Cannot set up socket: %s", strerror(errno));
return 0;
}
if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0)
{
wl_logerr("Cannot write to socket: %s", strerror(errno));
close(sock);
return 0;
}
if(close(sock) < 0)
wl_logerr("Cannot close socket: %s", strerror(errno));
return 1;
}
/* Check for new messages on commsock */
int wl_recv(int *sock, char *out, int maxlen)
{
struct sockaddr_in *cliaddr;
- socklen_t len=sizeof(struct sockaddr);
+ socklen_t len = sizeof(struct sockaddr);
char retval[3];
memset(out, 0, maxlen);
if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0)
return -1;
/* Get packet type and return it */
memset(retval, 0, sizeof(retval));
memcpy(retval, out, 2);
return atoi(retval);
}