author | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
commit | d331ca1cf11e8f525665a1e5cb10f491d47c19e8 (patch) (unidiff) | |
tree | 42e46b280ac5b9ce5762f0df3a09189c4912d560 /noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc | |
parent | e34eef8e2f2a36797ef980d505a99948f88a5df2 (diff) | |
download | opie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.zip opie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.tar.gz opie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.tar.bz2 |
wl_recv was more or less broken because of missing socket structure, fixed.
general cleanup.
GUI has to be updated in functions wl_setupsock and wl_recv
Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc | 15 |
1 files changed, 8 insertions, 7 deletions
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 | |||
@@ -5,28 +5,27 @@ | |||
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 | } |
@@ -70,21 +69,23 @@ int wl_send(const char *host, int port, const char *string, ...) | |||
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); |