if (socket->form == f_socket_address_form_inet4_e) {
address = (struct sockaddr *) &socket->address.inet4;
socket->address.inet4.sin_family = f_socket_address_family_inet4_e;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_in);
}
else if (socket->form == f_socket_address_form_inet6_e) {
address = (struct sockaddr *) &socket->address.inet6;
socket->address.inet6.sin6_family = f_socket_address_family_inet6_e;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_in6);
}
else if (socket->form == f_socket_address_form_local_e) {
address = (struct sockaddr *) &socket->address.local;
socket->address.local.sun_family = f_socket_address_family_local_e;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_un);
if (socket->name.used && socket->name.string && socket->name.used + 1 <= socket->name.size) {
memcpy((void *) socket->address.local.sun_path, (void *) socket->name.string, socket->name.used);
#ifdef _en_support_socket_address_at_
else if (socket->form == f_socket_address_form_at_e) {
address = (struct sockaddr *) &socket->address.at;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_at);
}
#endif // _en_support_socket_address_at_
#ifdef _en_support_socket_address_ax25_
else if (socket->form == f_socket_address_form_ax25_e) {
address = (struct sockaddr *) &socket->address.ax25;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_ax25);
}
#endif // _en_support_socket_address_ax25_
#ifdef _en_support_socket_address_dl_
else if (socket->form == f_socket_address_form_dl_e) {
address = (struct sockaddr *) &socket->address.dl;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_dl);
}
#endif // _en_support_socket_address_dl_
#ifdef _en_support_socket_address_eon_
else if (socket->form == f_socket_address_form_eon_e) {
address = (struct sockaddr *) &socket->address.eon;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_eon);
}
#endif // _en_support_socket_address_eon_
#ifdef _en_support_socket_address_ipx_
else if (socket->form == f_socket_address_form_ipx_e) {
address = (struct sockaddr *) &socket->address.ipx;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_ipx);
}
#endif // _en_support_socket_address_ipx_
#ifdef _en_support_socket_address_iso_
else if (socket->form == f_socket_address_form_iso_e) {
address = (struct sockaddr *) &socket->address.iso;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_iso);
}
#endif // _en_support_socket_address_iso_
#ifdef _en_support_socket_address_ns_
else if (socket->form == f_socket_address_form_ns_e) {
address = (struct sockaddr *) &socket->address.ns;
- socket->length = sizeof(struct sockaddr);
+ socket->length = sizeof(struct sockaddr_ns);
}
#endif // _en_support_socket_address_ns_
#endif // _di_f_socket_bind_
#ifndef _di_f_socket_connect_
- f_status_t f_socket_connect(const f_socket_t socket) {
+ f_status_t f_socket_connect(f_socket_t * const socket) {
+ #ifndef _di_level_0_parameter_checking_
+ if (!socket) return F_status_set_error(F_parameter);
+ #endif // _di_level_0_parameter_checking_
- if (socket.id == -1) return F_file_descriptor;
+ if (socket->id == -1) return F_file_descriptor;
struct sockaddr * address = 0;
- if (socket.form == f_socket_address_form_inet4_e) {
- address = (struct sockaddr *) &socket.address.inet4;
+ if (socket->form == f_socket_address_form_inet4_e) {
+ address = (struct sockaddr *) &socket->address.inet4;
+ socket->length = sizeof(struct sockaddr_in);
}
- else if (socket.form == f_socket_address_form_inet6_e) {
- address = (struct sockaddr *) &socket.address.inet6;
+ else if (socket->form == f_socket_address_form_inet6_e) {
+ address = (struct sockaddr *) &socket->address.inet6;
+ socket->length = sizeof(struct sockaddr_in6);
}
- else if (socket.form == f_socket_address_form_local_e) {
- address = (struct sockaddr *) &socket.address.local;
+ else if (socket->form == f_socket_address_form_local_e) {
+ address = (struct sockaddr *) &socket->address.local;
+ socket->length = sizeof(struct sockaddr_un);
}
#ifdef _en_support_socket_address_arp_
- else if (socket.form == f_socket_address_form_arp_e) {
- address = (struct sockaddr *) &socket.address.arp;
+ else if (socket->form == f_socket_address_form_arp_e) {
+ address = (struct sockaddr *) &socket->address.arp;
+ socket->length = sizeof(struct sockaddr);
}
#endif // _en_support_socket_address_arp_
#ifdef _en_support_socket_address_at_
- else if (socket.form == f_socket_address_form_at_e) {
- address = (struct sockaddr *) &socket.address.at;
+ else if (socket->form == f_socket_address_form_at_e) {
+ address = (struct sockaddr *) &socket->address.at;
+ socket->length = sizeof(struct sockaddr_at);
}
#endif // _en_support_socket_address_at_
#ifdef _en_support_socket_address_ax25_
- else if (socket.form == f_socket_address_form_ax25_e) {
- address = (struct sockaddr *) &socket.address.ax25;
+ else if (socket->form == f_socket_address_form_ax25_e) {
+ address = (struct sockaddr *) &socket->address.ax25;
+ socket->length = sizeof(struct sockaddr_ax25);
}
#endif // _en_support_socket_address_ax25_
#ifdef _en_support_socket_address_dl_
- else if (socket.form == f_socket_address_form_dl_e) {
- address = (struct sockaddr *) &socket.address.dl;
+ else if (socket->form == f_socket_address_form_dl_e) {
+ address = (struct sockaddr *) &socket->address.dl;
+ socket->length = sizeof(struct sockaddr_dl);
}
#endif // _en_support_socket_address_dl_
#ifdef _en_support_socket_address_eon_
- else if (socket.form == f_socket_address_form_eon_e) {
- address = (struct sockaddr *) &socket.address.eon;
+ else if (socket->form == f_socket_address_form_eon_e) {
+ address = (struct sockaddr *) &socket->address.eon;
+ socket->length = sizeof(struct sockaddr_eon);
}
#endif // _en_support_socket_address_eon_
#ifdef _en_support_socket_address_ipx_
- else if (socket.form == f_socket_address_form_ipx_e) {
- address = (struct sockaddr *) &socket.address.ipx;
+ else if (socket->form == f_socket_address_form_ipx_e) {
+ address = (struct sockaddr *) &socket->address.ipx;
+ socket->length = sizeof(struct sockaddr_ipx);
}
#endif // _en_support_socket_address_ipx_
#ifdef _en_support_socket_address_iso_
- else if (socket.form == f_socket_address_form_iso_e) {
- address = (struct sockaddr *) &socket.address.iso;
+ else if (socket->form == f_socket_address_form_iso_e) {
+ address = (struct sockaddr *) &socket->address.iso;
+ socket->length = sizeof(struct sockaddr_iso);
}
#endif // _en_support_socket_address_iso_
#ifdef _en_support_socket_address_ns_
- else if (socket.form == f_socket_address_form_ns_e) {
- address = (struct sockaddr *) &socket.address.ns;
+ else if (socket->form == f_socket_address_form_ns_e) {
+ address = (struct sockaddr *) &socket->address.ns;
+ socket->length = sizeof(struct sockaddr_ns);
}
#endif // _en_support_socket_address_ns_
#ifdef _en_support_socket_address_x25_
- else if (socket.form == f_socket_address_form_x25_e) {
- address = (struct sockaddr *) &socket.address.x25;
+ else if (socket->form == f_socket_address_form_x25_e) {
+ address = (struct sockaddr *) &socket->address.x25;
+ socket->length = sizeof(struct sockaddr_x25);
}
#endif // _en_support_socket_address_x25_
else {
// Generic (f_socket_address_form_generic_e) or failsafe.
- address = (struct sockaddr *) &socket.address.generic;
+ address = (struct sockaddr *) &socket->address.generic;
+ socket->length = sizeof(struct sockaddr);
}
- if (connect(socket.id, address, socket.length) == -1) {
+ if (connect(socket->id, address, socket->length) == -1) {
if (errno == EACCES) return F_status_set_error(F_access_denied);
if (errno == EADDRINUSE) return F_status_set_error(F_busy_address);
if (errno == EADDRNOTAVAIL) return F_status_set_error(F_available_not_address);
* The socket.id is the socket file descriptor used to establish the data file descriptor socket.id_data.
* The socket.id_data, socket.address, and socket.length are updated upon a successful return.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* The socket.address may be any valid structure, like "struct sockaddr", "struct sockaddr_un", or "struct sockaddr_in".
* The socket.address.*.*_family is conditionally altered by this function.
* The caller must appropriately initialize and configure the socket.address.
- * The socket.length must represent the full size of the address structure and is not altered by this function.
+ * The socket.length is updated based on socket.form.
* The socket.id must refer to a valid socket file descriptor.
*
* For IPv4:
* The socket.length is updated to represent the size of "struct sockaddr".
* The socket.type is not modified.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* The socket.address must have the proper structure setup based on the socket.type value, like "f_socket_address_family_inet4_e".
* Only domains defined with an associated structure in the f_socket_address_t are supported.
* Only socket.id is used.
+ * The socket.length is updated based on socket.form.
+ *
+ * Must not be NULL.
*
* @return
* F_okay on success.
* @see connect()
*/
#ifndef _di_f_socket_connect_
- extern f_status_t f_socket_connect(const f_socket_t socket);
+ extern f_status_t f_socket_connect(f_socket_t * const socket);
#endif // _di_f_socket_connect_
/**
* The socket.type must be assigned the desired socket type.
* The socket.id will be updated with a file descriptor representing the created socket.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* The protocol to use.
* @param id_1
* The first of the pair of socket file descriptors.
+ *
+ * Must not be NULL.
* @param id_2
* The second of the pair of socket file descriptors.
*
* This socket is supposed to be identical to the one specified by id_1.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* @param socket
* The socket structure.
* The socket.id must represent a valid socket file descriptor.
+ *
+ * Must not be NULL.
* @param action
* The action to perform on close.
* f_socket_close_fast_e calls close().
* @param socket
* The socket structure.
* The socket.id must represent a valid socket file descriptor.
+ *
+ * Must not be NULL.
* @param backlog_max
* The max length of the pending connections queue.
* Suggested default setting: 8.
* @param socket
* The socket structure.
* The socket.id must represent a valid socket file descriptor.
+ *
+ * Must not be NULL.
* @param level
* The level in which the socket option is located.
* This may be synonymous with "layer".
* The option code used to represent the option name.
* @param value
* The value to assign.
+ *
+ * Must not be NULL.
* @param length
* The length of the value (often derived from a sizeof() call).
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* @param socket
* The socket structure.
* The socket.id must represent a valid socket file descriptor.
+ *
+ * Must not be NULL.
* @param level
* The level in which the socket option is located.
* This may be synonymous with "layer".
* The option code used to represent the option name.
* @param value
* The value to assign.
+ *
+ * Must not be NULL.
* @param length
* The length of the value (often derived from a sizeof() call).
*
* The socket structure.
* The socket.id must represent a valid socket file descriptor.
* The socket.size_read is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
+ *
+ * Must not be NULL.
* @param name
* The retrieved host name.
* The name.size is used to determine as the max size.
* If name.size is 0, then a default max (F_socket_default_name_max_d) is used.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* The socket.size_read is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
* The socket.address is used to store the name of the remote connection.
*
+ * Must not be NULL.
+ *
* @return
* F_okay on success.
*
* The socket structure.
* The socket.id_data must represent a valid file descriptor.
* The socket.size_read is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param buffer
* The buffer to populate.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length read.
* @param socket
* The socket structure.
* The socket.id_data must represent a valid file descriptor.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param header
* The message header.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length read.
* The socket structure.
* The socket.id_data must represent a valid file descriptor.
* The socket.size_read is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param buffer
* The buffer to populate.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length read.
* The socket structure.
* The socket.id_data must represent a valid socket file descriptor.
* The socket.size_write is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param buffer
* The buffer to populate.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length send.
* @param socket
* The socket structure.
* The socket.id_data must represent a valid file descriptor.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param header
* The message header.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length send.
* The socket structure.
* The socket.id_data must represent a valid socket file descriptor.
* The socket.size_write is used to represent the buffer size in buffer and must not be larger than the actual size of the buffer.
+ *
+ * Must not be NULL.
* @param flags
* Read flags.
* @param buffer
* The buffer to populate.
+ *
+ * Must not be NULL.
* @param length
* (optional) The length of the buffer.
* This gets replaced with the value of a positive ssize_t representing the length send.