5 files changed, 45 insertions, 41 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index e516177..6e512c4 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |||
@@ -1,26 +1,30 @@ | |||
1 | /* | 1 | /* |
2 | * rfmon mode sniffer | 2 | * rfmon mode sniffer |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "sniff.hh" | 7 | #include "sniff.hh" |
8 | #include "ieee802_11.hh" | 8 | #include "ieee802_11.hh" |
9 | #include "extract.hh" | 9 | #include "extract.hh" |
10 | #include "wl_log.hh" | 10 | #include "wl_log.hh" |
11 | #include "wl_types.hh" | ||
11 | #include "wl_proto.hh" | 12 | #include "wl_proto.hh" |
12 | 13 | ||
13 | /* Main function, checks packets */ | 14 | /* Main function, checks packets */ |
14 | void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) | 15 | void process_packets(const struct pcap_pkthdr *pkthdr, |
16 | const unsigned char *packet, | ||
17 | char *guihost, | ||
18 | int guiport) | ||
15 | { | 19 | { |
16 | unsigned int caplen = pkthdr->caplen; | 20 | unsigned int caplen = pkthdr->caplen; |
17 | unsigned int length = pkthdr->len; | 21 | unsigned int length = pkthdr->len; |
18 | u_int16_t fc; | 22 | u_int16_t fc; |
19 | unsigned int HEADER_LENGTH; | 23 | unsigned int HEADER_LENGTH; |
20 | 24 | ||
21 | /* pinfo holds all interresting information for us */ | 25 | /* pinfo holds all interresting information for us */ |
22 | struct packetinfo pinfo; | 26 | struct packetinfo pinfo; |
23 | struct packetinfo *pinfoptr; | 27 | struct packetinfo *pinfoptr; |
24 | 28 | ||
25 | /* wl_network_t will finally be set and send to the ui */ | 29 | /* wl_network_t will finally be set and send to the ui */ |
26 | wl_network_t wl_net; | 30 | wl_network_t wl_net; |
@@ -86,43 +90,42 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack | |||
86 | pinfoptr->isvalid = 0; | 90 | pinfoptr->isvalid = 0; |
87 | return; | 91 | return; |
88 | } | 92 | } |
89 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | 93 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) |
90 | { | 94 | { |
91 | /* Only channels between 1 and 14 are possible | 95 | /* Only channels between 1 and 14 are possible |
92 | others must be noise packets */ | 96 | others must be noise packets */ |
93 | pinfoptr->isvalid = 0; | 97 | pinfoptr->isvalid = 0; |
94 | return; | 98 | return; |
95 | } | 99 | } |
96 | 100 | ||
97 | /* Here should be the infos to the gui issued */ | 101 | /* Here should be the infos to the gui issued */ |
98 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | 102 | if (pinfoptr->cap_ESS == 1 && pinfoptr->cap_IBSS ==0) |
99 | { | 103 | { |
100 | wl_loginfo("Found an access point"); | 104 | wl_loginfo("Found an access point"); |
101 | wl_net.net_type=1; | 105 | wl_net.net_type=1; |
102 | } | 106 | } |
103 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) | 107 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) |
104 | { | 108 | { |
105 | wl_loginfo("Found an ad-hoc network"); | 109 | wl_loginfo("Found an ad-hoc network"); |
106 | wl_net.net_type=2; | 110 | wl_net.net_type=2; |
107 | } | 111 | } |
108 | |||
109 | memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); | ||
110 | 112 | ||
111 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 113 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
112 | wl_loginfo("Net is a non-broadcasting network"); | 114 | wl_loginfo("Net is a non-broadcasting network"); |
113 | else | 115 | else |
114 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 116 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
115 | 117 | ||
116 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 118 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
119 | memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); | ||
117 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); | 120 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); |
118 | 121 | ||
119 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); | 122 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); |
120 | wl_net.ssid_len=pinfoptr->ssid_len; | 123 | wl_net.ssid_len=pinfoptr->ssid_len; |
121 | 124 | ||
122 | wl_loginfo("Channel is: %d", pinfoptr->channel); | 125 | wl_loginfo("Channel is: %d", pinfoptr->channel); |
123 | wl_net.channel=pinfoptr->channel; | 126 | wl_net.channel=pinfoptr->channel; |
124 | wl_net.wep=pinfoptr->cap_WEP; | 127 | wl_net.wep=pinfoptr->cap_WEP; |
125 | 128 | ||
126 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); | 129 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); |
127 | memset(wl_net.mac, 0, sizeof(wl_net.mac)); | 130 | memset(wl_net.mac, 0, sizeof(wl_net.mac)); |
128 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1); | 131 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1); |
@@ -228,59 +231,66 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
228 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 231 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
229 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 232 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
230 | 233 | ||
231 | /* Gets the tagged elements out of the packets */ | 234 | /* Gets the tagged elements out of the packets */ |
232 | while (offset + 1 < ppinfo->pktlen) | 235 | while (offset + 1 < ppinfo->pktlen) |
233 | { | 236 | { |
234 | switch (*(p + offset)) | 237 | switch (*(p + offset)) |
235 | { | 238 | { |
236 | case E_SSID: | 239 | case E_SSID: |
237 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 240 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
238 | if (pbody.ssid.length > 0) | 241 | if (pbody.ssid.length > 0) |
239 | { | 242 | { |
240 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 243 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); |
244 | offset += pbody.ssid.length; | ||
241 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 245 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
242 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | 246 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
243 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); | 247 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); |
244 | else | 248 | else |
245 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); | 249 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); |
246 | ppinfo->ssid_len = pbody.ssid.length; | 250 | ppinfo->ssid_len = pbody.ssid.length; |
247 | } | 251 | } |
248 | break; | 252 | break; |
249 | 253 | ||
250 | case E_CHALLENGE: | 254 | case E_CHALLENGE: |
251 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 255 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
252 | if (pbody.challenge.length > 0) | 256 | if (pbody.challenge.length > 0) |
253 | { | 257 | { |
254 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 258 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); |
259 | offset += pbody.challenge.length; | ||
255 | pbody.challenge.text[pbody.challenge.length]='\0'; | 260 | pbody.challenge.text[pbody.challenge.length]='\0'; |
256 | } | 261 | } |
257 | break; | 262 | break; |
258 | case E_RATES: | 263 | case E_RATES: |
259 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 264 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
260 | if (pbody.rates.length > 0) | 265 | if (pbody.rates.length > 0) |
261 | { | 266 | { |
262 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | 267 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); |
268 | offset += pbody.rates.length; | ||
263 | } | 269 | } |
264 | break; | 270 | break; |
265 | case E_DS: | 271 | case E_DS: |
266 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | 272 | memcpy(&(pbody.ds),p+offset,3); |
273 | offset +=3; | ||
267 | ppinfo->channel = pbody.ds.channel; | 274 | ppinfo->channel = pbody.ds.channel; |
268 | break; | 275 | break; |
269 | case E_CF: | 276 | case E_CF: |
270 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 277 | memcpy(&(pbody.cf),p+offset,8); |
278 | offset +=8; | ||
271 | break; | 279 | break; |
272 | case E_TIM: | 280 | case E_TIM: |
273 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 281 | memcpy(&(pbody.tim),p+offset,2); |
274 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 282 | offset +=2; |
283 | memcpy(&(pbody.tim.count),p+offset,3); | ||
284 | offset +=3; | ||
275 | if ((pbody.tim.length -3) > 0) | 285 | if ((pbody.tim.length -3) > 0) |
276 | { | 286 | { |
277 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 287 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
278 | offset += pbody.tim.length -3; | 288 | offset += pbody.tim.length -3; |
279 | } | 289 | } |
280 | break; | 290 | break; |
281 | default: | 291 | default: |
282 | 292 | ||
283 | offset+= *(p+offset+1) + 2; | 293 | offset+= *(p+offset+1) + 2; |
284 | break; | 294 | break; |
285 | } /* end of switch*/ | 295 | } /* end of switch*/ |
286 | } /* end of for loop */ | 296 | } /* end of for loop */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc index 0630d04..664ba92 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |||
@@ -1,18 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | * Communication protocol | 2 | * Communication protocol |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "wl_types.hh" | ||
7 | #include "wl_proto.hh" | 8 | #include "wl_proto.hh" |
8 | #include "wl_log.hh" | 9 | #include "wl_log.hh" |
9 | #include "wl_sock.hh" | 10 | #include "wl_sock.hh" |
10 | 11 | ||
11 | /* Adds a field to the buffer */ | 12 | /* Adds a field to the buffer */ |
12 | int add_field(char *buffer, const char *string, int len) | 13 | int add_field(char *buffer, const char *string, int len) |
13 | { | 14 | { |
14 | char newlen[5]; | 15 | char newlen[5]; |
15 | 16 | ||
16 | /* 3 Byte = Length */ | 17 | /* 3 Byte = Length */ |
17 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); | 18 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); |
18 | memcpy(buffer, newlen, 3); | 19 | memcpy(buffer, newlen, 3); |
@@ -25,45 +26,45 @@ int add_field(char *buffer, const char *string, int len) | |||
25 | } | 26 | } |
26 | 27 | ||
27 | int get_field(const char *buffer, char *out, int maxlen) | 28 | int get_field(const char *buffer, char *out, int maxlen) |
28 | { | 29 | { |
29 | char len[5]; | 30 | char len[5]; |
30 | 31 | ||
31 | /* Get length of value */ | 32 | /* Get length of value */ |
32 | memcpy(len, buffer, 3); | 33 | memcpy(len, buffer, 3); |
33 | 34 | ||
34 | /* Copy buffer to out pointer */ | 35 | /* Copy buffer to out pointer */ |
35 | memset(out, 0, maxlen); | 36 | memset(out, 0, maxlen); |
36 | 37 | ||
37 | if(atoi(len)-3 > maxlen -1) | 38 | if(atoi(len) > maxlen -1) |
38 | memcpy(out, buffer + 3, maxlen - 1); | 39 | memcpy(out, buffer + 3, maxlen - 1); |
39 | else | 40 | else |
40 | memcpy(out, buffer + 3, atoi(len)); | 41 | memcpy(out, buffer + 3, atoi(len)); |
41 | 42 | ||
42 | /* Return length of whole field (including 3 byte length) */ | 43 | /* Return length of whole field (including 3 byte length) */ |
43 | return (atoi(len) + 3); | 44 | return (atoi(len) + 3); |
44 | } | 45 | } |
45 | 46 | ||
46 | /* Send found network to UI */ | 47 | /* Send found network to UI */ |
47 | int send_network_found (const char *guihost, int guiport, void *structure) | 48 | int send_network_found (const char *guihost, int guiport, void *structure) |
48 | { | 49 | { |
49 | wl_network_t *ptr; | 50 | wl_network_t *ptr; |
50 | char buffer[2048], temp[5]; | 51 | char buffer[2048], temp[5]; |
51 | unsigned int len = 0; | 52 | unsigned int len = 0; |
52 | 53 | ||
53 | ptr = (wl_network_t *)structure; | 54 | ptr = (wl_network_t *)structure; |
54 | 55 | ||
55 | /* Type = Found new net (without length field) */ | 56 | /* Type = Found new net (without length field) */ |
56 | memset(temp, 0, sizeof(temp)); | 57 | memset(temp, 0, sizeof(temp)); |
57 | snprintf(temp, sizeof(temp), "%.2d", NETFOUND); | 58 | snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); |
58 | memcpy(buffer, temp, 2); | 59 | memcpy(buffer, temp, 2); |
59 | len += 2; | 60 | len += 2; |
60 | 61 | ||
61 | /* Set Net-type */ | 62 | /* Set Net-type */ |
62 | memset(temp, 0, sizeof(temp)); | 63 | memset(temp, 0, sizeof(temp)); |
63 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); | 64 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); |
64 | len += add_field(buffer + len, temp, 1); | 65 | len += add_field(buffer + len, temp, 1); |
65 | 66 | ||
66 | /* Set channel */ | 67 | /* Set channel */ |
67 | memset(temp, 0, sizeof(temp)); | 68 | memset(temp, 0, sizeof(temp)); |
68 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); | 69 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); |
69 | len += add_field(buffer + len, temp, 2); | 70 | len += add_field(buffer + len, temp, 2); |
@@ -89,25 +90,25 @@ int send_network_found (const char *guihost, int guiport, void *structure) | |||
89 | 90 | ||
90 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | 91 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); |
91 | } | 92 | } |
92 | 93 | ||
93 | /* Fill buffer into structur */ | 94 | /* Fill buffer into structur */ |
94 | int get_network_found (void *structure, const char *buffer) | 95 | int get_network_found (void *structure, const char *buffer) |
95 | { | 96 | { |
96 | wl_network_t *ptr; | 97 | wl_network_t *ptr; |
97 | char temp[5]; | 98 | char temp[5]; |
98 | unsigned int len = 0; | 99 | unsigned int len = 0; |
99 | 100 | ||
100 | ptr = (wl_network_t *)structure; | 101 | ptr = (wl_network_t *)structure; |
101 | 102 | ||
102 | /* packet type already determined, skip check */ | 103 | /* packet type already determined, skip check */ |
103 | len += 2; | 104 | len += 2; |
104 | 105 | ||
105 | /* Get net type (accesspoint || ad-hoc || ...) */ | 106 | /* Get net type (accesspoint || ad-hoc || ...) */ |
106 | memset(temp, 0, sizeof(temp)); | 107 | memset(temp, 0, sizeof(temp)); |
107 | len += get_field(buffer + len, temp, sizeof(temp)); | 108 | len += get_field(buffer + len, temp, sizeof(temp)); |
108 | ptr->net_type = atoi(temp); | 109 | ptr->net_type = atoi(temp); |
109 | 110 | ||
110 | /* Get channel */ | 111 | /* Get channel */ |
111 | memset(temp, 0, sizeof(temp)); | 112 | memset(temp, 0, sizeof(temp)); |
112 | len += get_field(buffer + len, temp, sizeof(temp)); | 113 | len += get_field(buffer + len, temp, sizeof(temp)); |
113 | ptr->channel = atoi(temp); | 114 | ptr->channel = atoi(temp); |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh index f645f58..46ef8e5 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh | |||
@@ -9,22 +9,13 @@ | |||
9 | 9 | ||
10 | /* Type definitions, to be continued */ | 10 | /* Type definitions, to be continued */ |
11 | #define NETFOUND 01 | 11 | #define NETFOUND 01 |
12 | #define NETLOST 02 | 12 | #define NETLOST 02 |
13 | #define STARTSNIFF 98 | 13 | #define STARTSNIFF 98 |
14 | #define STOPSNIFF 99 | 14 | #define STOPSNIFF 99 |
15 | 15 | ||
16 | int add_field(char *, const char *, int); | 16 | int add_field(char *, const char *, int); |
17 | int get_field(const char *, char *, int); | 17 | int get_field(const char *, char *, int); |
18 | int send_network_found (const char *, int, void *); | 18 | int send_network_found (const char *, int, void *); |
19 | int get_network_found (void *, const char *); | 19 | int get_network_found (void *, const char *); |
20 | 20 | ||
21 | typedef struct { | ||
22 | int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ | ||
23 | int ssid_len; /* Length of SSID */ | ||
24 | int channel; /* Channel */ | ||
25 | int wep; /* 1 = WEP enabled ; 0 = disabled */ | ||
26 | char mac[64]; /* MAC address of Accesspoint */ | ||
27 | char bssid[128]; /* BSSID of Net */ | ||
28 | } wl_network_t; | ||
29 | |||
30 | #endif /* WLPROTO_HH */ | 21 | #endif /* WLPROTO_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc index db6b7b8..6e26cb8 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc | |||
@@ -1,38 +1,37 @@ | |||
1 | /* | 1 | /* |
2 | * Socket operations for wellenreiter | 2 | * Socket operations for wellenreiter |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "wl_sock.hh" | 7 | #include "wl_sock.hh" |
8 | #include "wl_log.hh" | 8 | #include "wl_log.hh" |
9 | 9 | ||
10 | /* Setup UDP Socket for incoming commands */ | 10 | /* Setup UDP Socket for incoming commands */ |
11 | int wl_setupsock(const char *host, int port) | 11 | int wl_setupsock(const char *host, int port, struct sockaddr_in saddr) |
12 | { | 12 | { |
13 | struct sockaddr_in saddr; | ||
14 | int sock; | 13 | int sock; |
15 | 14 | ||
16 | if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) | 15 | if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
17 | { | 16 | { |
18 | wl_logerr("Cannot set up socket: %s", strerror(errno)); | 17 | wl_logerr("Cannot set up socket: %s", strerror(errno)); |
19 | return -1; | 18 | return -1; |
20 | } | 19 | } |
21 | 20 | ||
22 | memset(&saddr, 0, sizeof(saddr)); | 21 | memset(&saddr, 0, sizeof(saddr)); |
23 | saddr.sin_family = PF_INET; | 22 | saddr.sin_family = PF_INET; |
24 | saddr.sin_port = htons(port); | 23 | saddr.sin_port = htons(port); |
25 | saddr.sin_addr.s_addr = inet_addr(host); | 24 | saddr.sin_addr.s_addr = inet_addr(host); |
26 | 25 | ||
27 | if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) | 26 | if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) |
28 | { | 27 | { |
29 | wl_logerr("Cannot bind socket: %s", strerror(errno)); | 28 | wl_logerr("Cannot bind socket: %s", strerror(errno)); |
30 | close(sock); | 29 | close(sock); |
31 | return -1; | 30 | return -1; |
32 | } | 31 | } |
33 | 32 | ||
34 | return sock; | 33 | return sock; |
35 | } | 34 | } |
36 | 35 | ||
37 | /* Send a string to commsock */ | 36 | /* Send a string to commsock */ |
38 | int wl_send(const char *host, int port, const char *string, ...) | 37 | int wl_send(const char *host, int port, const char *string, ...) |
@@ -64,28 +63,30 @@ int wl_send(const char *host, int port, const char *string, ...) | |||
64 | wl_logerr("Cannot write to socket: %s", strerror(errno)); | 63 | wl_logerr("Cannot write to socket: %s", strerror(errno)); |
65 | close(sock); | 64 | close(sock); |
66 | return 0; | 65 | return 0; |
67 | } | 66 | } |
68 | 67 | ||
69 | if(close(sock) < 0) | 68 | if(close(sock) < 0) |
70 | wl_logerr("Cannot close socket: %s", strerror(errno)); | 69 | wl_logerr("Cannot close socket: %s", strerror(errno)); |
71 | 70 | ||
72 | return 1; | 71 | return 1; |
73 | } | 72 | } |
74 | 73 | ||
75 | /* Check for new messages on commsock */ | 74 | /* Check for new messages on commsock */ |
76 | int wl_recv(int *sock, char *out, int maxlen) | 75 | int wl_recv(int *sock, struct sockaddr_in cliaddr, char *out, int maxlen) |
77 | { | 76 | { |
78 | struct sockaddr_in *cliaddr; | ||
79 | socklen_t len = sizeof(struct sockaddr); | 77 | socklen_t len = sizeof(struct sockaddr); |
80 | char retval[3]; | 78 | char retval[3]; |
81 | 79 | ||
82 | memset(out, 0, maxlen); | 80 | memset(out, 0, maxlen); |
83 | if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0) | 81 | if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)&cliaddr, &len) < 0) |
82 | { | ||
83 | wl_logerr("Cannot receive from socket: %s", strerror(errno)); | ||
84 | return -1; | 84 | return -1; |
85 | } | ||
85 | 86 | ||
86 | /* Get packet type and return it */ | 87 | /* Get packet type and return it */ |
87 | memset(retval, 0, sizeof(retval)); | 88 | memset(retval, 0, sizeof(retval)); |
88 | memcpy(retval, out, 2); | 89 | memcpy(retval, out, 2); |
89 | 90 | ||
90 | return atoi(retval); | 91 | return atoi(retval); |
91 | } | 92 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh index 6ddbaef..e7d9747 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh | |||
@@ -1,20 +1,21 @@ | |||
1 | /* $id */ | 1 | /* $Id */ |
2 | 2 | ||
3 | #ifndef WLSOCK_HH | 3 | #ifndef WLSOCK_HH |
4 | #define WLSOCK_HH | 4 | #define WLSOCK_HH |
5 | 5 | ||
6 | #include <stdarg.h> | ||
6 | #include <sys/types.h> | 7 | #include <sys/types.h> |
7 | #include <sys/socket.h> | 8 | #include <sys/socket.h> |
8 | #include <netinet/in.h> | 9 | #include <netinet/in.h> |
9 | #include <arpa/inet.h> | 10 | #include <arpa/inet.h> |
10 | #include <signal.h> | 11 | #include <signal.h> |
11 | #include <string.h> | 12 | #include <string.h> |
12 | #include <unistd.h> | 13 | #include <unistd.h> |
13 | #include <stdlib.h> | 14 | #include <stdlib.h> |
14 | #include <errno.h> | 15 | #include <errno.h> |
15 | 16 | ||
16 | int wl_setupsock(const char *, int); | 17 | int wl_setupsock(const char *, int, struct sockaddr_in); |
17 | int wl_send(const char *, int, const char *, ...); | 18 | int wl_send(const char *, int, const char *, ...); |
18 | int wl_recv(int *, char *, int); | 19 | int wl_recv(int *, struct sockaddr_in, char *, int); |
19 | 20 | ||
20 | #endif /* WLSOCK_HH */ | 21 | #endif /* WLSOCK_HH */ |