author | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
commit | d331ca1cf11e8f525665a1e5cb10f491d47c19e8 (patch) (side-by-side diff) | |
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 @@ -1,38 +1,37 @@ /* * Socket operations for wellenreiter * * $Id$ */ #include "wl_sock.hh" #include "wl_log.hh" /* Setup UDP Socket for incoming commands */ -int wl_setupsock(const char *host, int port) +int wl_setupsock(const char *host, int port, struct sockaddr_in saddr) { - struct sockaddr_in saddr; int sock; 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) { wl_logerr("Cannot bind socket: %s", strerror(errno)); close(sock); return -1; } return sock; } /* Send a string to commsock */ 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, ...) 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) +int wl_recv(int *sock, struct sockaddr_in cliaddr, char *out, int maxlen) { - struct sockaddr_in *cliaddr; 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) + if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)&cliaddr, &len) < 0) + { + wl_logerr("Cannot receive from socket: %s", strerror(errno)); return -1; + } /* Get packet type and return it */ memset(retval, 0, sizeof(retval)); memcpy(retval, out, 2); return atoi(retval); } |