Lines Matching +full:recv +full:- +full:not +full:- +full:empty
2 * Copyright (c) 2002 - 2003
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * that hides the differences between operating systems. It does not
59 #include "pcap-int.h"
90 * On UN*X, send() and recv() return ssize_t.
92 * On Windows, send() and recv() return an int.
101 * that hold the return values from send() and recv().
133 if (remaining > fuzzSize - fuzzPos) { in fuzz_recv()
134 remaining = fuzzSize - fuzzPos; in fuzz_recv()
198 * so that lower-rated errors for a given address in a given family
199 * should not overwrite higher-rated errors for another address in that
200 * family, and higher-rated errors should overwrite lower-rated errors.
206 SOCK_AFNOTSUPERR, /* address family not supported */
227 * or that it is set up, but it's IPv4-only or IPv6-only in sock_geterrtype()
249 * Network errors that could be IPv4-specific, IPv6- in sock_geterrtype()
284 * "Address family not supported" probably means in sock_geterrtype()
289 * address family if it's not supported), but overwrite in sock_geterrtype()
312 * \param errbuf: a pointer to an user-allocated buffer that will contain
317 * The error message cannot be larger than 'errbuflen - 1' because the
320 * \return '0' if everything is fine, '-1' if some errors occurred. The
335 return -1; in sock_init()
364 sockcount--; in sock_cleanup()
374 * \return '0' if the address is multicast, '-1' if it is not.
378 if (saddr->sa_family == PF_INET) in sock_ismcastaddr()
381 if (IN_MULTICAST(ntohl(saddr4->sin_addr.s_addr))) return 0; in sock_ismcastaddr()
382 else return -1; in sock_ismcastaddr()
387 if (IN6_IS_ADDR_MULTICAST(&saddr6->sin6_addr)) return 0; in sock_ismcastaddr()
388 else return -1; in sock_ismcastaddr()
406 return addr_a->info->ai_family - addr_b->info->ai_family; in compare_addrs_to_try_by_address_family()
418 if (addr_a->errtype == addr_b->errtype) in compare_addrs_to_try_by_status()
420 if (addr_a->errcode == addr_b->errcode) in compare_addrs_to_try_by_status()
422 return addr_a->info->ai_family - addr_b->info->ai_family; in compare_addrs_to_try_by_status()
424 return addr_a->errcode - addr_b->errcode; in compare_addrs_to_try_by_status()
427 return addr_a->errtype - addr_b->errtype; in compare_addrs_to_try_by_status()
438 sock = socket(addrinfo->ai_family, addrinfo->ai_socktype, in sock_create_socket()
439 addrinfo->ai_protocol); in sock_create_socket()
449 * especially in client programs, which may not even be aware that in sock_create_socket()
454 sizeof (int)) == -1) in sock_create_socket()
488 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
493 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
530 * Force the use of IPv6-only addresses. in sock_open()
535 * https://tools.ietf.org/html/rfc3493#section-3.7 in sock_open()
544 * Not all network stacks support IPv4 on IPv6 sockets; in sock_open()
545 * pre-NT 6 Windows stacks don't support it, and the in sock_open()
553 * https://tools.ietf.org/html/rfc3493#section-5.3 in sock_open()
561 if (addrinfo->ai_family == PF_INET6) in sock_open()
565 (char *)&on, sizeof (int)) == -1) in sock_open()
576 if (bind(sock, addrinfo->ai_addr, (int) addrinfo->ai_addrlen) != 0) in sock_open()
583 if (addrinfo->ai_socktype == SOCK_STREAM) in sock_open()
584 if (listen(sock, nconn) == -1) in sock_open()
613 tempaddrinfo = tempaddrinfo->ai_next) in sock_open()
637 tempaddrinfo = tempaddrinfo->ai_next, i++) in sock_open()
672 current_af != tempaddrinfo->ai_family) in sock_open()
692 if (connect(sock, tempaddrinfo->ai_addr, (int) tempaddrinfo->ai_addrlen) == -1) in sock_open()
745 * the daemon might not be set in sock_open()
771 bufspaceleft = errbuflen - msglen; in sock_open()
781 sock_getascii_addrport((struct sockaddr_storage *) addrs_to_try[i].info->ai_addr, in sock_open()
786 bufspaceleft = errbuflen - msglen; in sock_open()
824 bufspaceleft = errbuflen - msglen; in sock_open()
839 bufspaceleft = errbuflen - msglen; in sock_open()
857 * (while recv() ones are still allowed). Then, it closes the socket.
861 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
866 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
868 * \return '0' if everything is fine, '-1' if some errors occurred. The error message is returned
883 return -1; in sock_close()
893 * 1) on Windows, Microsoft explicitly says it's not thread-safe;
895 * thread-safe, so an implementation might use a static buffer
899 * provided, or not known"? It's typically going to be "not
900 * known", not "oopsie, I passed null pointers for the host name
901 * and service name", not to mention they forgot the "neither");
927 "%sAddress family for %s not supported", in get_gai_errstring()
934 "%s%s could not be resolved at this time", in get_gai_errstring()
946 "%sA non-recoverable error occurred when attempting to resolve %s", in get_gai_errstring()
952 "%sThe address family for looking up %s was not recognized", in get_gai_errstring()
988 "%sThe service value specified when looking up %s as not recognized for the socket type", in get_gai_errstring()
994 "%sThe socket type specified when looking up %s as not recognized", in get_gai_errstring()
1052 * \param port: a pointer to a user-allocated buffer containing the network port to use.
1061 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1066 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1087 * is not guaranteed to do so; to handle that, if port is null, in sock_initaddress()
1155 * XXX - should we just check that at least *one* address is in sock_initaddress()
1158 * support? :-)) in sock_initaddress()
1160 if ((addrinfo->ai_family != PF_INET) && in sock_initaddress()
1161 (addrinfo->ai_family != PF_INET6)) in sock_initaddress()
1164 snprintf(errbuf, errbuflen, "getaddrinfo(): socket type not supported"); in sock_initaddress()
1172 if ((addrinfo->ai_socktype == SOCK_STREAM) && in sock_initaddress()
1173 (sock_ismcastaddr(addrinfo->ai_addr) == 0)) in sock_initaddress()
1176 …snprintf(errbuf, errbuflen, "getaddrinfo(): multicast addresses are not valid when using TCP strea… in sock_initaddress()
1190 * In case the socket buffer does not have enough space, it loops until all data
1195 * \param buffer: a char pointer to a user-allocated buffer in which data is contained.
1199 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1204 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1206 * \return '0' if everything is fine, '-1' if an error other than
1208 * '-2' if we got one of those errors.
1225 return -1; in sock_send()
1240 * on errors on stream-oriented sockets when the other in sock_send()
1250 if (nsent == -1) in sock_send()
1270 return -2; in sock_send()
1283 return -2; in sock_send()
1288 return -1; in sock_send()
1291 remaining -= nsent; in sock_send()
1304 * resulting buffer will not be larger than 'totsize'. Finally, it updates
1305 * the 'offset' variable in order to point to the first empty location of the buffer.
1307 * In case the function is called with 'checkonly' equal to 1, it does not copy
1314 * This function is useful in case the userland application does not know immediately
1323 * \param outbuf: user-allocated buffer (of size 'totsize') into which data
1327 * empty location.
1331 * \param checkonly: '1' if we do not want to copy data into the buffer and we
1334 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1339 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1341 * \return '0' if everything is fine, '-1' if some errors occurred. The error message
1344 * In case of 'checkonly == 1', data is not copied, but 'offset' is updated in any case.
1357 snprintf(errbuf, errbuflen, "Not enough space in the temporary send buffer."); in sock_bufferize()
1358 return -1; in sock_bufferize()
1372 * This function basically calls the recv() socket function and it checks that no
1376 * want to receive exactly 'size' byte, it loops on the recv() until all the requested
1379 * In case the socket does not have enough data available, it cycles on the recv()
1385 * \param buffer: a char pointer to a user-allocated buffer in which data has to be stored
1396 * received (in case the socket does not have enough data available).
1404 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1409 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1411 * \return the number of bytes read if everything is fine, '-1' if some errors occurred.
1435 return -1; in sock_recv()
1445 * We don't use MSG_WAITALL because it's not supported in in sock_recv()
1455 * XXX - what about MSG_PEEK? in sock_recv()
1458 if (nread == -2) return -1; in sock_recv()
1461 nread = recv(sock, bufp, remaining, recv_flags); in sock_recv()
1463 nread = recv(sock, bufp, remaining, recv_flags); in sock_recv()
1466 if (nread == -1) in sock_recv()
1470 return -3; in sock_recv()
1472 sock_geterrmsg(errbuf, errbuflen, "recv() failed"); in sock_recv()
1473 return -1; in sock_recv()
1491 return -1; in sock_recv()
1510 remaining -= nread; in sock_recv()
1520 * Returns the size of the datagram on success or -1 on error.
1543 return -1; in sock_recv_dgram()
1550 snprintf(errbuf, errbuflen, "DTLS not implemented yet"); in sock_recv_dgram()
1551 return -1; in sock_recv_dgram()
1557 * entire datagram in one recv() or recvmsg() call, and in sock_recv_dgram()
1561 nread = recv(sock, buffer, (int)size, 0); in sock_recv_dgram()
1565 * To quote the MSDN documentation for recv(), in sock_recv_dgram()
1568 * with the first part of the datagram, and recv in sock_recv_dgram()
1578 "recv() failed"); in sock_recv_dgram()
1579 return -1; in sock_recv_dgram()
1583 * The Single UNIX Specification says that a recv() on in sock_recv_dgram()
1584 * a socket for a message-oriented protocol will discard in sock_recv_dgram()
1585 * the excess data. It does *not* indicate that the in sock_recv_dgram()
1590 * when receiving a message for a message-oriented in sock_recv_dgram()
1611 if (nread == -1) in sock_recv_dgram()
1614 return -3; in sock_recv_dgram()
1615 sock_geterrmsg(errbuf, errbuflen, "recv() failed"); in sock_recv_dgram()
1616 return -1; in sock_recv_dgram()
1620 * XXX - Solaris supports this, but only if you ask for the in sock_recv_dgram()
1632 snprintf(errbuf, errbuflen, "recv(): Message too long"); in sock_recv_dgram()
1633 return -1; in sock_recv_dgram()
1654 * this buffer is not large enough, it will cycle in order to read everything as well.
1660 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1665 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1667 * \return '0' if everything is fine, '-1' if some errors occurred.
1680 * in case this is not enough, the "while" loop discards the message by calling the in sock_discard()
1682 * We do not want to create a bigger variable because this causes the program to exit on in sock_discard()
1687 if (sock_recv(sock, ssl, buffer, TEMP_BUF_SIZE, SOCK_RECEIVEALL_YES, errbuf, errbuflen) == -1) in sock_discard()
1688 return -1; in sock_discard()
1690 size -= TEMP_BUF_SIZE; in sock_discard()
1699 if (sock_recv(sock, ssl, buffer, size, SOCK_RECEIVEALL_YES, errbuf, errbuflen) == -1) in sock_discard()
1700 return -1; in sock_discard()
1721 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1726 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1729 * - '1' if the host list is empty
1730 * - '0' if the host belongs to the host list (and therefore it is allowed to connect)
1731 …* - '-1' in case the host does not belong to the host list (and therefore it is not allowed to con…
1732 * - '-2' in case or error. The error message is returned in the 'errbuf' variable.
1754 return -2; in sock_check_hostlist()
1759 /* it avoids a warning in the compilation ('addrinfo used but not initialized') */ in sock_check_hostlist()
1795 if (sock_cmpaddr(from, (struct sockaddr_storage *) ai_next->ai_addr) == 0) in sock_check_hostlist()
1803 * If we are here, it means that the current address does not matches in sock_check_hostlist()
1806 ai_next = ai_next->ai_next; in sock_check_hostlist()
1831 return -2; in sock_check_hostlist()
1838 snprintf(errbuf, errbuflen, "The host is not in the allowed host list. Connection refused."); in sock_check_hostlist()
1839 return -1; in sock_check_hostlist()
1843 /* No hostlist, so we have to return 'empty list' */ in sock_check_hostlist()
1853 * The two structures do not need to be sockaddr_storage; you can have both 'sockaddr_in' and
1856 * This function will return '0' if the two addresses matches, '-1' if not.
1863 * \return '0' if the addresses are equal, '-1' if they are different.
1867 if (first->ss_family == second->ss_family) in sock_cmpaddr()
1869 if (first->ss_family == AF_INET) in sock_cmpaddr()
1871 if (memcmp(&(((struct sockaddr_in *) first)->sin_addr), in sock_cmpaddr()
1872 &(((struct sockaddr_in *) second)->sin_addr), in sock_cmpaddr()
1878 if (memcmp(&(((struct sockaddr_in6 *) first)->sin6_addr), in sock_cmpaddr()
1879 &(((struct sockaddr_in6 *) second)->sin6_addr), in sock_cmpaddr()
1885 return -1; in sock_cmpaddr()
1893 * - connected sockets
1894 * - server sockets
1896 * On unconnected client sockets it does not work because the system dynamically chooses a port
1915 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1920 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1922 * \return It returns '-1' if this function succeeds, '0' otherwise.
1926 * \warning If the socket is using a connectionless protocol, the address may not be available
1938 if (getsockname(sock, (struct sockaddr *) &mysockaddr, &sockaddrlen) == -1) in sock_getmyinfo()
1951 * This function is basically an extended version of the inet_ntop(), which does not exist in
1966 * zero-ed prior using it, and the address family field must be filled with the proper value.
1984 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
1989 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
1991 * \return It returns '-1' if this function succeeds, '0' otherwise.
2001 retval = -1; in sock_getascii_addrport()
2004 if (sockaddr->ss_family == AF_INET) in sock_getascii_addrport()
2014 if ((sockaddr->ss_family == AF_INET6) && in sock_getascii_addrport()
2015 …(memcmp(&((struct sockaddr_in6 *) sockaddr)->sin6_addr, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof… in sock_getascii_addrport()
2030 errbuf[errbuflen - 1] = 0; in sock_getascii_addrport()
2036 address[addrlen - 1] = 0; in sock_getascii_addrport()
2042 port[portlen - 1] = 0; in sock_getascii_addrport()
2054 * This function basically replaces inet_pton(), which does not exist in Winsock because
2061 * \param address: a zero-terminated string which contains the name you have to
2064 * \param sockaddr: a user-allocated sockaddr_storage structure which will contains the
2068 * - 'AF_INET' if we want to ping an IPv4 host
2069 * - 'AF_INET6' if we want to ping an IPv6 host
2070 * - 'AF_UNSPEC' if we do not have preferences about the protocol used to ping the host
2072 * \param errbuf: a pointer to an user-allocated buffer that will contain the complete
2077 * larger than 'errbuflen - 1' because the last char is reserved for the string terminator.
2079 * \return '-1' if the translation succeeded, '-2' if there was some non critical error, '0'
2101 if (addrinfo->ai_family == PF_INET) in sock_present2network()
2102 memcpy(sockaddr, addrinfo->ai_addr, sizeof(struct sockaddr_in)); in sock_present2network()
2104 memcpy(sockaddr, addrinfo->ai_addr, sizeof(struct sockaddr_in6)); in sock_present2network()
2106 if (addrinfo->ai_next != NULL) in sock_present2network()
2112 return -2; in sock_present2network()
2116 return -1; in sock_present2network()