-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/sock.cc | 28 | ||||
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/sock.hh | 1 |
2 files changed, 25 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 | |||
@@ -48,6 +48,10 @@ int sendcomm(const char *host, int port, const char *string, ...) | |||
48 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); | 48 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); |
49 | va_end(ap); | 49 | va_end(ap); |
50 | 50 | ||
51 | saddr.sin_family = AF_INET; | ||
52 | saddr.sin_port = htons(port); | ||
53 | saddr.sin_addr.s_addr = inet_addr(host); | ||
54 | |||
51 | /* Setup socket */ | 55 | /* Setup socket */ |
52 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) | 56 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
53 | { | 57 | { |
@@ -55,10 +59,6 @@ int sendcomm(const char *host, int port, const char *string, ...) | |||
55 | return -1; | 59 | return -1; |
56 | } | 60 | } |
57 | 61 | ||
58 | saddr.sin_family = AF_INET; | ||
59 | saddr.sin_port = htons(port); | ||
60 | saddr.sin_addr.s_addr = inet_addr(host); | ||
61 | |||
62 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) | 62 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) |
63 | { | 63 | { |
64 | wl_logerr("Cannot write to socket: %s", strerror(errno)); | 64 | wl_logerr("Cannot write to socket: %s", strerror(errno)); |
@@ -71,3 +71,23 @@ int sendcomm(const char *host, int port, const char *string, ...) | |||
71 | 71 | ||
72 | return 1; | 72 | return 1; |
73 | } | 73 | } |
74 | |||
75 | /* Check for new messages on commsock */ | ||
76 | int recvcomm(int *sock, char *out, int maxlen) | ||
77 | { | ||
78 | struct sockaddr_in *cliaddr; | ||
79 | socklen_t len=sizeof(struct sockaddr); | ||
80 | char buffer[128], retval[3]; | ||
81 | |||
82 | memset(buffer, 0, sizeof(buffer)); | ||
83 | if(recvfrom(*sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | ||
84 | return -1; | ||
85 | |||
86 | memset(out, 0, maxlen); | ||
87 | memcpy(out, buffer, maxlen - 1); | ||
88 | |||
89 | memset(retval, 0, sizeof(retval)); | ||
90 | memcpy(retval, out, 2); | ||
91 | |||
92 | return atoi(retval); | ||
93 | } | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/sock.hh index afde641..611e335 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/sock.hh | |||
@@ -15,5 +15,6 @@ | |||
15 | 15 | ||
16 | int commsock(const char *, int); | 16 | int commsock(const char *, int); |
17 | int sendcomm(const char *, int, const char *, ...); | 17 | int sendcomm(const char *, int, const char *, ...); |
18 | int recvcomm(int *, char *, int); | ||
18 | 19 | ||
19 | #endif /* WLSOCK_HH */ | 20 | #endif /* WLSOCK_HH */ |