7 #include <sys/socket.h> 80 size_t hostbuflen,
char* portbuf,
size_t portbuflen,
81 int rcvfrom_flags,
bool numeric) {
83 int num = ((numeric ==
true) ? LIBSOCKET_NUMERIC : 0);
87 "inet_dgram::rcvfrom() - Socket is closed!",
91 sfd, buf, len, hostbuf, hostbuflen, portbuf, portbuflen,
92 rcvfrom_flags, num))) {
93 if (is_nonblocking && errno == EWOULDBLOCK)
97 "inet_dgram::rcvfrom() - recvfrom() failed " 98 "-- could not receive data from peer!");
123 string& srcport,
int rcvfrom_flags,
bool numeric) {
126 using std::unique_ptr;
127 unique_ptr<char[]> from_host(
new char[1024]);
128 unique_ptr<char[]> from_port(
new char[32]);
130 memset(from_host.get(), 0, 1024);
131 memset(from_port.get(), 0, 32);
135 bytes =
rcvfrom(buf, len, from_host.get(), 1023, from_port.get(), 31,
136 rcvfrom_flags, numeric);
138 srchost.resize(strlen(from_host.get()));
139 srcport.resize(strlen(from_port.get()));
141 srchost.assign(from_host.get());
142 srcport.assign(from_port.get());
168 int rcvfrom_flags,
bool numeric) {
171 using std::unique_ptr;
172 unique_ptr<char[]> cbuf(
new char[buf.size()]);
174 memset(cbuf.get(), 0, buf.size());
176 bytes =
rcvfrom(cbuf.get(), static_cast<size_t>(buf.size()), srchost,
177 srcport, rcvfrom_flags,
183 buf.assign(cbuf.get(), bytes);
208 const char* dstport,
int sndto_flags) {
213 "inet_dgram::sendto() - Socket already closed!",
218 if (is_nonblocking && errno == EWOULDBLOCK)
222 "inet_dgram::sndto() - Error at sendto");
244 const string& dstport,
int sndto_flags) {
247 bytes =
sndto(buf, len, dsthost.c_str(), dstport.c_str(), sndto_flags);
267 const string& dstport,
int sndto_flags) {
270 bytes =
sndto(buf.c_str(), buf.size(), dsthost.c_str(), dstport.c_str(),
Contains libsocket elements.
This class is instantiated and thrown when an error occurs. If there's an error somewhere in libsocke...
ssize_t sendto_inet_dgram_socket(int sfd, const void *buf, size_t size, const char *host, const char *service, int sendto_flags)
This function is the equivalent to sendto(2)
ssize_t rcvfrom(void *buf, size_t len, char *srchost, size_t hostlen, char *srcport, size_t portlen, int rcvfrom_flags=0, bool numeric=false)
Receives data from peer.
int sfd
sfd is the sockets API file descriptor
ssize_t recvfrom_inet_dgram_socket(int sfd, void *buffer, size_t size, char *src_host, size_t src_host_len, char *src_service, size_t src_service_len, int recvfrom_flags, int numeric)
Receive data from a UDP/IP socket.
ssize_t sndto(const void *buf, size_t len, const char *dsthost, const char *dstport, int sndto_flags=0)
Send data to UDP peer.
Contains all functions available in the C libsocket.