author | mjm <mjm> | 2002-11-27 21:16:52 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-11-27 21:16:52 (UTC) |
commit | e16163a106d5f814e9774f6a630cdb2ee488a616 (patch) (side-by-side diff) | |
tree | ec0468c5a4cc889f3c4f7cca26c3dcb1d3e324b6 /noncore/net/wellenreiter/libwellenreiter/source/sock.cc | |
parent | c118084479a4d146244b3e9e86b958f618a80a6d (diff) | |
download | opie-e16163a106d5f814e9774f6a630cdb2ee488a616.zip opie-e16163a106d5f814e9774f6a630cdb2ee488a616.tar.gz opie-e16163a106d5f814e9774f6a630cdb2ee488a616.tar.bz2 |
new funection recvcomm for receiving commands, cleanup,...
Diffstat (limited to 'noncore/net/wellenreiter/libwellenreiter/source/sock.cc') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/sock.cc | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/sock.cc index 2cc16eb..90fc20a 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sock.cc @@ -50,2 +50,6 @@ int sendcomm(const char *host, int port, const char *string, ...) + saddr.sin_family = AF_INET; + saddr.sin_port = htons(port); + saddr.sin_addr.s_addr = inet_addr(host); + /* Setup socket */ @@ -57,6 +61,2 @@ int sendcomm(const char *host, int port, const char *string, ...) - saddr.sin_family = AF_INET; - saddr.sin_port = htons(port); - saddr.sin_addr.s_addr = inet_addr(host); - if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) @@ -73 +73,21 @@ int sendcomm(const char *host, int port, const char *string, ...) } + +/* Check for new messages on commsock */ +int recvcomm(int *sock, char *out, int maxlen) +{ + struct sockaddr_in *cliaddr; + socklen_t len=sizeof(struct sockaddr); + char buffer[128], retval[3]; + + memset(buffer, 0, sizeof(buffer)); + if(recvfrom(*sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) + return -1; + + memset(out, 0, maxlen); + memcpy(out, buffer, maxlen - 1); + + memset(retval, 0, sizeof(retval)); + memcpy(retval, out, 2); + + return atoi(retval); +} |