X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=net.c;h=9309ac1f02dc63edcc7af2939686b10b6d9b0599;hp=427ab0f0d2a3ebe3873eeff603422742b66a94b1;hb=8f3685d67bcec78c7028eedc9ee0fcaefb3aa13f;hpb=2fe2b6e212e8e0d09cd1a8fc95f7f2f3a1110485 diff --git a/net.c b/net.c index 427ab0f0..9309ac1f 100644 --- a/net.c +++ b/net.c @@ -19,11 +19,13 @@ #define AI_ADDRCONFIG 0 #endif +#include #include "para.h" #include "error.h" #include "net.h" #include "string.h" +#include "fd.h" /** Information about one encrypted connection. */ @@ -155,9 +157,13 @@ int makesock(unsigned l3type, unsigned l4type, int passive, /* Set up address hint structure */ memset(&hints, 0, sizeof(hints)); hints.ai_family = l3type; - /* getaddrinfo does not really work well with SOCK_DCCP */ - if (socktype == SOCK_DGRAM || socktype == SOCK_STREAM) - hints.ai_socktype = socktype; + hints.ai_socktype = socktype; + /* + * getaddrinfo does not support SOCK_DCCP, so for the sake of lookup + * (and only then) pretend to be UDP. + */ + if (l4type == IPPROTO_DCCP) + hints.ai_socktype = SOCK_DGRAM; /* only use addresses available on the host */ hints.ai_flags = AI_ADDRCONFIG; @@ -345,31 +351,6 @@ struct in_addr extract_v4_addr(const struct sockaddr_storage *ss) return ia; } -/* - * Write a buffer to a file descriptor, re-write on short writes. - * - * \param fd The file descriptor. - * \param buf The buffer to be sent. - * \param len The length of \a buf. - * - * \return Standard. In any case, the number of bytes that have been written is - * stored in \a len. - */ -static int write_all(int fd, const char *buf, size_t *len) -{ - size_t total = *len; - - assert(total); - *len = 0; - while (*len < total) { - int ret = write(fd, buf + *len, total - *len); - if (ret == -1) - return -ERRNO_TO_PARA_ERROR(errno); - *len += ret; - } - return 1; -} - /** * Encrypt and send a binary buffer. * @@ -747,10 +728,9 @@ int recv_cred_buffer(int fd, char *buf, size_t size) * * \return Positive if \a pattern was received, negative otherwise. * - * This function creates a buffer of size \a bufsize and tries - * to receive at most \a bufsize bytes from file descriptor \a fd. - * If at least \p strlen(\a pattern) bytes were received, the beginning of - * the received buffer is compared with \a pattern, ignoring case. + * This function tries to receive at most \a bufsize bytes from file descriptor + * \a fd. If at least \p strlen(\a pattern) bytes were received, the beginning + * of the received buffer is compared with \a pattern, ignoring case. * * \sa recv_buffer(), \sa strncasecmp(3). */ @@ -758,7 +738,7 @@ int recv_pattern(int fd, const char *pattern, size_t bufsize) { size_t len = strlen(pattern); char *buf = para_malloc(bufsize + 1); - int ret = -E_RECV_PATTERN, n = recv_buffer(fd, buf, bufsize); + int ret = -E_RECV_PATTERN, n = recv_buffer(fd, buf, bufsize + 1); if (n < len) goto out;